The main ideas of the algorithm
Step 1: Given , generate a Bezier with parameters respectively the left tangent, right tangent, and the allowable deviation.
Step 2: Compute is the sum of errors of the curve when fitting with the
If . is found, algorithm stops.
Otherwise, split the at which is the furthest point to , then recursively generate that fit to 2 new set of points: and .
Some important notes
For ease of calculation, we use the curve calculation formula with parameter :
For 3rd degree Bezier curves with control points then the tangent to the curve at the endpoints and lies on the line containing the segment and the line contains the segment . This is shown through the formula:
Then, we can compute and with respectively are tangent vectors at and
So fitting a curve with a set of points is essentially finding the appropriate value of . The details for calculation have been described quite thoroughly in the paper from page 618 to page 620, so I won’t write it again. The implementation of this part is in the generateBezier function, you can refer to the source code section.
The remaining thing is to calculate the distance from a point to the curve , with parametric equation :
I borrowed the drawing from the paper. In order to calculate the distance from to which means we need to calculate . Thus, curve fitting means we need to minimize the distance of all points in the set to : , with is the value of the accordant parrameter of . To simplify, we find the minimum of the sum of squared distances of all points in the set to the curve :
- In order to calculate , wwe approximate it by calculate the rate off its length over the sum of lengths of all segments. Then we try to update by solving the equation using Newton-Ralphson method with .