Shapes & spaces

Geometric median calculator using Weiszfeld’s algorithm

Find a planar location minimizing total Euclidean distance, with coincident-point handling, convergence status and per-observation distances.

Your numbers

One x,y pair per line. Use a decimal point, at most six decimal places, and no thousands separators. Coordinates must be within ±1,000,000.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

The geometric median minimizes the sum of Euclidean distances to a set of observations. It is useful when total straight-line travel distance matters, but it differs from the centroid, which minimizes squared distances. This page uses equal weight per row, checks whether an observation itself satisfies the optimum condition and otherwise applies modified Weiszfeld iterations. Repeated rows retain their weight rather than being discarded. An explicit convergence status accompanies the returned location.

THE FORMULAMinimize F(X) = Σ|X − Pᵢ|; away from observations, Xnew = [ΣPᵢ/|X−Pᵢ|]/[Σ1/|X−Pᵢ|].

A worked example

For the four corners of a square with side two, symmetry places the geometric median at (1,1). Each corner is √2 away, so the total distance is 4√2, approximately 5.656854. With a single observation, that observation is the median and the objective is zero. The three-observation problem includes the familiar Fermat-point case on this same page.

Good to know

Supports one through 100 equally weighted planar rows on the stated coordinate grid. The result minimizes direct Euclidean distance without road networks, obstacles or facility constraints. Collinear observations can have multiple minimizing locations. Iterative outputs are approximate; a displayed iteration-limit result is not declared converged. The gap diagnostic is a floating-point estimate, not a statistical confidence interval.

Total distance gives a different location from squared distance

For collinear observations at x = 0, 0 and 10, any displacement to the right of zero increases the combined distance to the two observations at zero faster than it decreases the distance to ten. The geometric median is therefore zero. The arithmetic mean is 10/3 instead, because its squared-distance objective penalizes the remote observation much more strongly. Calling both results a center without naming the objective would hide a substantive difference.

For a noncollinear triangle whose angles are all below 120°, the distance-minimizing point has three connecting directions separated by 120°. If an angle is at least 120°, its vertex is a minimizing location. The observation-optimum check handles that case directly. There is no separate Fermat-point page in this batch because it is a special input configuration of the same sum-of-distances task.

The square center minimizes the sum of its four corner distancesMedian (1,1)Each: √2Sum: 4√2
The geometric median of the default square corners is (1,1). Each distance is √2, so the objective is 4√2. The algorithm minimizes distances rather than their squares.

The Convex hull calculator from unordered points encloses the observations. At least one geometric median lies within that hull.

Repeated and coincident observations need special treatment

Ordinary Weiszfeld weights divide by distance. If an iterate coincides with an observation, blindly applying the formula would divide by zero. The implementation checks a subgradient condition at observations and uses the modified coincident-point step when needed. Repeated rows increase the multiplicity of that location, which is part of the intended equal-per-observation weighting.

Stopping only because successive coordinates barely move can be misleading near a difficult optimum. The solver also estimates an objective gap from the subgradient and a bound on the observation hull’s diameter. It reports an iteration limit if its convergence criterion is not met. The per-observation table makes the displayed total independently checkable. The existing centroid-related tools average positions or areas under other objectives; the geometric median should not be substituted for them without deciding which distance cost actually matters.

A few questions, answered

Should I remove repeated rows?

Only if they are accidental duplicates. Each row is an observation with equal weight, so genuine repeated observations should remain.

Is the geometric median always unique?

No. For two distinct points, every point of the segment between them minimizes total distance. Some larger collinear datasets also have a whole interval of minimizers.

Find your calculator

Start typing to explore the library.