Can the $~t~$ of a quadratic Bezier curve be found given a $~x~$ or $~y~$ (using the quadratic formula)?

477 Views Asked by At

Given an $y$-coordinate and the three control points of a quadratic Bezier curve, can you calculate $~t~$ in the following way ?:

$ y_{p0} - y + 2(y_{p1} - y_{p0})t + (y_{p0} - 2y_{p1} + y_{p2})t^2 = 0 $

$a = (y_{p0} - 2y_{p1} + y_{p2})$

$b = 2(y_{p1} - y_{p0})$

$c = y_{p0} - y$

Use quadratic formula to find $t$

(I believe it should, but I'm trying to use this method to rasterize $2$D Bezier-triangles and I'm failing and can't find why. I'm mostly asking if it's possible in theory or not, because if there is something wrong in the implementation I should be the first person to find it as I'm most familiar with my code, while I would not be able to find my mistake if the math behind my algorithm is flawed in the first place.)

Thank you for your answer.

1

There are 1 best solutions below

2
On BEST ANSWER

It is possible to find $t$ for a given $x$ or $y$ value in a quadratic bezier curve.

The quadratic bezier formula $$ y = y_1 + (1-t)^2(y_0-y_1) + t^2(y_2-y_1) $$ can be magically rearranged to $$ t = \frac{(y_{0} - y_{1}) \pm \sqrt{y y_{0} - 2 y y_{1} + y y_{2} - y_{0} y_{2} + y_{1}^{2}}}{y_{0} - 2 y_{1} + y_{2}} $$

This looks very similar to your solution when your $a, b, c$ values are substituted in the quadratic formula.

Here are the key aspects for traversal:

  • Boundary values for the loop should be selected carefully. If traversing by $y$, values should range from lowest and highest of the three control points.
  • In $t$ formula, square root part becomes imaginary when curve does not touch or go through the given $y$. (Beyond the curvature towards second node point when it is higher or lower than other node points, for instance).
  • There's a $\pm$ in the formula, so it yields two $t$ values for your set of control points and for every $y$ value. Either of the points may or may not fall on the curve segment. You should validate the results by checking range ($ 0 \leq t \leq 1 $) or by substituting in the first formula.
  • Finally, this method is unusable when the divisor becomes zero for the given set of control points. In such cases, traverse on other dimension ($x$) or switch to a root-finding method such as Newton's method.