I have the following information:
- radiusX (rx)
- radiusY (ry)
- x1
- y1
- x2
- y2
The SVG spec allows you to define an arc by specifying its radius, and start and end points. There are other options such as large-arc-flag
and sweep-flag
which help to define how you want the start-point to reach the end-point. More details here.
I am not mathematically inclined, so understanding all of this is near impossible.
I guess I am looking for a simple equation that results in me knowing the centerX
and centerY
values given all the arguments accepted by SVG's arc command.
Any help is appreciated.
I've search stackoverflow and none of the answers seem to explain the solution in plain english.
You can use this javascript function to calculate.
Usage example:
svg
js
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).