Two line segments are intersecting... how do I rotate either line about the intersection point?

1.2k Views Asked by At

I have two line segments which are currently intersecting, how do I rotate either intersecting line about the intersection point?

How do I calculate rotation of these lines?

Rotation about a point formula:

x' = x * cos(theta) - y * sin(theta)
y' = x * sin(theta) + y * cos(theta)

But I believe this is rotation about the origin. So I need to first calculate the point of intersection. I know how to calculate the point of intersection, so let's assume I have my point of intersection.

How do I use my pointOfIntersection variable to rotate a line about this? I can plug in values for x and y, but what is theta? Is theta the angle of intersection?

1

There are 1 best solutions below

6
On BEST ANSWER

The formula for rotation around a point $(x_0,y_0)$ is

$$ x' = (x - x_0) \cos(\theta) - (y - y_0) \sin(\theta) + x_0, $$ $$ y' = (x - x_0) \sin(\theta) + (y - y_0) \cos(\theta) + y_0. $$

Conceptually, you translate everything so that the point $(x_0,y_0)$ moves to the origin, then you rotate around the origin, and finally you translate everything so that the origin goes to $(x_0,y_0)$. The effect on $(x_0,y_0)$ is that it is moved to the origin, then back to where it started.

You can use this formula for your problem if you set $(x_0,y_0)$ to the point where the lines intersect and set $\theta$ to the amount of rotation you want.