Formula for endpoints of a parallel line?

SharkNose

New member
Joined
Oct 16, 2005
Messages
8
Ok, I've been wracking my brain over this for 2 weeks. It's time to call in the experts.

See diagram below. Using the coordinate system shown and given Line A with endpoints at coordinates x1, y1 and x2, y2. Can you give me a formula(s) that takes the endpoints of Line A (x1, y1 and x2, y2) and will produce the endpoints of Line B (s1, t1 and s2, t2), where Line B is parallel to Line A and Line B is exactly 5 units away from Line A? An imaginary line from s1, t1 to x1, y1 is 5 units in length and perpendicular to Line A. Line B's length will equal that of Line A. Likewise, I'll need another formula(s) to produce another parallel line, Line C, on the opposite side of Line A.

This is for a railroad computer simulation where a user will draw a line representing a railroad track. I want the computer to be able to draw a parallel track above or below the original exactly 5 units away from the original and the same length as the original. The original track drawn (Line A) can be in any direction.

Thank you for your assistance.

Andrew

Coords.GIF
 
Distance labled '5' is almost '6'!!

What do you know about Pythagorean Triples? Ponder a 3-4-5 Right Triangle and see if it doesn't solve your problem.
 
Pythagorean Triples

tkhunny said:
Distance labled '5' is almost '6'!!

What do you know about Pythagorean Triples? Ponder a 3-4-5 Right Triangle and see if it doesn't solve your problem.

That doesn't look like a formula to me... :)

The diagram is rather crude and I estimated the 5 side.

Well, math is definitely not my forte, so up to a few minutes ago, I didn't know what Pythagorean Triples were. Now that I've looked them up, I think the triple that I want is [5,12,13] since the 5 will always be my shortest side.

I will ponder this some more, but if I get stuck, I'll be back. Thanks.

Andrew
 
Way to go on looking up something with which you were not previously familiar. That takes some courage.

Trust me on this, you will need the 3-4-5. It's a right triangle. The two short sides are the perpendicular legs. It's the long side that should interest you.
 
I think your own diagram is confusing you!

Look at line (s1,t1) to (x1,y1) which you show = 5;
that's the hypotenuse of a 3-4-5 right triangle.
Your diagram shows the vertical distance between these 2 points also as 5;
that should be 4: redo your diagram such that (x1,y1) moves up a square:
then it'll be apparent that you're working with 3-4-5 triangles (as per TK).
Notice that the horizontal distance between these 2 points is properly
shown as 3: right? Good job on that part!
 
Denis said:
I think your own diagram is confusing you!

:lol: That's entirely possible, Denis, and not uncommon for me.

Below is a revised diagram where the points aren't so neatly placed as before. The 5 length is pretty accurate this time. I understand where you and tkhunny were going with the 3-4-5 right triangle, but I think you were putting the perpendicular legs in the wrong spot.

The user's Line A will start on integer coordinates, but the calculated Lines B and C may not.

Hopefully, I didn't confuse myself more and take you with me. :shock:

Coords2.GIF
 
OK. I see your point. I was telling you where to find a couple of points that were exactly 5 from your starting points. I was NOT telling you how to find that point that is exactly five from your starting points such that the slope of the adjoining line segment was perpendicular to your original line. Very good. Way to hang in there.

Can you find the equation of your line?

y - 5 = [(5-15)/(14-5)]*(x-15)

That will be very helpful.

It would also be helpful if you flipped your y-axis over. It is very unusual to have the positive y-axis going down. It's OK, if that's what you REALLY want, but it wouldn't normally be recommended.
 
tkhunny said:
Can you find the equation of your line?

y - 5 = [(5-15)/(14-5)]*(x-15)

That will be very helpful.

I'm not sure what that means. The only equations I have been able to figure out on my own are the length of Line A:

SQRT( ( x2 – x1 ) ^2 + ( y2 – y1 ) ^2 ) =

SQRT( ( 14 – 5 ) ^2 + ( 5 – 15 ) ^2 ) =

SQRT( 9 ^2 + -10 ^2 ) =

SQRT( 81 + 100 ) =

SQRT( 181 ) = 13.453624

and the slope of Line A:

Code:
 y2 – y1      5 – 15      -10
--------- = --------- = ------ = -1.111111
 x2 – x1      14 – 5        9

which I believe works out to an angle of 48.013 degrees.

Now where these two figures help me out to discovering the points s1, t1 and s2, t2, I have no idea. This is where I got stuck and do not know how to proceed toward my goal.

I am kind of resigned to having the y-axis in that direction as computer graphics originate in the upper left of the screen and are plotted that way. It would complicate matters more if I were to translate everything to put 0,0 at the lower left. One problem at a time, please. :)

Andrew
 
It's fine to have +y going down. You just have to make sure you communicate that and remember that. It is unusual, but I wouldn't call it "wrong".

You seem to have no background in algebraic methods. The most straight forward method might be basic geometry. Can you use your software to draw circles with a given center and radius?
 
tkhunny said:
You seem to have no background in algebraic methods. The most straight forward method might be basic geometry. Can you use your software to draw circles with a given center and radius?

High School was 30 years ago for me, so anything I learned then about geometry is long gone. I can't even find my books from then. Searching the Internet for the solution to this problem has brought back a few basic principles. My background is computer programming, but I have never had an application require this sort of math formula before.

Yes, I can draw circles, but what I'm looking for is simply this:

Input -> x1, y1 and x2, y2 of Line A

Output -> s1, t1 and s2, t2 of Line B

At least I thought it was simple. Since you mentioned circles and radius, can we find a point on a circle with radius of 5 and center point of x1, y1 ? Will this accomplish what I'm looking for? Can we use the angle that I found of Line A at all?

Thanks again for your time.
 
It is not all that difficult a problem. There are many ways to go about it. The trouble is finding a way that is comprehensible.

I'll try to lay it out sequuentially. I think I would suggest the following:

1) Use your points to find the equation of the line defined by those two points. Notice the slope before you put it in Standard Form

(5,15) (14,5)
y-5 = [(5-15)/(14-5)]*(x-14)
y-5 = (-9/10)*(x-14) ==> Slope = -9/10
10*x + 9*y - 185 = 0

2) Construct the two lines perpendicular to the given line and through the given points. This requires the slope of the line. Multiplying the slopes of perpendicular lines produces -1, so the slope of the lines we want is +10/9.

y-15 = (10/9)*(x-5) ==> y = (9/10)*x + (21/2)
y-5 = (10/9)*(x-14) ==> y = (9/10)*x - (38/5)

3) Construct the locus of points of distance 5 from each of your points. This is a circle.

(x-5)<sup>2</sup>+(y-15)<sup>2</sup> = 5<sup>2</sup>
(x-14)<sup>2</sup>+(y-5)<sup>2</sup> = 5<sup>2</sup>

4) Solve the formulas from 2) and 3) by substitution.

y = (9/10)*x + (21/2)
(x-5)<sup>2</sup>+(y-15) = 5<sup>2</sup>
Substituting
(x-5)<sup>2</sup>+(((9/10)*x + (21/2))-15)<sup>2</sup> = 5<sup>2</sup>
Quadratic Formula give:
x = 5 + 50/sqrt(181)
x = 5 - 50/sqrt(181)
These are the x-coordinates of the two points that are a distance of 5 from (5,15)

y = (9/10)*x - (38/5)
(x-14)<sup>2</sup>+(y-5)<sup>2</sup> = 5<sup>2</sup>
Substituting
(x-14)<sup>2</sup>+(((9/10)*x - (38/5))-5)<sup>2</sup> = 5<sup>2</sup>
Quadratic Formula give:
x = 14 + 50/sqrt(181)
x = 14 - 50/sqrt(181)
These are the x-coordinates of the two points that are a distance of 5 from (14,5)

5) The four x-coordinates can be used to find the corresponding four y-coordinates.
 
Another way, using similarity.

I'll use top right quadrant.
Line A has given endpoints A(x1,y1) and B(x2,y2)
I'll use line B only (above line A); endpoints D(x3,y3) and C(x4,y4)

After you draw line AB, all you need to do is make rectangle ABCD with
sides AD and BC = 5; then draw rectangle EFGH around rectangle ABCD,
such that A is on EF, B is on FG, C is on GH and D is on HE.

For illustrative purposes, I'm setting it up like this:
Code:
H                        C    G

                              B

D

E    A                        F
We now have 2 identical triangles ADE and BCG, and 2 identical triangles
ABF and CHD; ADE is similar to ABF.

Triangle ABF: BF=a, AF=b, AB = c.
Triangle ADE: AE=d, DE=e, AD=f (given as 5 in your problem).

a = y2-y1, b=x2-x1, c = sqrt(a^2 + b^2); similarity means:
f/d = c/a : d = af/c
f/e = c/b : e = bf/c

x3 = x1 - d, y3 = y1 + e
x4 = x2 - d, y4 = y2 + e

Example:
Given: x1=11,y1=4,x2=23,y2=13, f=5
So A(11,4) and B(23,13)
b=23-11 = 12, a = 13-4 = 9 : c = sqrt(9^2 + 12^2) = 15.

d = af/c = 9(5)/15 = 3
e = bf/c = 12(5)/15 = 4

x3 = x1 - d = 11 - 3 = 8, y3 = y1 + e = 4 + 4 = 8; so D(8,8)
x4 = x2 - d = 23 - 3 = 20, y4 = y2 + e = 13 + 4 = 17; so C(20,17)
 
Now we're getting somewhere. This is great, tkhunny! :D I completed your equations and came up with this:

s1 = 1.284
t1 = 11.655

s2 = 10.284
t2 = 1.655


u1 = 8.716
v1 = 18.345

u2 = 17.716
v2 = 8.345

It looks like my estimate of the points of the parallel lines in my 2nd diagram were pretty close to the mark. :)

One question though:

tkhunny said:
2) Construct the two lines perpendicular to the given line and through the given points. This requires the slope of the line. Multiplying the slopes of perpendicular lines produces -1, so the slope of the lines we want is +10/9.

y-15 = (10/9)*(x-5) ==> y = (9/10)*x + (21/2)
y-5 = (10/9)*(x-14) ==> y = (9/10)*x - (38/5)

I understand where to put my original points and slope into the equations, but I do not understand where the (21/2) and (38/5) came from. :?:

And Denis, I plugged my coordinates into your similarity example and came up with the same results for s1, t1 and s2, t2:

s1 = 1.284
t1 = 11.655

s2 = 10.284
t2 = 1.655

I had to change plus to a minus on the calculation of the y coordinates, I guess because of my y-axis being reversed.

Both methods will work and it's good to have a choice when I go to translate all this into Visual Basic or C#.

Andrew
 
SharkNose said:
I had to change plus to a minus on the calculation of the y coordinates, I guess because of my y-axis being reversed.
I think all you need to do is use the absolute value when you subtract
coordinates; in Basic: abs(x1-x2).
Then there's no need to worry about negative distances; right, TK?
 
y-15 = (9/10)*(x-5)
y-5 = (9/10)*(x-14)
It's just algebra, but it appears I was having a bad day. Frankly, the upside down axes are still bugging me. It shouldn't be that much trouble.

The slope of the original line is -10/9
The slope of these perpendicular lines is 9/10
Note that (-10/9)*(9/10) = -1, as required.

Let's see if I can do it with a couple fewer errors.

y-15 = (9/10)*(x-5)
y-15 = (9/10)*x - (9/10)*5
y-15 = (9/10)*x - (9/2)
y-15+15 = (9/10)*x - (9/2) + 15
y = (9/10)*x - (9/2) + (30/2)
y = (9/10)*x + (21/2)

y-5 = (9/10)*(x-14)
y-5 = (9/10)*x - (9/10)*14
y-5 = (9/10)*x - (9/5)*7
y-5 = (9/10)*x - (63/5)
y-5+5 = (9/10)*x - (63/5) + 5
y = (9/10)*x - (63/5) + (25/5)
y = (9/10)*x - (38/5)

I have no idea how these correct formulas managed to get into the calculations already shown, but they did.
 
I understand what you're doing with your equations now, tkhunny. Thank you for being patient and stepping through them for me.

When I get my program creating parallel lines, I'll post back and show you a screen shot or 2.

Thanks again! :D

Andrew
 
Success!!!

8-) 8-) 8-)

Here we go! The black lines were created with the mouse. The red lines are the calculated s1, t1 - s2, t2 line and the blue lines are the calculated u1, v1 - u2, v2 line. All were done programmatically in Visual Basic.

Coords3.gif


I had to make some adjustments to allow for the direction of the line. And the vertical and horizontal lines were handled separately (they were easy!) As you can see the results are perfect!

Thanks again, gang! I really appreciate your help.

Andrew
 
Nice! Looks like a real busy railroad station :roll:

For your next assignment:
the coordinates of square ABCD are given:
1: draw a square inside ABCD, sides at distance x from ABCD's sides
2: draw a square outside ABCD, sides at distance x from ABCD's sides
 
Top