Finding the intersection of two lines is a fairly straightforward algorithm. You find their slopes, factor the equation, simple. But finding the intersection between two quadratic bezier curves doesn’t seem to have a simple equation. From the sources I’ve read (I’ll try and find them again so I can cite and quote them) curve-to-curve intersection can only be solved as an approximation.
There are a lot of cool things you can do once you have both line and curve intersections figured out. For example you can combine two shapes wherever they overlap. You can also do some less obvious things such as path offsets (equivalent to Flash authoring’s Modify > Shapes > Expand Fill)
There are several methods for this intersection approximation, but all of them reduce the curve into smaller (and flatter) curve segments, eventually performing a line-to-line intersection in place of the reduced curve segment. My first approach seems to be one of the faster methods for ActionScript, but maybe not.
Click and drag the handles in this demonstration:
The approach does a simple hit test between the bounding rectangle of each curve. This is a programmatic hit test, evaluating the control points of the curves in memory and doesn’t rely on Flash’s display list at all (which would be entirely too slow and unnecessary). If the curves’ bounding rects touch, then each is subdivided in half, tested against all the other subdivisions of the other curve, and subdivided and tested again where the hit tests succeed. You get the idea when moving the curves around in my test.
The source is available via right-click > view source, though I apologize I have no documentation whatsoever. I didn’t intend on blogging about this subject any time soon, but reading up on Jim Armstrong’s blog inspired me to start sharing and see if I can’t get any feedback. The approach is primarily where I want to hear any comments, positive or negative, and then I can clean up code for use later on.