11
$\begingroup$

Given two points $p_1$ , $p_2$ around the origin $(0,0)$ in $2D$ space, how would you calculate the angle from $p_1$ to $p_2$?

How would this change in $3D$ space?

$\endgroup$
3
  • 10
    $\begingroup$ There is no angle between two points... Do you mean the angle between the points at the origin? Maybe? $\endgroup$ Commented Jul 20, 2010 at 19:44
  • $\begingroup$ Regarding the 3d space problem, you will basically need to measure the angle in spherical co-ordinates, so two angles. This is after adding in the twin requirements of an origin point and origin vector to measure angle from (as alluded to in the previous comment) $\endgroup$
    – workmad3
    Commented Jul 20, 2010 at 19:50
  • $\begingroup$ Yes, it's safe to assume a given origin (0,0). $\endgroup$ Commented Jul 20, 2010 at 19:57

4 Answers 4

12
$\begingroup$

Assuming this is relative to the origin (as John pointed out): Given two position vectors $\vec p_1$ and $\vec p_2$, their dot product is:

$$\vec p_1\cdot \vec p_2 = |\vec p_1| \cdot |\vec p_2| \cdot \cos \theta$$

Solving for $\theta$, we get:

$$\theta = \arccos\left(\frac{\vec p_1 \cdot \vec p_2}{|\vec p_1| \cdot |\vec p_2|}\right)$$

In a 2D space this equals:

$$v = \arccos\left(\frac{x_1x_2 + y_1y_2}{\sqrt{(x_1^2+y_1^2) \cdot (x_2^2+y_2^2)}}\right)$$

And extended for 3D space:

$$v = \arccos\left(\frac{x_1x_2 + y_1y_2 + z_1z_2}{\sqrt{(x_1^2+y_1^2+z_1^2) \cdot (x_2^2+y_2^2+z_2^2)}}\right)$$

$\endgroup$
2
$\begingroup$

I will assume that you mean the angle of the line from $p_1$ to $p_2$ with respect to the $x$-axis

This is the best I can do given the information you have provided.

In any case, the official mathsy way would be to find the dot product between the two, and divide by the magnitude of $p_1-p_2$ and take the arccossine. $$ \begin{aligned} v &= (\text{normalized vector from } p_1 \text{ to } p_2) \\ \theta &= \arccos( v \cdot \langle1,0\rangle) \qquad\qquad\qquad\qquad (\text{dot product}) \end{aligned} $$ You can normalize a vector by dividing every term by the magnitude (length) of the entire vector.

For 3D, the same thing applies:

$$ \theta = \arccos( v \cdot \langle1,0,0\rangle ) \qquad\qquad (\text{dot product}) $$


You could also possibly mean the angle between the line from the origin to $p_1$ and the line from the origin to $p_2$.

You can do this with dot products, as well; but both vectors must be normalized.

$$ \theta = \arccos( a \cdot b ) \qquad\qquad (\text{dot product}) $$

where $a$ is the normalized vector from the origin to $p_1$ and $b$ is the normalized vector from the origin to $p_2$.

$\endgroup$
0
$\begingroup$

Let the two points be $(x_1,y_1)$ and $(x_2,y_2)$ then angle $\theta$ between them $=$
$$\theta=\tan^{-1}{\frac{y_2}{x_2}}-\tan^{-1}{\frac{y_1}{x_1}}$$

$\endgroup$
2
  • $\begingroup$ What's wrong? its correct... $\endgroup$ Commented May 15, 2018 at 15:32
  • $\begingroup$ Yes, this answer is perfectly correct in two dimensions. You might want to specify the limits of validity of the inverse tangents to improve it. @LionHeart's comment makes no sense at all. $\endgroup$ Commented Jul 22, 2022 at 22:43
0
$\begingroup$

In case you want to implement it on some programming language.

Usually there is a function called like $\operatorname{atan2}(y, x)$ which returns oriented angle between points $(x, y)$ and $(1, 0)$. In that case use could use

$$\operatorname{atan2}(\text{vector product}, \text{scalar product}). $$

This is usually more stable than using just $\arccos$ or $\arcsin$.

$\endgroup$
1
  • 1
    $\begingroup$ Im not quite sure what your answer is. And speaking in terms of mechanical programming languages does not really express the mathematical concept and understanding that us mathematicians are going for. $\endgroup$ Commented Feb 12, 2013 at 2:07

You must log in to answer this question.

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