1
$\begingroup$

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.

$\endgroup$
0

2 Answers 2

3
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ Thanks a lot, especially for not requiring me to shift the space, but using x₀, y₀. $\endgroup$
    – v010dya
    Jul 3, 2014 at 16:34
  • $\begingroup$ I can't get directionality from this, can i? $\endgroup$
    – v010dya
    Jul 3, 2014 at 19:22
  • $\begingroup$ @Volodya you will have to clarify what you mean by 'directionality'. $\endgroup$
    – lemon
    Jul 3, 2014 at 20:05
  • $\begingroup$ If i understand this correctly, u⋅v = v⋅u, and thus i wouldn't be able to tell if the angle +0.3 rad or -0.3 rad, for example. $\endgroup$
    – v010dya
    Jul 3, 2014 at 20:09
  • 1
    $\begingroup$ @Volodya You are correct but there is a way of doing this (in 2D) - I have updated my answer. $\endgroup$
    – lemon
    Jul 3, 2014 at 20:16
2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Ah I never thought to use $\theta=\mathrm{atan2}(y_2-y_0,x_2-x_0)-\mathrm{atan2}(y_1-y_0,x_1-x_0)$ $\endgroup$
    – lemon
    Jul 3, 2014 at 20:26
  • $\begingroup$ @user2584283: exactly. Let the computer do the work for you. $\endgroup$ Jul 3, 2014 at 20:28

Not the answer you're looking for? Browse other questions tagged .