Rotate a line between x1y1 and x2y2 by angle α then finding the end of the rotated line

157 Views Asked by At

I have two points, $x$1$y$1 and $x$2$y$2 on a coordinate grid indexed in matrix convention (y increases as you go down, x increases as you go right). I want to rotate an imaginary line between $x$1$y$1 and $x$2$y$2 by angle $\alpha$ around point $x$1$y$1. Then I want to find the end of that rotated line (Where $x$2$y$2 used to be before rotation). The unit circle is also flipped in this situation, so the angle increases as you go clockwise. I've tried using rotational matrices

$$\begin{bmatrix}x_3\\y_3\end{bmatrix} = \begin{bmatrix}\cos \alpha &\sin \alpha\\-\sin \alpha & \cos \alpha\end{bmatrix}\begin{bmatrix}x_2 - x_1\\y_2 - y_1\end{bmatrix}+\begin{bmatrix}x_1\\y_1\end{bmatrix} $$

Also, I want a positive angle to rotate anti clockwise and a negative angle to rotate clockwise

But this doesn't always work, as you can see here (Look at the vehicle that says "I need to correct by ...) But sometimes it works, like at step 115, -14 should rotate the line 14 degrees clockwise, and it did. But at like step 25 it's not doing it, and I don't understand why.