Intersections Between a Cubic Bézier Curve and a Line

The calculations are roughly the same regardless of what line is used.

Suppose the line has equation $lx+my+nz = d$. In vector form, this is $$ \mathbf{A}\cdot \mathbf{X} = d, $$ where $\mathbf{A} = (l,m,n)$. Also, suppose the Bézier curve has equation $$ \mathbf{X}(t) = (1-t)^3\mathbf{P}_0 + 3t(1-t)^2\mathbf{P}_1 + 3t^2(1-t)\mathbf{P}_2 + t^3\mathbf{P}_3 $$ Substituting this into the previous equation, we get $$ (1-t)^3(\mathbf{A} \cdot \mathbf{P}_0) + 3t(1-t)^2(\mathbf{A} \cdot \mathbf{P}_1) + 3t^2(1-t)(\mathbf{A} \cdot \mathbf{P}_2) + t^3(\mathbf{A} \cdot \mathbf{P}_3) - d = 0 $$ This is a cubic equation that you need to solve for $t$. The $t$ values you obtain (at most 3 of them) are the parameter values on the Bézier curve at the intersection points. If any of these $t$ values is outside the interval $[0,1]$, you'll probably want to ignore it.

In your particular case, you know that the line passes through either the start-point or the end-point of the Bézier curve, so either $t=0$ or $t=1$ is a solution of the cubic equation, which makes things easier. Suppose $t=0$ is a solution. Then the cubic above can be written in the form $$ t(at^2 + bt + c) =0 $$ Now you only have to find $t$ values in $[0,1]$ that satisfy $at^2 + bt +c =0$, which is easy.


this can be solved analytically, by solving a cubic function within a cubic function, one rather complicated cubic function.

getting a points closest euclidean [distance to a cubic bezier] is solved on shadertoy.com

doing that for all points along a line gives you a cubic function with 1 or 2 local minima (or a line if all 3 CV are colinear AD line is parallel to the linear bezier).


for a quick estimation, cubic beziers are constrained to a triangular bounding volume (or line if the CV are colinear), this allows you to skip solving a big cubic function for many cases.

Tags:

Bezier Curve