Forgot password?
 Create new account
View 141|Reply 1

calculate the start and end angles of an SVG path arc command

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-3-6 23:38:35 |Read mode
计算svg path 中的A (elliptical arc command)(此处假定是圆弧, 即 rx=ry)的start angle,end angle以导入TikZ
  1. import math
  2. # SVG path string
  3. path = 'M 11.71,194.229 A 103.5,103.5 0 0 0 109.185,20.817'
  4. # Split the path string to get the start and end points of the arc
  5. _,start_point,_, radius, _, _, _, end_point = path.split()
  6. radius = float(radius.split(",")[0])
  7. # Convert the start and end points to floats
  8. start_x, start_y = map(float, start_point.split(","))
  9. end_x, end_y = map(float, end_point.split(","))
  10. # Calculate the start angle using the atan2 function
  11. start_angle = math.degrees(math.atan2(start_y - radius, start_x))
  12. # Calculate the end angle using the atan2 function
  13. end_angle = math.degrees(math.atan2(end_y - radius, end_x))
  14. print(r"\draw(",start_point,")arc(",start_angle,":",end_angle,":",radius,");")
Copy the Code

This will output:
\draw( 11.71,194.229 )arc( 82.64573712265114 : -37.13571293426289 : 103.5 );

See 14.7The Arc Operation

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2023-3-6 23:52:10
1#错的. 没有考虑sweep-flag largeArcFlag
28df4988-4837-11e6-9f3b-b266d825bec1[1].png

手机版Mobile version|Leisure Math Forum

2025-4-20 22:13 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list