How to rotate a line segment around one of the end points?

13.9k Views Asked by At

enter image description here

I am given x1, y1, x2, y2 and θ. How can I find x3 and y3?

By the way, there can be another line segment on the other side of AB (as if the line was rotated counter-clockwise). How to find that too?

2

There are 2 best solutions below

1
On BEST ANSWER

A straightforward way to do this is to translate the point you’re rotating around to the origin, rotate, and then translate back. This yields the formula $$ \begin{bmatrix}x_3\\y_3\end{bmatrix}=\begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}\begin{bmatrix}x_2-x_1\\y_2-y_1\end{bmatrix}+\begin{bmatrix}x_1\\y_1\end{bmatrix}. $$ Note that positive angles are conventionally taken to be counterclockwise, so if you want a clockwise rotation, either negate the angle or flip the signs of the sines in the rotation matrix.

If you use homogeneous coordinates, you can combine this into a single matrix multiplication:$$\begin{bmatrix}x_3\\y_3\\1\end{bmatrix} = \begin{bmatrix}\cos\theta&-\sin\theta&-x_1\cos\theta+y_1\sin\theta+x_1 \\ \sin\theta&\cos\theta&-x_1\sin\theta-y_1\cos\theta+y_1 \\ 0&0&1 \end{bmatrix}\begin{bmatrix}x_2\\y_2\\1\end{bmatrix}.$$ Handy for combining with other transformations, but not really any less work. If you’re rotating several points at the same time, this form points out the common factors that you can precompute for all of those rotations.

0
On

This is a short answer from @amd answer.

$x_3 = \cos (\theta)\space(x_2 - x_1) - \sin (\theta)\space(y_2 - y1)+ x_1$

$y_3 = \sin (\theta)\space(x_2 - x_1) + \cos (\theta)\space(y_2 - y1)+ y_1$