# Parallel line

5 replies to this topic

### #1elijah

New Member

• Members
• 21 posts

Posted 18 November 2009 - 06:30 PM

I know that for a line to be parallel , the vector ( dir ) of the line must be the same. I have a line in 3d and I need to create another parallel line above and below the existing line at a given offset. Can anybody help me or give me some idea on how to accomplish this. I thought of just adding so offset value for the given axis on the the origin of the line. But I do not know whether this is correct?

### #2Mihail121

Senior Member

• Members
• 1059 posts

Posted 18 November 2009 - 06:40 PM

elijah said:

I know that for a line to be parallel , the vector ( dir ) of the line must be the same. I have a line in 3d and I need to create another parallel line above and below the existing line at a given offset. Can anybody help me or give me some idea on how to accomplish this. I thought of just adding so offset value for the given axis on the the origin of the line. But I do not know whether this is correct?

It's not possible. Think abou it: what does "above" or "below" mean given we have three dimensions? You need just one more primitive (i.e. point) to fix a plane and then you can place additional lines. Non-zero offset of both the points will indeed result in a parallel line, although the concept of below or above will still not exist.

### #3Reedbeta

DevMaster Staff

• 5311 posts
• LocationSanta Clara, CA

Posted 18 November 2009 - 06:43 PM

Mihail is technically correct. But, let's assume you have an "up vector" that defines what the global up/down direction is. (This might commonly be <0, 1, 0> if you use Y-up or <0, 0, 1> if you use Z-up.)

You already know a line is defined by a point and direction. To create another parallel line you keep the same direction and just move the point. So, to create a second line 5 units above the first, you would add 5 times your up vector to the point.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #4TheNut

Senior Member

• Moderators
• 1701 posts
• LocationCyberspace

Posted 18 November 2009 - 08:09 PM

Calculate the cross product with the perpindicular vector to find an "up-vector". It's not guaranteed to be "up" per-say, it could just as easily point down, but you could define "up" as positive Y (or Z) and use that against the vector. Then just follow Reedbeta's instructions.
http://www.nutty.ca - Being a nut has its advantages.

### #5elijah

New Member

• Members
• 21 posts

Posted 19 November 2009 - 01:22 AM

Here is my pseudo code from your suggestion "TheNut" & "ReedBeta"

Given
LINE = A + t * D

From the Line we can get
SP = Start Point
EP = End Point

UPVECTOR = SP x EP

What do I do now after getting the UPVECTOR. To get 5 times UPVECTOR * 5 ? Then what do I do next ???

### #6Reedbeta

DevMaster Staff

• 5311 posts
• LocationSanta Clara, CA

Posted 19 November 2009 - 01:30 AM

That calculation for upvector won't necessarily work. For now just use either <0, 1, 0> or <0, 0, 1> as your up vector, depending on whether Y or Z is up in your system.

Then just add it to A, the origin point of the line.
reedbeta.com - developer blog, OpenGL demos, and other projects

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users