Find equidistant points between two coordinates

svineet picture svineet · Jan 4, 2014 · Viewed 8.5k times · Source

I have a function which needs to take out equidistant points between two points on the screen(2d).
Like this -

|--------------|

The distance is already decided. For example, I take it as 2 here, then the points I need the -

|--.--.--.--.--|

The points can be anywhere on the 2d plane, which means if I draw a line between the two points, it can be any orientation possible in a 2d plane, i.e diagonal, horizontal, etc.
I can't figure out how to do this in python.

I do not know what to google for ... And I'm 14 so I don't know any type of math for this.
I know the how to calculate distance and slope of the line, but I don't know how to proceed.
Thanks in advance!

Answer

xan picture xan · Jan 4, 2014

Given the two endpoints you can express the equation for the line in "parametric" form as

x = x1 + (x2-x1) * t
y = y1 + (y2-y1) * t

As you can verify, when t == 0, (x,y) == (x1,y1) and when t == 1, (x,y) == (x2,y2). With more investigation you can see that when t is between 0 and 1, (x,y) is on the connecting line segment, and to get a point a certain fraction of the distance between the points, set t to that fraction.

For instance, to get points with separation 2 on a distance 10 line as in your example, evaluate x and y at t = 0.2, 0.4, 0.6, and 0.8.