Jump to content
  • Advertisement
Sign in to follow this  
jaysonturner

Co-ordinates of parallel line segments.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Working in 2d. I have a line segment made up of two vectors, one for each end-point. using these vectors I wish to create another line segment parallel to it. Example 0,0 ----------------- 1, 0 x,y ----------------- x,y The space between these lines is say 5. How do I find the co-ordinates of the new line? I need a formula that will work for line segments at all angles. Is there a good c lib for performing calculations like this? Thanks for your time. Jayson.

Share this post


Link to post
Share on other sites
Advertisement
Get a 'normal' to the line, which is a direction perpendicular to it, and offset the points in that direction to create the new line.


// End-points
vec2d start;
vec2d end;

// Calculate the normal
vec2d normal;
normal.x = start.y - end.y;
normal.y = end.x - start.x;
normalize(normal);

// Create new end-points
vec2d newStart = start + normal * distance;
vec2d newEnd = end + normal * distance;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!