BezierInfo-2
BezierInfo-2 copied to clipboard
Algorithm for projecting a point can be confused by loops.
I implemented the point projection algorithm and in my tests found that it can be confused by curves with loops as shown in the attached movie. It happens because the initial look-up table is too coarse in just the right place to make the initial guess incorrect. In my app, I fixed it by making the look-up table longer, but that's really just a kludge. I don't know that there's a concrete fix for this. But you might want to mention it in the projections chapter.
https://user-images.githubusercontent.com/523551/106835035-6a7ba300-664b-11eb-94a9-dd6210b1d859.mov
Good point, at the very least explaining that this approach is limited by LUT fidelity is worth doing.
Can I suggest this can be solved by implementing an alternative method to find the intersection points.
When projecting a point, A, onto the Bezier curve, the closest intersection point on the curve will form a perpendicular vector between the curve and point A. Assume this vector intersects the Bezier curve at a position, t*. One can create a vector from A to B(t*) and can also calculate the tangent of the Bezier curve at t*, B'(t*). The dot product of the projection vector and the tangent vector will be zero when they are perpendicular. This can be solved to find the relevant values of t*. Note, solving this typically ends up as a polynomial with an order given by 2d-1, where d is the degree of the Bezier curve. Root finding algorithms can be used to find the solutions for t* in the range of [0,1]. There may be multiple values of t*, so finding the length of the projection vector for each intersection point can enable the closest intersection point to be determined.
A nice feature is that this method is not dependant on the LUT fidelity, but you can end up with a high order polynomial to solve!
Thanks:)