Online Example::Cubic Bezier, Y at X

This example illustates the Bezier3::yAtX() method. In the general case (barring nearly or exactly vertical Beziers), there may be no, one, two, or three y-values for a given x-coordinate. The yAtX() method returns an array of Objects, each containing the t-parameter and y-value at that t-parameter corresponding to an input x-value in the range of the quadratic Bezier curve. The combination of t-parameter value and y-coordinate allow the caller to determine which of two possible y-coordinates may be 'better' in a specific application.

If the input x-coordinate is outside the range of x-values covered by the Bezier curve covered by t in [0,1], then the returned array contains no values.

The method of approach is to treat the problem as one of finding the roots of the cubic polynomical Bx(t)-x0 = 0, where Bx(t) is the equation for the x-coordinates of the Bezier curve and x0 is the x-coordinate at which the y-coordinates are desired. An initial root is found via a combination of Bisection and Jack Creshaw's TWBRF. Back in the college when I was programming in Fortran, I used Halley's method for this problem.

Once any root is found, say r, then (t-r) is a factor of the original cubic polynomial and it can be divided out using synthetic division, leaving a quadratic polynomial. Finding any remaining roots of the quad. is trivial. Given all roots, evaluate the y-values, By(t) at those roots.

In the future, I may add a Bezier Clipping demo to show an alternate and more general solution to Bezier-line intersection.

This example requires the Flash™ 9 player.

You need to upgrade your Flash Player

This example requires the Flash™ 9 player.

Click in the drawing area to define the four control points. The cubic Bezier is automatically drawn. Click the 'Select x' button and then click anywhere in the drawing area to define an x-coordinate. Markers are placed at appropriate y-coordinates on the Bezier curve at the specified x (if they exist). Click the 'Reset' button to draw a new curve.

For further reading,

:: Cubic Bezier Curves - Cubic Bezier's and introduction to quadratic approximation. (to answer the above question)

Source Code. Download the Singularity package (this example is in Singularity/demos/CubicYatX.mxml).