Home > Degrafa, Flex > Degrafa BezierUtils Class

Degrafa BezierUtils Class

January 26, 2009

There should be a new class in your friendly neighborhood SVN (Origin branch), com.degrafa.geometry.utilities.BezierUtils.  This is the repository for various utilities pertaining to Bezier curves in Degrafa.  The first utility is closest point to a Bezier (quadratic or cubic).

This is often used in games, sometimes in collision detection.  A Sprite’s centroid is used as an arbitrary point.  The outline of a simple game surface may be defined with a cubic Bezier.  The closest point on the Bezier to the specified point is computed and the bounding container of the Sprite is used to determine if the Sprite will intersect the surface in the next frame.  The t-parameter on the cubic Bezier is used to compute the curve’s tangent in the case the Sprite ‘bounces’ off the surface.  The point itself may be used as the center of an effect if the Bezier represents part of a deflector shield.

A demo is provided to illustrate usage of the closest point method for a cubic Bezier. To use the demo, drag the ‘A’, ‘B’, ‘C’, or ‘D’ interpolation points to a new location.  A small cross-hair appears.  Position the cross-hair and click.  This sets the input point and the closest point on the Bezier curve is illustrated as shown below.

closest point to a cubic Bezier curve

closest point to a cubic Bezier curve

If you wish to use the method in an application and specifically identify the point for a cubic, then it is necessary to use the AdvancedCubicBezier class due to the issue with pointAt() for cubic Beziers.

I’ll try to have another demo out for quad. Beziers later this week.

View demo.

View source.

About these ads
Categories: Degrafa, Flex
  1. JT
    January 26, 2009 at 1:37 pm

    This is cool. I noticed the reference to Graphic Gems in the code. Just checked and it’s not in our uni bookstore. Is this algorithm documented online?

  2. January 26, 2009 at 2:10 pm

    Not of which I’m aware. If you’re going to be working in or interested in this area, the Gems books are well worth purchasing and you should be able to get them used @Amazon or Barnes.

    good luck!

  3. Rothrock
    February 5, 2009 at 4:20 pm
  4. February 6, 2009 at 7:07 am

    That’s the code, not the complete derivation of the algorithm.

    regards,

    – jim

  5. JT
    February 6, 2009 at 2:47 pm

    Yeah, that’s what I want, the actual derivation of the algorithm. I can read the code in Actionscript:) thanks!

  1. February 2, 2009 at 7:31 am
Comments are closed.
Follow

Get every new post delivered to your Inbox.

Join 1,333 other followers

%d bloggers like this: