[Math] Angle between two line segments

geometrytrigonometry

Here's a question? I have two line segments which have an angle between them. For the line segments, I know coordinates of their points. I need to be able to rotate one segment for one angle (for example, $\alpha$ needs to be $60^\circ$) – it doesn't matter in which direction is angle calculated, as long as it stays persistent. Because that I only know point of line segment, idea is to rotate other point around point of intersection for desired angle, and to get coordinates for that point after rotation. But I can not come to solution which works for every angle and where rotation direction (clockwise or counter-clockwise) is persistent. $(0, 0)$ is in top left corner, as shown on picture. You don't have to bother with theory (if you don't want), I need to apply this as algorithm. Thanks
enter image description here

Best Answer

The usual rotation matrix approach works. To rotate by an angle $\theta$, you have $x'=x \cos \theta - y \sin \theta, y'=y \cos \theta + x \sin \theta$ If you apply it to all the points, the angles between lines will stay the same.

Related Question