Shapes & spaces

Cylinder fitting calculator from noisy 3D points with a free axis

Fit an infinite circular cylinder with a freely varying axis to spatial observations by local orthogonal radial least squares.

Your numbers

Enter finite values within the stated bounds; coordinate rows may use commas.

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 an infinite circular cylinder with a freely varying axis to spatial observations by local orthogonal radial least squares.

THE FORMULAmin Σ(di−r)²; di=||(pi−c)−w[w·(pi−c)]||; ||w||=1; r=mean(di).

A worked example

Sixteen default points on two unit-radius rings at z=−1 and z=1 recover radius1 and the vertical axis, with residuals at floating rounding scale.

Good to know

8–100 finite3D observations with full spatial spread. Six deterministic starts and converged local fits; positive fitted radius and bounded parameters. Not an enclosing cylinder, not a global-optimum or uniqueness certificate; axis direction sign arbitrary.

Fitting differs from enclosing points

A fitted cylinder minimizes deviations from a circular cylindrical surface. Some measured points can lie inside it and others outside it. An enclosing cylinder instead requires every observation to remain inside its boundary and can be strongly controlled by a single extreme point.

This calculator also estimates the axis rather than requiring its direction as a fixed input. The result is an infinite circular cylinder, described by a unit direction, a point on its axis and a radius. End caps and an enclosing height are not part of the fitting objective.

Two rings identify a cylindrical axisRadius = 1Axis direction (0,0,1)Local radial least squares
Scroll across to see the full diagram.
The default rings have radius1 and lie at z=±1; their shared axis is vertical.

Compare this with the Minimum enclosing cylinder calculator with a fixed axis direction. Fit the axis and radius by orthogonal least-squares residuals, rather than enclose all observations with an already fixed axis.

What the observations must describe

Enter spatial points sampled from a cylinder in one consistent length unit. Useful data cover several angular positions and more than one axial level. A single ring, a line of points or a very small surface fragment cannot reliably identify all cylinder parameters from the same information.

The implementation checks that the sample spans three spatial dimensions before fitting. This is necessary but does not establish unique identification of every noisy configuration. Limited angular coverage, a very short axial span or an almost spherical sample can still make a local cylinder estimate sensitive to perturbations.

A directly checkable cylindrical sample

The default points lie on two rings with radius one, centered on the z axis at heights minus one and plus one. Each ring contains eight equally spaced angular observations. Every point is therefore exactly one unit from the same vertical line.

The recovered radius is one and the axis direction is vertical, up to an irrelevant sign. Orthogonal radial residuals are near floating rounding scale. Replacing the default coordinates with a rotated and translated version should recover the same radius and the correspondingly transformed axis line.

Removing the redundant axis coordinate

Moving a chosen axis point along its own direction leaves the infinite cylinder unchanged. Treating that displacement as a free fitting variable introduces a redundant parameter. The implementation removes it by reporting the point on the fitted axis aligned with the sample-centroid reference plane.

For a candidate unit direction and transverse center, radial distances are perpendicular distances to the line. The best radius for those distances is their mean. Substituting that mean into the residual sum leaves a four-parameter geometric search instead of optimizing an unnecessary axial position or an independent radius.

Why several starts are used

The objective is nonlinear in axis direction, so one local search is not enough to justify a broad claim. Starting directions include the sample's principal axes and coordinate directions. Each successful optimization must converge to a finite valid parameter set before it can enter the comparison.

The displayed fit is the converged candidate with the smallest observed objective. Its number of converged starts and iteration count are diagnostics, not a proof of global optimality. An unvisited basin could contain another solution, and several different parameterizations may describe the same axis line.

Interpreting radius and residuals

The root-mean-square residual summarizes radial discrepancies, including both positive and negative deviations. A small value means the points lie near the fitted surface under this objective. It does not directly measure uncertainty of the axis or a confidence interval for the radius.

Inspect the residual list rather than relying only on its average. A few large errors can reveal a noncylindrical shape, bad measurements or uneven sampling. The least-squares objective is not robust to outliers; a different metrology convention or robust estimator can produce another defensible fitted cylinder.

Before treating the result as a measurement

Repeat the calculation after sensible translation, rotation and unit scaling. Geometric residuals should transform consistently. Compare against a known synthetic cylinder first, then perturb its points at the scale of the expected measurement noise to understand parameter sensitivity for your particular sampling layout.

Use a fixed-axis enclosure calculator when every observation must be contained, and a finite-cylinder construction when cap positions matter. This page answers a local surface-fitting question. It does not certify manufacturing tolerances, reject outliers automatically or infer physical confidence limits from an unspecified error model.

A few questions, answered

Does the cylinder contain every point?

Not necessarily. Radial least squares permits points on both sides of the fitted surface.

Is the fitted axis unique?

No uniqueness claim is made. Limited sample coverage can make different axes nearly equivalent.

Why can the direction reverse?

The vectors w and minus w describe the same infinite axis line.

Are height and end caps estimated?

No. The model is an infinite circular cylinder; cap positions require an additional convention.

Find your calculator

Start typing to explore the library.