-
Notifications
You must be signed in to change notification settings - Fork 22
Description
I'm doing deep research into robust path operations. That may well end up being three blog posts:
- Robust path operations on polylines (Draft of path ops blog #78 is draft)
- Cubic/cubic Bézier intersection
- Putting it all together
These blog posts should be rich in figures. In addition, I am tempted to make interactive diagrams where the control points of the Béziers can be moved, and code updates the various bounds and so on.
Perhaps the order of the last two should be reversed. A key concept is: what should the output of curve/curve intersection look like, to be usable in a path ops context? I propose:
- The two input curves are y-monotonic and have endpoints match in y coordinate (y0..y1)
- thus, curves can be represented as
$x = f(y)$ and$x = g(y)$ ,$y_0 \leq y \leq y1$
- thus, curves can be represented as
- Output is a sequence of segments that cover the y0..y1 range
- Segment is left-order, ambiguous, or right-order
- Ambiguous also contains an optional crossing point, only valid for intersections of odd multiplicity
- Order means g(y) - f(y) > epsilon (or g(y) - f(y) < -epsilon)
- Ambiguous means Fréchet distance < epsilon
- May require some refinement when slope is really high (Fréchet distance at endpoints may be overestimate)
- Also note these two epsilons are not the same, this one should be higher
How ambiguous sections are handled depends on the path op. For intersection or union, when two curves are near the path op selects one of the curves. Cut over at the crossing point (or don't cut if there's no crossing point). For difference, both curve segments are in the output; merge them (summing winding numbers), possibly adding horizontal segments of length ~ epsilon at boundaries of region.
Remainder of this outline sketches the algorithm for cubic/cubic intersection. It should be much better than the standard "fat line" Bézier clipping algorithm.
Outer loop is subdivision, but works in 1 dimension (y). (Note: not obvious for pedagogical reasons whether to do
For both cubics, compute an estimated parabola of the form
Given cubic and parabola estimate, compute bounds so
Claim: cubic scaling. As
Given two estimated parabolas (a, b, c, d_min, d_max), easy to represent upper and lower bounds of difference:
Happy case: these ranges are significantly smaller than original y0..y1 range. Keep iterating. Convergence should be cubic.
Also happy case: bounds may prove regions where
Less happy case: subdivide, for example at y = 0.5(y0+y1). Given cubic scaling, expect errors to be 1/8.
Big question: when does subdivision stop? Should be
Fréchet bound techniques
This section is a bit more speculative. It should be applied when bounds on parabolas do not significantly reduce range.
First, skew f(y) and g(y) linearly
Compute upper bound on Fréchet distance between (skewed) f and g = d. Also compute max slope dx/dy of f and g (straightforward to get upper bound using interval techniques) = m. Claim: max
How to compute upper bound on Fréchet distance? Hypothesis: sample both cubics along 6 points equally spaced by arc length. For some
References
- Curve intersection using Bézier clipping, Sederberg and Nishita 1990
- Intersection algorithms based on geometric intervals, North 2007, Masters thesis
- Comparison of Distance Measures for Planar Curves, Alt et al, 2004
- Bézier clipping is quadratically convergent, Schultz 2007