Coordinates
Equidistant
Mathematics
Geometry
Spatial Analysis

Find equidistant points between two coordinates

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Finding equidistant points between two coordinates means dividing the segment from the start point to the end point into equal steps. This is useful in geometry, computer graphics, path sampling, and mapping. The math is simple in a flat coordinate system, but if the coordinates represent latitude and longitude on Earth, you also need to think about curvature and whether straight-line interpolation is accurate enough.

Linear Interpolation in a Flat Coordinate System

If your points are ordinary Cartesian coordinates such as (x1, y1) and (x2, y2), the standard method is linear interpolation. For any fraction t from 0 to 1, the point along the segment is:

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

That formula moves from the first point to the second by the chosen fraction of the distance.

python
1def interpolate_point(x1, y1, x2, y2, t):
2    x = x1 + t * (x2 - x1)
3    y = y1 + t * (y2 - y1)
4    return x, y
5
6
7print(interpolate_point(0, 0, 10, 20, 0.5))

The result for t = 0.5 is the midpoint, because it is halfway between the two endpoints.

Generate Several Equidistant Points

If you want n interior points between the endpoints, divide the segment into n + 1 equal parts. Then evaluate the interpolation formula at fractions:

  • '1 / (n + 1)'
  • '2 / (n + 1)'
  • and so on up to n / (n + 1)
python
1def equidistant_points(start, end, count):
2    x1, y1 = start
3    x2, y2 = end
4    points = []
5
6    for step in range(1, count + 1):
7        t = step / (count + 1)
8        x = x1 + t * (x2 - x1)
9        y = y1 + t * (y2 - y1)
10        points.append((x, y))
11
12    return points
13
14
15points = equidistant_points((0, 0), (12, 6), 3)
16print(points)

That produces three evenly spaced interior points on the line segment.

Include the Endpoints When Needed

Sometimes you want all sampled points, including the start and end coordinates. In that case, divide the segment into segments equal pieces and generate segments + 1 points.

python
1def sampled_segment(start, end, segments):
2    x1, y1 = start
3    x2, y2 = end
4    output = []
5
6    for step in range(segments + 1):
7        t = step / segments
8        output.append((
9            x1 + t * (x2 - x1),
10            y1 + t * (y2 - y1),
11        ))
12
13    return output
14
15
16print(sampled_segment((2, 4), (8, 10), 4))

This is useful for drawing evenly spaced markers along a line or generating path checkpoints.

Geographic Coordinates Need Extra Care

If the coordinates are latitude and longitude, simple interpolation of latitude and longitude values is only an approximation. For short local distances it is often good enough, but for longer distances the shortest path on Earth is a great-circle path, not a straight line in latitude-longitude space.

That means there are really two questions:

  • do you want evenly spaced points in a flat projected coordinate system?
  • or evenly spaced points along the Earth's surface?

For serious geographic work over long distances, use geodesic or great-circle interpolation from a GIS or geospatial library. Linear interpolation is best treated as a convenient approximation, not a universal answer.

Check the Distance Between Consecutive Points

A good sanity check is verifying that the step vector between consecutive interpolated points is constant in Cartesian space.

python
1def deltas(points):
2    return [
3        (points[i + 1][0] - points[i][0], points[i + 1][1] - points[i][1])
4        for i in range(len(points) - 1)
5    ]
6
7
8pts = sampled_segment((0, 0), (8, 4), 4)
9print(pts)
10print(deltas(pts))

In a flat system, those deltas should all match. If they do not, there is probably an error in the interpolation logic.

Common Pitfalls

One common mistake is forgetting whether the requested count includes the endpoints. “Five equidistant points between A and B” can mean five interior points or five total sampled points depending on context.

Another issue is using linear interpolation on latitude and longitude for long-distance geographic routes and assuming the result is exact. It is only an approximation on a curved Earth.

Developers also sometimes divide by count when they should divide by count + 1, which shifts the spacing and accidentally places a generated point on an endpoint.

Finally, make sure the coordinate system matches the problem. Flat interpolation is appropriate for Cartesian geometry, but geographic coordinates often need geodesic handling.

Summary

  • Equidistant points on a segment are usually found with linear interpolation.
  • For n interior points, evaluate the segment at fractions 1 / (n + 1) through n / (n + 1).
  • Decide explicitly whether the endpoints are part of the requested output.
  • In Cartesian coordinates, equal interpolation steps give equal spacing along the segment.
  • For latitude-longitude data over long distances, use geodesic methods instead of plain linear interpolation.

Course illustration
Course illustration

All Rights Reserved.