1

I have the following problem. I have several points on the plain, and there is another point somewhere in the middle of them. The goal is to find angular distance between any two points.

My only thought so far is to draw a line between a central point and all the lines from the central point to all the others and see where these lines intersect the circle. If we shift the coordinates to make central point (0,0), then it becomes

x² + y² = 1 y = m*x

(m is trivial to calculate here)

x² + (m*x)² = 1

(1+m)(x²) = 1

x = ±sqrt(1/(1+m))

plus/minus is trivially resolved by seeing where the original point was in relation to the centre.

y = m*x

(Of course if the points are in vertical alignment m is undeterminant, but that is trivially resolved by setting x=0 and y to either 1 or -1).

Then i can easily through pythagorean distance find the distance of these points on the circle. But something tells me that there must be a much easier way to turn all these into a single value as projections on a circle.

v010dya
  • 137

2 Answers2

3

For two vectors $u$ and $v$, the dot product has the following property

$$ u\cdot v=|u||v|\cos\theta $$

where $\theta$ is the angle between them.

Therefore, if your centre point is $(x_0,y_0)$ and you pick two points $(x_1,y_1)$ and $(x_2,y_2)$ then the angle formed is:

$$\theta = \cos^{-1}\frac{(x_2-x_0)(x_1-x_0)+(y_2-y_0)(y_1-y_0)}{\sqrt{[(x_2-x_0)^2+(y_2-y_0)^2][(x_1-x_0)^2+(y_1-y_0)^2]}} $$

This will always be positive. To add directionality compute the term $$(x_1-x_0)(y_2-y_0)-(x_2-x_0)(y_1-y_0)$$ If it is negative then set $\theta=-\theta$.

lemon
  • 3,548
2

In a computer, there is the Atan2 function. Once you have shifted the center to $(0,0)$ the angle from the $+x$ axis to the point $(a,b)$ is $Atan2(b,a)$. The function takes care of worrying about the signs of $a,b$ to get the proper quadrant. To get the angle between two points, just subtract. If you want the result in $[0,2\pi)$ you may have to add or subtract $2\pi$. Search the site for Atan2 for many questions on the subject.

Ross Millikan
  • 374,822