 Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.   ## Points in a straight line

This is a discussion on Points in a straight line within the MapPoint Desktop Discussion forums, part of the Map Forums category; I have a number of lines drawn on a map and for the purposes of a program I am writting ...

1. Senior Member Green Belt
Join Date
Sep 2003
Posts
103

## Points in a straight line

I have a number of lines drawn on a map and for the purposes of a program I am writting I need to get about 10 coordinates along the length of each line, I can get the coordinates at the end of each line but, not being particularly great at maths!!!, I cant work out how to get coordinates along the length of the line.

Does anyone know what the equation might be to do this.  Reply With Quote

2. Is this a straight line? If so:

You can derive it from the principle of like triangles. Or from vector addition.

Let your endpoints be A and B
A = (x1,y1)
B = (x2, y2)

Let Delta = A - B
ie. Delta_X = x1-x2 and Delta_Y = y1-y2

Point P on line = (xp,yp)

xp = x1 + L * Delta_X
yp = y1 + L * Delta_Y

L = Real number in the range 0...1
0 gives A, 1 gives B  Reply With Quote

3. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Thanks for your help, what i'm trying to do is plot positions within a freeform shape by using horizontal scan lines from left to right and as we move across the scan lines I need to be able to know if I have crossed a line in the shape, if i cross an odd number of lines I must be inside the shape, an even number and i'm outside.

Therefore I need to be able to work out if the x position on a particular y scan line has crossed a line in the shape so I think what I need to know is the x position on the shape for a given value of y.

I already know the coordinates for all the points on the shape.

I think this makes sense but as I said I never was any good at maths! Do you think you could help by giving me an 'idiots guide' on how I should go about doing this. Possibly using an example

Lat, Lon

Start point of line 50.83386, -0.1674
End Point 50.8335, -0.1688

So now I want to find the x(longitude) position on the line where y(latitude) = 50.8337  Reply With Quote

4. I think there was an error in my original reply - the sign of Delta is reversed.

For what you're after a "Method of Similar Triangles" is probably more appropriate but requires a diagram to be clear. Mathematically it is the same though.

Line A-B, what is X for a particular Y?
A=Ax,Ay
B=Bx,By

Like triangles gives:
(Ax-Bx) / (Ay-By) = ( X - Bx) / ( Y - By)

Note: Ay=By will give an error - you need to check for this.
As will Y = By

Re-arranging,

(X-Bx) = (Ax-Bx) * (Y-By) / (Ay-By)

=> X = Bx + (Ax-Bx) * (Y-By) / (Ay-By)

Richard  Reply With Quote

5. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Thanks for your help, i'll give this a try and i'll keep you posted  Reply With Quote

6. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Thanks for your help again, you will be pleased to here that using that equation I have now managed to write the code for working out points (addresses) within a freeform shape, this has saved me and others hours of extra work.

Thanks again for you help.  Reply With Quote

7. Glad to be of help!

Really it is just a form of linear interpolation - I've it used on everything from geometric problems to interpolating seismic velocities near salt in sedimentary basins such as the Gulf of Mexico and the North Sea!

btw, If you have any further problems, I'm available for hire... Richard  Reply With Quote

There are currently 1 users browsing this thread. (0 members and 1 guests)

line, points, straight 