Rotate and translate a line so that it passes through two given points

1.5k Views Asked by At

I have 2 point and a line segment in 2d space. The line only rotates and translates using its mid point.

How do I calculate the translation and rotation required for the line to be touching the 2 points with center in the middle?

I know the initial state of the line, so calculating translation is easy $$ (x',y') = \frac{p_1+p_2}{2} -[\text{line center}] $$ Can you please tell me how to calculate the rotation?

Thanks!

2

There are 2 best solutions below

6
On BEST ANSWER

It comes down to the following: we want to rotate the line so that it is parallel to the other segment. Once we have this, the translation will ensure that the lines overlap (since they both intersect and have the same slope).

In order to find the necessary angle of rotation, find the angles (relative to the $x$-axis) at which the starting line and the target line, then take the difference. If $m_1$ and $m_2$ are the respective slopes of the starting line and the target line, then the angle of rotation necessary is $$ \theta = \tan^{-1}(m_2) - \tan^{-1}(m_1) $$

2
On

Let $a$ be the distance from the center point to one of the given points (say p1). Let $b$ be the distance from the center point to one end of the line segment Let $c$ be the distance from p1 to the same end of the line segment. Use the Law of Cosines $c^2=a^2+b^2-2ab\cos{\theta}$ and solve for $\theta$.