[Math] Cubic Bezier curve and a straight line intersection

bezier-curve

Suppose that two ends of a cubic Bezier curve is connected by a straight line. Is there a simple way to find out whether this straight line intersects the Bezier curve (apart from the endpoints)? If it intersects then what will be the corresponding Bezier curve parameter's value?

Best Answer

Given 2D cubic Bezier segment $\mathcal{B}(t,A,B,C,D)=A\,(1-t)^3+3B\,(1-t)^2t+3C\,(1-t)t^2+D\,t^3$, $t\in[0,1]$ and line segment $\mathcal{L}(t,A,D)=A\,(1-s)+D\,s$, $s\in[0,1]$, the value of $t:\mathcal{B}(t,A,B,C,D)=\mathcal{L}(s,A,D),\ t\ne0, t\ne1$ is the same as the value of $t:\mathcal{B}(t,0,B-A,C-A,D-A)=\mathcal{L}(s,0,D-A)$. So, with a substitution $b=B-A,\ c=C-A,\ d=D-A$ we can solve a system of two equations with two unknowns $t,s$:

\begin{align} \mathcal{B}(t,0,b_x,c_x,d_x) &= \mathcal{L}(s,0,d_x) \\ \mathcal{B}(t,0,b_y,c_y,d_y) &= \mathcal{L}(s,0,d_y) \end{align}

which gives the value of parameter $t$ as

\begin{align} t &= \frac{b_x\,d_y-d_x\,b_y}{b_x\,d_y-c_x\,d_y-d_x\,b_y+d_x\,c_y} \end{align}

If $0<t<1$ than the intersection point of $\mathcal{B}$ and $\mathcal{L}$ is $X=\mathcal{B}(t,A,B,C,D)$.

enter image description here