0

Why does direction of vector formula produce same signed angle, even when exchanging the order of points?

For points $P=(x_1,y_1)$, $Q=(x_2,y_2)$

Angle of direction vector is

$\arctan(\theta)=\frac{y_2-y_1}{x_2-x_1}$

If we assume for example $P=(2,3)$, $Q=(5,8)$.

Then both

atan((8-3)/(5-3))*180/pi

and

atan((3-8)/(3-5))*180/pi

= 68.19859 deg

Even though visually they should be different depending on whether one goes from $P$ to $Q$ or from $Q$ to $P$?

Do I need another formula?

mavavilj
  • 7,270

1 Answers1

1

In your example, \begin{align*} \frac{y_2 - y_1}{x_2 - x_1} &= {8-3}{5-3} = \frac{5}{2} \\ \frac{y_1 - y_2}{x_1 - x_2} &= {3-8}{3-5} = \frac{-5}{-2} = \frac{5}{2} \\ \end{align*} So it's not really the arctan that's obscuring the order of the points, it's the slope formula.

In the general formula: $$ \tan \theta = m = \frac{y_2-y_1}{x_2-x_1} $$ $\theta$ is the angle measured from the positive $x$-axis to the line with slope $y=mx$. Since $m$ doesn't depend on the order of the points, $\theta$ won't either, not from this formula.

If you want an orientation-dependent vector angle formula in $\mathbb{R}^2$, you can use the cross product. If $\vec u = \left<x_1,y_1\right>$ and $\vec v = \left<x_2,y_2\right>$, then $\vec u \times \vec v = \left<0,0,x_1y_2 - x_2 y_1\right>$ will have a positive $z$-component if $\vec v$ is counterclockwise from $\vec u$, and negative if clockwise. Indeed, $$ \sin\theta = \frac{x_1y_2 - x_2y_1}{\sqrt{x_1^2 + y_1^2} \sqrt{x_2^2 + y_2^2}} $$

  • Spot on on the explanation about why it's not arctan, but can you explain other bits more? I don't intuitively understand how the $\sin$ -equation is supposed to work, i.e. what kinds of angles it produces. And e.g. how it compares to the above atan2, which seems to solve the problem very neatly. Also, why do we need $z$-components in 2d case? – mavavilj May 27 '21 at 08:23
  • I can go into more detail, but just to double-check: what angle are you interested in? The angle between the positive $x$-axis and the vector $\overrightarrow{PQ}$? Then you should use the atan2 formula. Or the angle between the direction vectors $\overrightarrow{OP}$ and $\overrightarrow{OQ}$? Then you can use the cross-product formula. – Matthew Leingang May 27 '21 at 13:10
  • The angle of the vector that connects P and Q, but I want to be able to change the anchor point. So it may be P -> Q or Q -> P or ... The atan2 does this nicely, when one first projects the difference vector to origin. – mavavilj May 27 '21 at 13:58
  • A single vector doesn't have an ”angle.” It has a direction, but an angle requires another vector to be a reference. I'm inferring from your answer that you mean angle as measured from the positive x-axis. – Matthew Leingang May 28 '21 at 17:52