4
$\begingroup$

There are three points with $(x,y)$ coordinates, $A=(x_1, y_1), B=(x_2, y_2), C=(x_3, y_3)$. I want to find out the change of direction if you follow a straight line from $A$ to $B$ and then from $B$ to $C$, which will be the $\theta$ angle in the figure.

The magnitude of $\theta$ is easy to compute using dot product. If we define $\mathbf{v}=(x_2-x_1, y_2-y_1)$ and $\mathbf{w}=(x_3-x_2, y_3-y_2)$, then $\theta=\arccos \frac{\mathbf{v}\cdot \mathbf{w}}{\lVert \mathbf{v}\rVert \lVert \mathbf{w}\rVert}$.

Here is my question. I am also interested in whether $\overrightarrow{BC}$ lies to the left of direction of $\overrightarrow{AB}$ (as shown in the figure) or to the right. How do I get that in a simple way?

enter image description here

$\endgroup$
3
$\begingroup$

Let $\mathbf{v}=(v_1, v_2)$ and $\mathbf{w}=(w_1, w_2)$ be the vectors. The sine of the angle $\theta$ going from $\mathbf{v}$ to $\mathbf{w}$ is proportional to the following determinant:

$$D=\begin{vmatrix} v_1 && v_2 \\ w_1 && w_2 \end{vmatrix}$$

If $D>0$ then you are turning left; otherwise, you are turning right.

Note that this is simply the relevant computation when lifting both vectors to $\mathbb{R}^3$ and using the cross product.

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

You can lift the situation from $\mathbb R^2$ to $\mathbb R^3$ by setting $\vec a = \begin{pmatrix} \vec v \\0 \end{pmatrix}$ and $\vec b = \begin{pmatrix} \vec w \\0 \end{pmatrix}$, and then using the cross product:

If $\vec a \times \vec b$ has positive $z$ coordinate, you get one direction, if it has a negative $z$ coordinate you get the other one.

An alternative aproach (but when it comes to the calculation it is basically identical) is first calculating a perpendicular vector $\vec v^\perp := \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}\vec v$ and then seeing wheter the scalar product $\vec v^\perp \cdot \vec w$ is greater or less than zero.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.