# How to calculate clock-wise and anti-clockwise arc lengths between two points on a circle

I have two points with known coordinates on a circle of known position and radius. I need to calculate two things:

1. The clockwise arc length between the two points on the circle
2. The anti-clockwise arc length between the two points on the circle

How would I go about doing this? Note this is 2D.

You already have one good answer, but here are some pointers to a more pedestrian method easily accessible to a student of trigonometry.

Given the Cartesian coordinates $(x_0,y_0)$ of the center of a circle in a Cartesian plane, and the coordinates $(x_1,y_1)$ and $(x_2,y_2)$ of two points on that circle, you first want to find the direction from the circle's center to each point.

In many computer programming environments you can do this with an atan2 function; as already explained in an answer to another question, the formula for the first of the points is

$$\theta_1 = \mbox{atan2}(y_1 - y_0, x_1 - x_0).$$

Alternatively, using more traditional trigonometry you can write

$$\theta_1 = \begin{cases} \tan^{-1} \left(\frac{y_1 - y_0}{x_1 - x_0}\right) & \mbox{if } x_1 - x_0 > 0, \\ \tan^{-1} \left(\frac{y_1 - y_0}{x_1 - x_0}\right) + \pi & \mbox{if } x_1 - x_0 < 0, \\ \frac\pi2 & \mbox{if } x_1 - x_0 = 0 \mbox{ and } y_1 - y_0 > 0, \\ -\frac\pi2 & \mbox{if } x_1 - x_0 = 0 \mbox{ and } y_1 - y_0 < 0, \\ \end{cases}$$

The reason this is so complicated is that $\tan^{-1}$ gives answers only in the range $(-\frac\pi2, \frac\pi2),$ which gives you the directions to points only on a semicircle, not the whole circle, so we need to do something to get the points on the other semicircle; and of course we cannot do anything at all with $\frac{y_1 - y_0}{x_1 - x_0}$ when the denominator of that ratio would be zero.

Either of these methods gives you an angle measured in the anti-clockwise sense from the direction of the positive $x$-axis to the direction from $(x_0,y_0)$ to $(x_1,y_1)$.

Once you have such angles for both points, $\theta_1$ and $\theta_2$, subtract the angle of the point you are coming from from the angle of the point you are going to, and this will give you the angle of the anti-clockwise arc from one point to the other ...

... with one small hitch, which is that the answer should be in the range $[0, 2\pi)$ since you don't need to go around the circle more than once to reach the desired point, but subtracting two angles from either of the methods above will not always be in that range.

So after computing the difference of the angles, $\theta$, if you don't have $0 \leq \theta < 2\pi$ you "normalize" the angle by adding or subtracting a whole multiple of $2\pi$ to get a result $\theta'$ that is in the range $[0, 2\pi)$.

Once you have a normalized angle $\theta'$ (measured in radians, of course!), the anti-clockwise arc length is $\theta' r$,

To get the clockwise arc length, subtract the anti-clockwise arc from $2\pi r.$

The question is slightly ambiguous as you haven't specified which point is 'first'.

Let the two points and circle centre be $p,q,c \in \mathbb{R}^2$. The following will compute the clockwise angle measured starting from $p$ to rotate to $q$.

Let $x = p-c, y=q-c$. Compute $z=(x_1 y_1+x_2 y_2, x_1 y_2-x_2y_1)\in \mathbb{R}^2$ and let $\theta = \operatorname{arg} z \in [0, 2 \pi)$ (or $\operatorname{atan2}$, if you prefer).

Then the length of the clockwise arc from $p$ to $q$ is $r \theta$, where $r$ is the circle radius. The length of the anticlockwise arc is $r (2 \pi - \theta)$.

I think of $x,y$ as being in $\mathbb{C}$ instead. I will rotate both $x,y$ by an amount so that the rotated $x$ lines up with the real axis. To do this I multiply by ${\bar{x} \over |x|}$, which would give ${\bar{x} \over |x|} y$. Since the modulus does not matter when computing the angle (other than being non zero), we can just compute $\bar{x} y$, which gives the formula above.
An advantage of this approach is that you don't need to deal with the $0-2 \pi$ thing (assuming that $\operatorname{arg}$ returns a value in $[0,2 \pi)$).
We could also notice that the first component is the inner product of $x,y$ and the second component is the cross product of $x,y$ (leaving out the vector part).