找回密码
 快速注册
搜索
查看: 37|回复: 1

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

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-6 23:38 |阅读模式
计算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,");")
复制代码

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

See 14.7The Arc Operation

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-3-6 23:52
1#错的. 没有考虑sweep-flag largeArcFlag
28df4988-4837-11e6-9f3b-b266d825bec1[1].png

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:34

Powered by Discuz!

× 快速回复 返回顶部 返回列表