2

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 Answers1

3

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)$$

  • I tried it here. Sometimes it flips the start angle (maybe choses the shortest arc). Why is that? –  May 11 '16 at 09:44
  • @WilsonFraser: Many 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. Because atan2() 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
  • Desmos doesn't have a two parameter arctan, so I made an atan2 from the wiki page that you linked, which works (I tried it with the line between (x0,y0) and (x1,y1)) and gives a result between -pi and +pi. My atan2 function in Desmos is called w(y,x) because I can't call it atan2 because it thinks I mean a*tan(2). The red point is (x0,y0) and the blue point is (x1,y1). a0 is the start angle. –  May 12 '16 at 07:28
  • @WilsonFraser: Note that I defined $a_0$ and $a_1$ as angles from the center of the arc, to the start and end points, respectively. I suspect that to use your definition -- that $a_0$ is the direction of the tangent at the start point of the arc -- it might be easier to transform the coordinate system for the calculations. For example, putting $(x_0,y_0)$ at origin, $(x_1,y_1)$ at $(1,0)$. If you want, I can try and construct another answer using that approach. – Nominal Animal May 12 '16 at 21:53
  • @WilsonFraser: Also note that for graphics, Bézier curves are commonly used. For this particular case, a quadratic Bézier curve is trivial to construct, but it will not be circular. It will, however, be symmetric, and pretty nice-looking. (It is also trivial to convert a quadratic to cubic, as most computer graphics use cubic Bézier curves.) Let me know if you want to explore this, too. – Nominal Animal May 12 '16 at 21:55
  • Sometimes I find negative radius values. What does this mean? – syloc Oct 01 '21 at 23:32