Shapes & spaces

Sphere fitting calculator from noisy three dimensional points

Fit a sphere to spatial observations by unweighted geometric radial least squares, with residuals and a local-refinement status.

Your numbers

One comma-separated row per line.

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

Fit a sphere to spatial observations by unweighted geometric radial least squares, with residuals and a local-refinement status.

THE FORMULAmin_c,r>0 Σᵢ (‖pᵢ−c‖−r)²; radial RMS = sqrt(mean residual²).

A worked example

The six default axis observations lie on the unit sphere, yielding center (0,0,0), radius one and zero radial residual.

Good to know

4–100 distinct three-dimensional observations with full-rank algebraic sphere initialization. Finite coordinates; rescale data to moderate magnitudes (mean absolute coordinate ≤100,000). Damped geometric least-squares refinement with 100-iteration cap; rank or convergence failures throw. Unweighted local fit, not guaranteed global or robust to outliers.

Fit radial distance rather than enclosure

A sphere fit estimates a center and positive radius from spatial observations that may not lie exactly on one sphere. This page minimizes squared radial residuals: for each point, subtract the radius from its distance to the fitted center, square that difference and sum over the observations.

That objective treats observations equally and allows them to lie inside or outside the fitted surface. It is different from a minimum enclosing sphere, which must contain every point, and from an algebraic sphere fit that minimizes an expanded polynomial residual. The geometric residual has the same physical length units as the input coordinates.

Sphere fitting worked example from noisy three dimensional pointsSix axial observationsCenter (0,0,0)Fitted radius = 1
Scroll across to see the full diagram.
The six default axis observations lie on the unit sphere, yielding center (0,0,0), radius one and zero radial residual.

Compare this with the Trilateration calculator from anchor distances. Fit center and radius to many noisy points rather than intersect exact anchor-distance constraints.

Supply observations with enough spatial information

Enter between four and one hundred distinct rows of x, y and z coordinates. A full-rank sphere initialization is required, so coplanar or otherwise insufficiently informative samples are rejected. Merely supplying four rows does not guarantee that they determine a finite and numerically stable spatial sphere.

Keep coordinate magnitudes moderate and use consistent units on all three axes. Large offsets relative to the observed radius can amplify cancellation in the algebraic initialization. Translating a point cloud near the origin and rescaling it before fitting can improve numerical behavior, provided the fitted center and radius are transformed back consistently afterward.

Check the unit sphere example

The default observations are the six unit axis directions: positive and negative x, positive and negative y, and positive and negative z. Their symmetry fixes the center at the origin, and each has radial distance one. Therefore radius one gives zero residual at every observation and a zero total objective.

This exact-data example verifies both the fitted parameters and the residual convention. Perturbing one observation generally makes the residuals nonzero and shifts the geometric fit. The resulting sphere need not pass through any particular observation because the objective balances squared radial discrepancies across the whole supplied point cloud.

Initialize linearly then refine geometrically

Expanding the sphere equation makes twice the center coordinates and one auxiliary constant appear linearly. A least-squares solve provides an initial center and radius. This algebraic stage is useful for initialization, but it is not itself the final radial-distance objective reported by this calculator.

The geometric stage computes a Jacobian of radial residuals, solves for a least-squares parameter step and reduces the step length until the objective improves while preserving positive radius. Iteration stops when the correction is sufficiently small. Rank failures, unresolved refinement and the iteration limit are explicit errors rather than silently accepted fits.

Read signed residuals and RMS together

An individual residual is the observed distance from the fitted center minus the fitted radius. Positive values mean the point lies outside the fitted sphere; negative values mean it lies inside. Squaring removes that sign when computing the objective and the reported root-mean-square radial discrepancy.

RMS summarizes fit size but cannot reveal whether one point is an extreme outlier or whether errors follow a spatial pattern. Inspect the full residual list alongside the center and radius. If the cloud was measured in millimeters, both residuals and radius are in millimeters, while squared residual sums would have square-millimeter units.

Distinguish local convergence from uniqueness

A successful refinement identifies a finite local solution reached from the algebraic initializer. It does not certify a global optimum over every possible sphere. Partial spherical patches, nearly planar samples and uneven coverage can make different centers and large radii produce similar radial errors, even when the displayed residual is small.

The number of iterations is an algorithmic status, not an uncertainty estimate. Zero iterations means the initializer already met the stopping criterion, as in the symmetric default example. Noisy measurements require their own uncertainty model; the calculator does not infer confidence intervals, per-point variances or a statistically justified sphere from residual size alone.

Use residual checks for model criticism

A sphere is a restrictive model. If points lie on an ellipsoid, cylinder or warped surface, a finite sphere fit can still be computed without describing that geometry well. Structured residual signs across different regions of the cloud can signal such mismatch more clearly than a single average error.

Outliers receive a squared penalty and can move the fit substantially. Removing them requires an independently justified data decision, not a desire for a smaller residual. Weighted fitting, robust losses and outlier rejection would define different procedures and are not implied by the unweighted geometric least-squares objective on this page.

A few questions, answered

Is this a smallest enclosing sphere?

No. It minimizes unweighted squared radial residuals and can leave observations outside the sphere.

Must points lie exactly on a sphere?

No. Noisy observations are allowed;their residuals remain visible.

Why reject coplanar data?

The initialization cannot determine a unique spatial sphere from a rank-deficient design.

Is the nonlinear optimum global?

No. The finite local refinement and residual checks do not establish global optimality.

Find your calculator

Start typing to explore the library.