Help with generating parallel line

S

Shamli

Hi,
Given a line segment L1 endpoints (x1, y1), (x2, y2), and distance D.
I want to generate a new line segment L2 such that L2 is parallel to
L1 and the distance between L1 and L2 is D.
Thank you.
 
J

Jem Berkes

Given a line segment L1 endpoints (x1, y1), (x2, y2), and distance D.
I want to generate a new line segment L2 such that L2 is parallel to
L1 and the distance between L1 and L2 is D.

Those 4 points you have define a slope for the line L1
m1 = (y2 - y1) / (x2 - x1);

The line L2 will have the same slope, I haven't thought this out too
carefully but I believe the only difference (in slope-intercept form) will
be the intercept, which can differ by D to distance the lines apart.
 
K

Karl Heinz Buchegger

Jem said:
Those 4 points you have define a slope for the line L1
m1 = (y2 - y1) / (x2 - x1);

That's not a good idea. The slope may become infinite.

given
P1 ( x1, y1 )
P2 ( x2, y2 )
D

wanted
P3
P4

such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and
P3 and P4 or on the same side of the line P2 - P1

(make a drawing, all of the above are obvious from the drawing, but its
hard to describe and understand it in text form only)

Calulate:
P2 - P1, that is
dx = x2 - x1;
dy = y2 - y1;

a vector perpendicular to P2-P1 has the parameters

perp_x = dy
perp_y = -dx;

thus you just need to normalize this

len = sqrt( perp_x * perp_x + perp_y * perp_y );
perp_x /= len;
perp_y /= len;

and multiply with the desired distance

perp_x *= D;
perp_y *= D;

The points P3 and P4 are then:

P3 = P1 + perp

that is: x3 = x1 + perp_x
y3 = y1 + perp_y

P4 = P4 + perp

that is x4 = x2 + perp_x
y4 = y2 + perp_y


the line P4-P3 is parallel to P2-P1 with the given distance D
 
F

Fred L. Kleinschmidt

Shamli said:
Hi,
Given a line segment L1 endpoints (x1, y1), (x2, y2), and distance D.
I want to generate a new line segment L2 such that L2 is parallel to
L1 and the distance between L1 and L2 is D.
Thank you.

Insufficient information to creeate a unique set (x3,y3), (x4,y4). There
are an infinite number of such pairs that produce a line parallel to L1
at a distance D from it.

For example, which do you want form the below drawings?
/ /
/ /
/ /

or

/
/ /
/ /
/
 
D

David Rubin

Shamli said:
Hi,
Given a line segment L1 endpoints (x1, y1), (x2, y2), and distance D.
I want to generate a new line segment L2 such that L2 is parallel to
L1 and the distance between L1 and L2 is D.
Thank you.

What is the topology of the surface?

/david
 
D

David Rubin

Karl Heinz Buchegger wrote:

[snip]
given
P1 ( x1, y1 )
P2 ( x2, y2 )
D

such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and

Why perpendicular? For example, a parallelogram with width D is a model
of the solution, but D is not necessarily the length a line segment
perpendicular to the sides.

/david
 
K

Karl Heinz Buchegger

David said:
Karl Heinz Buchegger wrote:

[snip]
given
P1 ( x1, y1 )
P2 ( x2, y2 )
D

such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and

Why perpendicular?

Because given a line segement, constructing another line segment which is
perpendicular to it, is trivial.
For example, a parallelogram with width D is a model
of the solution, but D is not necessarily the length a line segment
perpendicular to the sides.

True.
But if the sides are perpendicular to the base line and the line segments
have length D, then their endpoints P3/P4 form a line segment parallel to P2-P1
at the desired distance D.

The goal was to create a parallel line, how to do that is left to me :)
 
K

Karl Heinz Buchegger

Karl said:
David said:
Karl Heinz Buchegger wrote:

[snip]
given
P1 ( x1, y1 )
P2 ( x2, y2 )
D

such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and

Why perpendicular?

Because given a line segement, constructing another line segment which is
perpendicular to it, is trivial.

That is: in euclidian space :)
 
K

Karl Heinz Buchegger

David said:
Karl Heinz Buchegger wrote:

[snip]
given
P1 ( x1, y1 )
P2 ( x2, y2 )
D

such that the distance from P3 to P1 equals D and
the distance from P4 to P2 equals D and
the line connecting P3 and P1 is perpendicular to the line P2 - P1 and
the line connection P4 and P2 is perpendiculat to the line P2 - P1 and

Why perpendicular? For example, a parallelogram with width D is a model
of the solution,

Oops. Sorry.
I misread this sentence.
To answer: No, a general parallelogram is not a model of the solution.
I nail the inner angles down to 90 degrees (hence P3-P1 is perpendicular
to P2-P1) and thus create a rectangle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,093
Messages
2,570,608
Members
47,228
Latest member
ValentinCh

Latest Threads

Top