Calculate center of SVG arc

后端 未结 2 1730
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 09:39

I have the following information:

  • radiusX (rx)
  • radiusY (ry)
  • x1
  • y1
  • x2
  • y2

The SVG spec allows you to defi

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 10:09

    I'm considering the case of x-axis-rotation = 0. Equations for start and end points:

    x1 = cx + rx * cos(StartAngle)

    y1 = cy + ry * sin(StartAngle)

    x2 = cx + rx * cos(EndAngle)

    y2 = cy + ry * sin(EndAngle)

    Excluding angles from equation pairs gives us:

    ry^2*(x1-cx)^2+rx^2*(y1-cy)^2=rx^2*ry^2

    ry^2*(x2-cx)^2+rx^2*(y2-cy)^2=rx^2*ry^2

    This equation system can be analytically solved for (cx, cy) by hands or with help of math packets (Maple, Mathematica etc). There are two solutions of quadratic equation (due to large-arc-flag and sweep-flag combination).

提交回复
热议问题