Search code examples
loopscurvebezier

How to prevent loops in cubic Bezier curves


I have a calculation that produces a cubic 2D Bezier curve. In this situation, the endpoints are fixed and my program calculates the internal control points. Most of the time these curves produce simple blends between two nearby shapes. But sometimes the geometry is such that drawing the curve would produce a loop, which would never look good in this application. In such situations, I am willing to modify the control points to prevent the loop. But to do this, I need to detect whether the given cubic Bezier curve will loop when drawn.

I could of course simply sample the curve at many points and look for a loop, but I'd rather find an algebraic solution based on the 8 variables (x and y values for each of the 4 points). Ideally, that solution will tell me not just if there's a loop, but how "big" the loop is in some sense. But even having a binary yes/no answer would be a big help.

Does anyone know of an algorithm that can determine if a given cubic 2D Bezier curve will produce a loop when drawn?


Solution

  • certainly: you can look at its canonical form to see whether the four points result in the curve "ending" in a region where loops must necessarily exist.

    The original theory for this is outlined in the 1989 paper "A Geometric Characterization of Parametric Cubic curves"