Closest Point on Bezier Code
The first pass at porting the classic Graphic Gem algorithm for closest point on a Bezier is complete and it works for both quadratic and cubic Beziers (the original Gem C code was hardcoded for cubics). This algorithm has important pedagogical significance beyond just being included in the Gems series. The embedded Bezier root finder illustrates practical application of geometric properties of Bezier curves, so I expect this to be a useful teaching tool.
The code is not a straight port; method names and function signatures were changed to meet longer-term goals. The code will be optimized in a subsequent release of the BezierUtils class. During the process, I noticed a typo in the Graphic Gems book describing the algorithm, so I expect a TechNote is in order. This will serve as a segway into discussions on dealing with cusps, alternate optima, and a comparison of root finders in Bezier vs. Power form (as well as a discussion on Lane’s algorithm). Alternate approaches to the problem as well as an extension to Bezier splines are on the table for future development.
There are two online demos, one for quadratic curves and the other for cubics. The updated Singularity package may be downloaded from links on either page. MXML files for the demos are provided in the download.