Created
August 12, 2020 14:30
-
-
Save davipatti/6bafc0f4781109c733ac24ea3fade55a to your computer and use it in GitHub Desktop.
Extract xy coordinates from svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Extracting xy coordinates from an svg path using svgpathtools | |
# https://github.com/mathandy/svgpathtools | |
# pip install svgpathtools | |
from svgpathtools import parse_path | |
import numpy as np | |
path = "M 125.09006,141.18848 C 110.99811,164.35846 111.22868,108.07854 83.831725,113.54159 56.434773,119.00464 91.156393,169.4818 61.713214,168.35114 32.270035,167.22048 81.822001,142.5491 60.875654,122.49307 39.929306,102.43705 13.745665,149.24722 6.4082722,121.25037 -0.92912038,93.253532 42.338807,123.59851 43.351984,95.418206 44.365161,67.2379 -6.2345334,65.117335 11.759409,43.777931 29.753351,22.438526 42.683955,75.303807 69.420586,63.044694 96.157218,50.78558 64.480031,7.6180619 90.699813,14.891972 c 26.219787,7.27391 -22.120071,45.96694 0.83756,61.421875 22.957637,15.454936 45.837447,-38.115775 52.856287,-9.974186 7.01884,28.141589 -35.94694,7.378485 -41.50034,35.827669 -5.553398,28.44918 36.28869,15.85118 22.19674,39.02115 z" | |
a = parse_path(path) | |
# Evaluate a at points in interval 0-1 | |
comp = [a.point(i) for i in np.linspace(0, 1, num=500)] | |
# Extract real and imaginary components as standard numpy array | |
arr = np.array([(n.real, n.imag) for n in comp]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment