# Line equations

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I need some help on this. Say I have a line (x1, y1) to (x2, y2). I calculate the half way point for this line using ((x2 + x1)/2, (y2 + y1)/2). Now I want to find a point a specific distance from my line that lies on the line perpendicular to my line and passing through the half way point, and I want the line to be pointing 'out', so if I was to rotate counter-clockwise from point 2 to point 1 the point I calculated would be in that area. Anyone have any idea how I would go about doing this?
eg.  1
'\'    * (pt to calculate)
'\'
'\'
2


##### Share on other sites

length = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )
norm_x = (x2 - x1) / length
norm_y = (y2 - y1) / length

Vector for perpendicular line:
perpen_x = -norm_y
perpen_y = norm_x

The point you want:
pt_to_calculate_x = halfway_pt_x + perpen_x * distance_to_point
pt_to_calculate_y = halfway_pt_y + perpen_y * distance_to_point

##### Share on other sites
It's simple:

calculate normal vector: let dx = x2 - x1, dy = y2 - y1. So, the normal is N = (-dy, dx), that is the normal pointing the direction you need. Normalize it (N_normalized = N / length(N) = N / sqrt((-dy)^2 + (dx)^2) = (-dy / sqrt((-dy)^2 + (dx)^2), dx / sqrt((-dy)^2 + (dx)^2))). So, now it is unit length.

Now, your desired point P (distanced in a distance D from half-way point) is

half_way + N_normalized * d (in vector terms)

[EDIT] : sorry, while I was printing, Anonimous Poster already gave the answer ))

##### Share on other sites
Thanks a lot you guys. That was very helpful.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 13
• 14
• 9
• ### Forum Statistics

• Total Topics
633365
• Total Posts
3011523
• ### Who's Online (See full list)

There are no registered users currently online

×