calculate the new end points of line after rotating an angle

i have two lines, one is slanted line and another is a straight line. Both the lines share same X coordinate separated by distance d. The straight line is rotated to an angle θ (which also needed to be calculated from slanted line) ,making it parallel to the slanted line. Now how to calculate the new end points X2,Y2 of the rotated line?

• I used the slope equation to find the m1 of the slanted line and then converted it into angle using m=tanθ formula.
• Now how to calculate the new X2,Y2 after rotating the line?

• You may want to use $(x,y)=(r\cos\theta,r\sin\theta)$. Commented Apr 11, 2020 at 8:34

No need to compute any angles or trigonometric functions of them directly. Since you want to end up parallel to the second line segment after rotation, you already have a vector that’s pointing in the right direction, namely $$P_4-P_3$$. You just need to adjust its length and add it to $$P_0$$: $$P_2=P_0+{\lvert P_1-P_0\rvert\over\lvert P_4-P_3\rvert}(P_4-P_3).$$

• Thanks for the reply. So the P0 u mentioned above is it the points X0,Y0 + distance ? but what distance? the distance between the lines or the distance between the P0 and P2? Commented Apr 11, 2020 at 9:22
• @Balaram26 The points $P_i$ are numbered just as you have them, e.g., $P_0=(x_0,y_0)$.
– amd
Commented Apr 11, 2020 at 18:16
• will the equation be the same even when the line order changes as line P3,P4 comes first and line P0,P1,P2 comes second ? Commented Apr 12, 2020 at 12:20
• @Balaram26 I have no idea what that means. How does a line segment “come first?” The formula works no matter how these points are laid out.
– amd
Commented Apr 13, 2020 at 0:00

Let $$AB$$ the segment from $$(x_0,y_0)$$ to $$(x_1,y_1)$$. Note that when you rotate the segment $$AB$$ this point that we call $$P$$ rotates, describing an arc of angle $$\theta$$.

So, let the origin $$O(x_0,y_0)$$, and draw the perpendicular line to the segment $$AB$$ from $$S(x_2,y_2)$$. Let $$K$$ the intersection, the triangle $$SOK$$ is a right triangle. So: $$x_2=|x_1|\cos(\theta)$$ and: $$y_2=|x_1|\sin(\theta)$$ Note that we can write $$|x_1|$$ bevause we assume that the segment $$AB$$ is part of $$x-$$axis.

• Is it typo or u mean the segment moved from (x0,y0) to (x1,y1) ? because i am moving the (x1,y1) to (x2,y2) Commented Apr 11, 2020 at 9:23
• @Balaram26: please see my edits. Commented Apr 11, 2020 at 9:36
• @Balaram26: if this answer has been useful, maybe a $+1$ or a favourite answer? Commented Apr 11, 2020 at 10:09