What's a parametric equation (eg. $(x,y)=(\cos(t \cdot 2\pi),\sin(t \cdot 2\pi)$ plots a circle where $t$ is the 'time' along the circle) that draws an arc between the two points $(x_0,y_0)$ and $(x_1,y_1)$ with a start angle $a$. Also, can I calculate what the end angle is going to be? I drew a picture to show you what I mean. Thank you :) The picture
1 Answers
I assume you mean a circular arc, an arc from a circle, with a fixed radius.
The general 2D parametric equation for a circular arc is $$\begin{cases} x(t) = x_c + r \cos(a_0 + a t)\\ y(t) = y_c + r \sin(a_0 + a t) \end{cases}$$ where $$a = a_1 - a_0$$ and $$0 \le t \le 1$$ The center is at $(x_c, y_c)$, and the arc starts at angle $a_0$, extends to angle $a_1$, with radius $r$. Note that $t=0$ is the start point, and $t=1$ the end point.
In your case, you know $a_0$, $x(0) = x_0$, $y(0) = y_0$, $x(1) = x_1$, and $y(1) = y_1$. The first three define $x_c$ and $y_c$: $$\begin{cases} x(0) = x_0 = x_c + r \cos(a_0)\\ y(0) = y_0 = y_c + r \sin(a_0) \end{cases} \iff \begin{cases} x_c = x_0 - r \cos(a_0)\\ y_c = y_0 - r \sin(a_0)\end{cases}$$ The last two can be used to define $r$ and $a$: $$\begin{cases} x(1) = x_1 = x_0 - r \cos(a_0) + r \cos(a_0 + a)\\ y(1) = y_1 = y_0 - r \sin(a_0) + r \sin(a_0 + a)\end{cases}$$ That is a bit of work to work out by hand, but we end up with $$r = \frac{(x_0-x_1)^2 + (y_0-y_1)^2}{2(x_0-x_1)\cos(a_0) + 2(y_0-y_1)\sin(a_0)}$$ and $$a = \arctan\left( \; ((x_0-x_1)^2 - (y_0-y_1)^2)\sin(a_0) - 2(x_0-x_1)(y_0-y_1)\cos(a_0), \\ ((y_0-y_1)^2 - (x_0-x_1)^2)\cos(a_0) - 2(x_0-x_1)(y_0-y_1)\sin(a_0) \;\right) - a_0$$ where $\arctan(y,x)$ returns the angle between the positive x axis and point $(x,y)$, counterclockwise, handling all four quadrants (as determined by the signs of $y$ and $x$), i.e. full 360°.
Also, since $a = a_1 - a_0$, the ending angle for the arc is $$a_1 = \arctan\left( \; ((x_0-x_1)^2 - (y_0-y_1)^2)\sin(a_0) - 2(x_0-x_1)(y_0-y_1)\cos(a_0), \\ ((y_0-y_1)^2 - (x_0-x_1)^2)\cos(a_0) - 2(x_0-x_1)(y_0-y_1)\sin(a_0) \;\right)$$
- 9,306
atan2()implementations return $[-\pi, +\pi]$. If $a$ is positive, $a_1 > a_0$, and the arc is drawn counterclockwise; if negative, $a_1 < a_0$, and the arc is drawn clockwise. Becauseatan2()result is clamped to $[-\pi,+\pi]$, the above formula for $a$ clamps $a_1$ to that same range. In general, you should get correct results if you use range $[-\pi,+\pi]$ for $a_0$, too. – Nominal Animal May 11 '16 at 14:33