Sign in to follow this  

Co-ordinates of parallel line segments.

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
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;

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this