Shapes & spaces

Closest point on a cubic Bezier curve calculator

Find a numerically closest point on a planar cubic Bézier segment by comparing stationary-distance candidates and both endpoints.

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

Find a numerically closest point on a planar cubic Bézier segment by comparing stationary-distance candidates and both endpoints.

THE FORMULAB(t)=Σᵢ₌₀³ C(3,i)(1−t)³⁻ⁱtⁱPᵢ; stationary candidates satisfy (B(t)−Q)·B′(t)=0.

A worked example

The default arch and query (1.5,0) have two equally near points at t≈0.146447 and 0.853553, both at distance ≈1.299038.

Good to know

Exactly four planar controls, one planar query, parameter restricted to [0,1]. Numerical degree-at-most-five stationarity polynomial with recursive derivative isolation and endpoints; near-multiple roots, very unequal scales and rounded ties are numerically sensitive. One minimizing candidate is returned, not a certified symbolic root enclosure.

Minimize distance on the actual segment

A cubic Bézier curve is determined by four planar control points, but generally passes through only the first and last. The two interior controls shape its tangents and bending. This calculator searches the curve itself for a closest point to a query, with the parameter restricted to the closed interval from zero to one.

The relevant distance is ordinary Euclidean distance between the query and a point on the curve. Distance to the control polygon is a different quantity, and a dense visual sampling may miss a narrow minimum. The stationary-point calculation supplies candidates between samples, while endpoints remain necessary candidates for a constrained segment.

Closest point on a cubic Bezier curve worked exampleTwo equally near pointsd ≈ 1.299038Compare every candidate
Scroll across to see the full diagram.
The default arch and query (1.5,0) have two equally near points at t≈0.146447 and 0.853553, both at distance ≈1.299038.

Compare this with the Cubic Bézier curve calculator from control points. Minimize distance from an external query point to the entire curve,not merely evaluate a supplied curve parameter.

Enter controls in their defining order

Provide four rows containing x and y coordinates, in order from the first endpoint through the two interior controls to the last endpoint. Enter the query as one coordinate pair. Reordering interior controls can change the curve, while reversing the entire sequence traces the same curve with parameter replaced by one minus t.

All coordinates must be finite numbers within the shared input bounds. Repeated controls are allowed because a Bézier segment can legitimately have coincident control points or reduce to a line or point. A malformed coordinate row is rejected rather than interpreted as a third spatial coordinate or an implicit missing value.

Follow the symmetric default example

The default controls are (0,0), (1,2), (2,2) and (3,0), while the query lies at (1.5,0). The curve is symmetric about the vertical line through the query. Its horizontal coordinate is three t and its vertical coordinate is six t times one minus t.

Two symmetric parameter values, approximately 0.146447 and 0.853553, give the same minimum distance of about 1.299038. The middle parameter one half is stationary as well, but its distance is 1.5 and is not minimal. This example shows why finding one stationary point is insufficient and why ties are possible.

Build every stationary candidate numerically

Differentiating squared distance removes the square root and gives twice the dot product of the displacement with the curve derivative. A cubic displacement multiplied by a quadratic derivative produces a polynomial of degree at most five. Its roots inside the parameter interval are the interior candidates for a minimum.

The implementation recursively finds derivative roots to split the interval into monotone pieces, then bisects sign-changing pieces and checks critical boundaries. Both endpoints are added regardless of stationarity. This bounded numerical procedure handles lower-degree polynomials too, but nearly multiple roots can be sensitive to coefficient scale and finite precision.

Read the candidate table before selecting a tie

Each candidate records its parameter, point coordinates and distance. The returned closest point is one candidate with smallest computed distance; several rows can tie within rounding. Verify a row by substituting its parameter into the Bézier equation and measuring its displacement from the query in the same coordinate units.

At a regular interior stationary point, the displacement is perpendicular to the curve tangent. That orthogonality check explains the stationarity equation but does not distinguish a maximum from a minimum. Comparing all candidate distances, including endpoints, is therefore the decisive final step rather than assuming every normal projection is closest.

Handle endpoint and degenerate cases

A query beyond a short curve segment can have an endpoint as its closest point even when the corresponding infinite extension has a nearer projection elsewhere. Restricting t to zero through one preserves the intended segment. Any stationary root outside that interval is deliberately excluded from the candidate table.

When all controls coincide, the curve is constant and every parameter maps to the same point. More generally, algebraic degree can drop when the controls describe a line or quadratic. Those cases do not justify dividing by a coefficient that has vanished; the numerical root routine trims negligible leading terms before processing the remaining polynomial.

Interpret numerical precision and scale

This calculator returns a numerical minimizer, not an exact symbolic guarantee for arbitrarily ill-conditioned data. Rescale very large or very small coordinates when candidate roots cluster or when a tiny perturbation changes which tied point is chosen. Keep the query and controls in the same units during that rescaling.

For practical auditing, inspect the full candidate table and compare any nearly equal distances at appropriate precision. A changed chosen parameter after rounding may still describe an equally good symmetric solution. The parameter is not arc length, so equal parameter intervals along the curve should not be interpreted as equal traveled distances.

A few questions, answered

Can the nearest point be an endpoint?

Yes. Both endpoints are compared with all isolated interior stationary candidates.

Can the nearest point be nonunique?

Yes. The symmetric default has two equal minima;one minimizing candidate is returned and the table preserves both.

Are repeated controls allowed?

Yes. Coincident controls can define a valid lower-degree curve or a constant point.

Is the control polygon the curve?

Usually not. Its interior segments influence the curve but are not the distance target.

Find your calculator

Start typing to explore the library.