Skip to main content
3 of 4
Bezier -> Bézier, while this is on the front page
LSpice
  • 12.9k
  • 4
  • 45
  • 69

Closest point on Bézier spline

Given a two-dimensional cubic Bézier spline defined by 4 control-points as described in the Wikipedia entry, is there a way to solve analytically for the parameter along the curve (ranging from 0 to 1) which yields the point closest to an arbitrary point in space?

$$ \mathbf{B}(t) = (1-t)^3 \,\mathbf{P}_0 + 3(1-t)^2 t\,\mathbf{P}_1 + 3(1-t) t^2\,\mathbf{P}_2 + t^3\,\mathbf{P}_3, ~~~~~ t \in [0,1] $$ where $\mathbf P_0$, $\mathbf P_1$, $\mathbf P_2$, and $\mathbf P_3$ are the four control-points of the curve.

I can solve it pretty reliably and quickly with a divide-and-conquer algorithm, but it makes me feel dirty…

David Rutten
  • 243
  • 1
  • 2
  • 6