Degrafa BezierUtils Class
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.