Maths & numbers
Closest pair in a point cloud
Find the nearest two points and show their distance on a plot.
A clear answer. Here’s how.
Examines all unordered pairs of 2–1,000 two-dimensional points using Euclidean distance. Exact duplicate positions give zero distance. Ties retain the first encountered pair in original input order; the output uses source CSV row numbers. Coordinates share one unit, so the resulting distance has that unit. Uses O(n²) comparisons with a stated input cap.
See a worked example
Worked example
A fixed demonstration, separate from the values you enter above.
- Point CSV
X,Y 0,0 4,0 2,1 2.2,1.1
Example result
| Source row | X | Y |
|---|---|---|
| 4 | 2 | 1 |
| 5 | 2.2 | 1.1 |
Closest Euclidean distance 0.22360679774997919. Ties use the first pair in input order; duplicate coordinates have zero distance.