# Finding Y given X on a Cubic 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)^3 * X0 + 3*(1-t)^2 * t * X1 + 3*(1-t) * t^2 * X2 + t^3 * X3

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

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

then rearrange to the Cubic equation style:

800t^3 + 3*(1-t)800t^2 + 3(1-t)^2*600t + (1-t)^3*100 -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?"

-
Since a general cubic equation is not particularly nice to solve algebraically anyway, a more practical approach to the entire problem would be to use something like bisection (halving of intervals) to find the $t$ that produces an $x$-coordinate "close enough" to what you're shooting for. – Henning Makholm Jul 3 '12 at 1:08

## 1 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.

-
Oh! Okay, so it's just me being terrible at Maths, ha. I didn't try to expand further because I didn't think it was possible (well, unless I wanted to make it more complicated). Thank you! I shall attempt to brush up on my Maths skills. – CyrusFiredawn Jul 3 '12 at 0:37