[Math] Rotate a line around a point in space.

geometry

I'm trying to figure this equation out before I code it.

If I have a line that starts at $(x_1,y_1)$, and ends at $(x_2,y_2)$.

I have a point not on the line, $(c_1,c_2)$ that I would like to rotate this line around to a certain angle.

Is there an equation for handling this or could you please suggest an equation to use?

Thanks,
B

Best Answer

First shift all coordinates such that the point $(c_1, c_2)$ is located at the origin, rotate and shift back to the original coordinate system

$$ \left(\begin{array}{c} x_{\rm new} \\ y_{\rm new} \end{array}\right) = \left(\begin{array}{c}c_1\\ c_2 \end{array}\right) + \left(\begin{array}{cc} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{array}\right) \left(\begin{array}{c} x_{\rm old} - c_1 \\ y_{\rm old} - c_2 \end{array}\right) $$

where $\theta$ is the angle of rotation.