# 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

Crossposted from StackOverflow.

-

1
– Sigur Feb 10 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 at 14:53
Removed programming reference – Ankit Sharma Feb 10 at 17:15
Smaller and bigger are not appropriate terms. – julien Feb 10 at 17:17
Length of line 2 is greater then length of line 1 – Ankit Sharma Feb 11 at 14:04

## 1 Answer

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 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 at 5:14
– Ankit Sharma Feb 11 at 13:59
@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 at 14:08
i m checking the slopes of lines only but getting 		-0.7777778 and 0.999999762 :( – Ankit Sharma Feb 11 at 14:12
show 3 more comments
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 16, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9244639277458191, "perplexity_flag": "middle"}