[Math] Finding Y given X on a Cubic Bezier Curve

bezier-curve

I just asked this in the Computing sections but they sent me here:

"So I've been looking around for some sort of method to allow me to find the Y-coordinate on a Cubic Bezier Curve, given an x-coordinate on it.

I've come across lots of places telling me to treat it a cubic function then attempt to find the roots, which I understand HOWEVER the equation for a Cubic Bezier curve is (for x-coords):

$$X(t) = (1-t)^3X_0 + 3(1-t)^2tX_1 + 3(1-t)t^2X_2 + t^3X_3$$

What confuses me is the addition of the $(1-t)$ values. For instance, if I fill in the $X_i$ values with some random numbers:

$$400 = (1-t)^3*100 + 3(1-t)^2t*600 + 3(1-t)t^2 * 800 + t^3 * 800$$

then rearrange to a cubic equation:

$$800t^3 + 3(1-t)800t^2 + 3(1-t)^2600t + (1-t)^3100 – 400 = 0$$

I still have the trouble of the $(1-t)$ blocks. I can't work out how I am supposed to solve $t$ when the $(1-t)$ is unknown in the first place.

Any ideas?

Best Answer

Expand fully. ${}{}{}{}{}{}{}{}{}$

In your example, the coefficient of $t^3$ turns out to be $100$.

In the general case $$X_0(1-t)^3 + 3X_1(1-t)^2 t + 3X_2(1-t) t^2 + X_3t^3,$$ the coefficient of $t^3$ will turn out to be $-X_0+3X_1-3X_2+X_3$. The constant term is $X_0$. The coefficient of $t^2$ is $3X_0-6X_1+3X_2$, and the coefficient of $t$ is $-3X_0+3X_1$.

For the expansion, all you need is $(1-t)^3=1-3t+3t^2-t^3$ and $(1-t)^2=1-2t+t^2$.

If (as is likely) you will be using a numerical method to solve the cubic, it is not even necessary to expand, since the numerical method will take care of things.

Related Question