Degrafa Advanced Quadratic Bezier

If you update your code base from SVN (Origin branch), you should see a new class, com.degrafa.geometry.AdvancedQuadraticBezier.  In keeping with the Degrafa ‘pay as you go’ philsophy, this class extends the existing QuadraticBezier to include some new functionality.  Quadratic Bezier is intended primarily for drawing quad. Beziers.  It is lightweight and well suited for its task.  AdvancedQuadraticBezier (and AdvancedCubicBezier to be added in the future) are repositories for functionality that is useful for more advanced applications such as games.

The initial set of new methods includes automatic 3-point interpolation with chord-length parameterization.  The 3-point interpolation normally used in the Flash community is really a midpoint formula that is a special case of the general formula.  The general formula is discussed in this TechNote and illustrated in this online demo.  The functionality prevously available in the Singularity Bezier2 class is now available to Degrafa users.

The computation of t-parameter at extreme points has also been ported.  So, you can query the parameter value in [0,1] where the x- or y-coordinate is a maximum or minimum.  I’ve used this before in applications where a quad. Bezier represents a trajectory for animating a sprite.  The start and end points are variable.  Finding the extreme y-coordinate (quickly) is necessary to ensure the trajectory does not cause the sprite to pass into invalid areas in the display space.

The y-at-x method is also available, but not yet tested.  That one is pretty much look but don’t touch at this point 🙂  I hope to have a test program written over the weekend.

The screenshot below illustrates sample output from the advanced quad. Bezier demo.  Prior demos used the draggable points to set control points for a quad. Bezier.  This demo uses them to set interpolation points.  Notice how the Bezier passes through all three points.  The red lines illustrate the results from the bounding methods, which is also a way to quickly compute a bounding rectangle for the Bezier curve, including the t-parameters at which the bounds occur.

Degrafa Advanced Quadratic Bezier
Degrafa Advanced Quadratic Bezier

I will continue to add new methods to this class as needed and hope to follow on with an advanced cubic Bezier class in the near future.  The Singularity BezierUtils class will eventually be ported as well (providing the ability to query the closest point on a quad. or cubic Bezier to an arbitrary point).

View Demo

View Source

Advertisement

2 thoughts on “Degrafa Advanced Quadratic Bezier

  1. JT – I think you’ve had calculus. Compute dy/dt and dx/dt (which is pretty simple given the quadratic polynomial coefficients). Set these equal to zero and compare the stationary points with coordinates of each endpoint.

    regards,

    – jim

Comments are closed.