[Math] Find Quadratic Bezier curve equation based on its control points

algebraic-geometrybezier-curvequadratics

If the 3 control points of the quadratic Bézier curve are known, how do you calculate algebraically the equation of that curve (which is an y=f(x) function)?
Let's say I have..

  • P0 (x,y) – startPoint
  • P1 (x,y) – controlPoint
  • P2 (x,y) – endPoint

and I want to get implicit equation for that, something like that:

f(x) = −0.5x^2​​ + 3.5x − 1 (for example).

I've found the fang's solution here, but he says

Although all quadric Bezier curve is part of a certain parabola, not all parabola can be represented as $f(x)=ax^2+bx+c$. So, the first thing you need to do is check if $x_2=\frac{x_1+x_3}{2}$. If this check fails, then your quadratic Bezier curve is not a segment of $f(x)=ax^2+bx+c$.

Ok, but if check fails how can I find its equation?

Another article about cubic Bezier is http://www.moshplant.com/direct-or/bezier/math.html Is there any approach for quadratic?

Best Answer

The equation of the curve is $$ \mathbf{C}(t) = (1-t)^2 \mathbf{P}_0 + 2t(1-t)\mathbf{P}_1 + t^2\mathbf{P}_2 $$ If we let $\mathbf{P}_0 = (x_0,y_0)$, $\mathbf{P}_1 = (x_1,y_1)$, $\mathbf{P}_2 = (x_2,y_2)$, then we can write two separate equations for $x$ and $y$: $$ x(t) = (1-t)^2 x_0 + 2t(1-t)x_1 + t^2 x_2 $$ $$ y(t) = (1-t)^2 y_0 + 2t(1-t)y_1 + t^2 y_2 $$

You can rearrange and collect powers of $t$, if you want to: $$ x(t) = (x_0 - 2x_1 + x_2)t^2 + 2(x_1 - x_0)t + x_0 $$ $$ y(t) = (y_0 - 2y_1 + y_2)t^2 + 2(y_1 - y_0)t + y_0 $$ As you mentioned, it is not always possible to write the curve in the form $y=f(x)$. For example, the curve $$ x(t) = (t - \tfrac12)^2 \quad ; \quad y(t) = t - \tfrac12 $$ has equation $x = y^2$. We could write $y = \sqrt x$, but this is only half of the curve (the other half is $y = -\sqrt x$).

However, you can always write a quadratic Bezier curve in the form $g(x,y)=0$, where $g$ is some second-degree function of $x$ and $y$.