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.
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.
6 thoughts on “Degrafa BezierUtils Class”
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?
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.
That’s the code, not the complete derivation of the algorithm.
Yeah, that’s what I want, the actual derivation of the algorithm. I can read the code in Actionscript:) thanks!
Comments are closed.