# Rotating and making two lines parallel

I have two line segments with points:

Line 1 is a line through $(x_1,y_1)$ and $(x_2,y_2)$ (smaller line)

Line 2 is a line through $(x_3,y_3)$ and $(x_4,y_4)$ (bigger line)

How can I make the Line 1 (smaller) to rotate and make it parallel to Line 2 (bigger) using either:

1. $(x_1,y_1)$ as fixed point of rotation or
2. $(x_2,y_2)$ as fixed point of rotation or
3. center point as fixed point of rotation

-
I believe that here is not the best place to ask for this. Maybe here programmers.stackexchange.com – Sigur Feb 10 '13 at 14:16
Code details and implementations are off-topic here, so if you want that, you should try stackoverflow or programmers.se. If you want the math of the rotations, then I think the question should be on-topic once you remove the reference to the programming language. – Paresh Feb 10 '13 at 14:53
Removed programming reference – Ankit Sharma Feb 10 '13 at 17:15
Smaller and bigger are not appropriate terms. – 1015 Feb 10 '13 at 17:17
Length of line 2 is greater then length of line 1 – Ankit Sharma Feb 11 '13 at 14:04

You can get the angle of each line using $\text{Atan2}(x_2-x_1,y_2-y_1)$ and similar. Note that the result is radians, but you probably don't need to worry about that. Taking the difference of the angles will show how much you have to rotate, call it $\theta$. To rotate $\theta$ around $(x_1,y_1)$ you have $$x'=(x-x_1) \cos \theta+(y-y_1) \sin \theta+x_1\\ y'=(y-y_1) \cos \theta - (x-x_1) \sin \theta + y_1$$
Wat is $x$ and $y$ in above equations? – Ankit Sharma Feb 11 '13 at 4:58
$x$ and $y$ are any point you want to transform. You might not have a line segment but some more complicated shape. These equations work for any point, given that $(x_1,y_1)$ is the center of rotation. – Ross Millikan Feb 11 '13 at 5:14
@AnkitSharma: to my eye it looks like it worked if you were trying to rotate around the center of the short line. You can check that the slopes of the two lines agree: if they aren't vertical, see if $\frac {y_4-y-3}{x_4-x_3}=\frac {y_2-y-1}{x_2-x_1}$ to within numeric precision. – Ross Millikan Feb 11 '13 at 14:08