Checking if two cubic Bézier curves intersect

Intersection of Bezier curves is done by the (very cool) Asymptote vector graphics language: look for intersect() here.

Although they don’t explain the algorithm they actually use there, except to say that it’s from p. 137 of “The Metafont Book”, it appears that the key to it is two important properties of Bezier curves (which are explained elsewhere on that site though I can’t find the page right now):

  • A Bezier curve is always contained within the bounding box defined by its 4 control points
  • A Bezier curve can always be subdivided at an arbitrary t value into 2 sub-Bezier curves

With these two properties and an algorithm for intersecting polygons, you can recurse to arbitrary precision:

bezInt(B1, B2):

  1. Does bbox(B1) intersect bbox(B2)?
    • No: Return false.
    • Yes: Continue.
  2. Is area(bbox(B1)) + area(bbox(B2)) < threshold?
    • Yes: Return true.
    • No: Continue.
  3. Split B1 into B1a and B1b at t = 0.5
  4. Split B2 into B2a and B2b at t = 0.5
  5. Return bezInt(B1a, B2a) ||
    bezInt(B1a, B2b) ||
    bezInt(B1b, B2a) ||
    bezInt(B1b, B2b).

This will be fast if the curves don’t intersect — is that the usual case?

[EDIT] It looks like the algorithm for splitting a Bezier curve in two is called de Casteljau’s algorithm.

Leave a Comment