# 2D - how to get a parallel line with an orthogonal distance?

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

## Recommended Posts

Hi at all! thx for answering my previous questions. No I got a simple problem. I want to draw a parallel line with an orthogonal distance in 2D space. here is a picture for an example: http://dubtissm.cabspace.com/img/code/line.gif So I know I could calculate the angle of the given line from the horizon, add 90° to the angle, and get the point above P1 via x=sin(angle+90)*distance+P1.x y=cos(angle+90)*distance+P1.y But for calculating the angle of the given line, I need the acos or asin function. These are missing on my platform. Hopefully someone could help me ;)

##### Share on other sites
An easy solution would be to use vectors.

1. Calculate the vector between the two endpoints of the line: v1 = p1-p0
2. Calculate an orthogonal vector by exchanging the x and y value and negate one component
3. Normalize the orthogonal vector
4. Multiply it with your distance and add it to both enpoints to get the endpoints of your new line

Example:

P1(2,2), P2(10,6), dist = 2

V1 = P2 - P1 = (8,4)

Orthogonal vector V2 = (-4,8) or V2 = (4,-8) depending on your offset direction

Normalize V2 = (-4,8)/len(V2) = (-4,8)/sqrt(-4²+8²) = (-4,8)/8.94 = (-0.45,0.89)

P1' = P1 + V2 * dist = (2,2) + (-0.9,1.78) = (1.1,3.78)
P2' likewise

[Edited by - Quak on October 18, 2006 12:04:05 PM]

##### Share on other sites
Quote:
 Original post by QuakAn easy solution would be to use vectors.1. Calculate the vector between the two endpoints of the line: v1 = p1-p02. Calculate an orthogonal vector by exchanging the x and y value and negate one component3. Normalize the orthogonal vector4. Multiply it with your distance and add it to both enpoints to get the endpoints of your new lineExample:P1(2,2), P2(10,6), dist = 2V1 = P2 - P1 = (8,4)Orthogonal vector V2 = (-4,8) or V2 = (4,-8) depending on your offset directionNormalize V2 = (-4,8)/len(V2) = (-4,8)/sqrt(-4²+8²) = (-4,8)/8.94 = (-0.45,0.89)P1' = P1 + V2 * dist = (2,2) + (-0.9,1.78) = (1.1,3.78)P2' likewise

Thx Quak! yes this will work.
great solution! Seems that there's no faster one.

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 9
• 11
• 9
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007067

×