I need to sort cubic bezier splines around a point by their outgoing tangent. My first attempt was to determine the outgoing tangent angle and sort by that. For a spline with four points p0, p1, p2, p3
, the outgoing tangent angle is:
p0 != p1 ? angle(p0, p1) : p0 != p2 ? angle(p0, p2) : angle(p0, p3)
This handles degenerate a cubic that is actually a quadratic or even a line. However, the point may have two outgoing splines with the same tangent angle but a different control point or end point position later on down the spline that impacts the sorting order.
Is there a nice closed-form algorithm for sorting two arbitrary bezier splines by outgoing angle that handles degenerate cases and also uses the rest of the spline to disambiguate cases when the tangents are equal? I can do it by trying t
values until I disambiguate but it seems like there could be a closed-form algorithm.