Curve fitting algorithm – P.J. Schneider

  • Step 1: Given points={(x1,y1),(x2,y2),,(xn,yn)}, generate a Bezier C with parameters t1^,t2^,ε respectively the left tangent, right tangent, and the allowable deviation.

  • Step 2: Compute error is the sum of errors of the curve C when fitting with the points

    • If error<εC is found, algorithm stops.

    • Otherwise, split the points at M(xM,yM) which is the furthest point to C, then recursively generate C1,C2 that fit to 2 new set of points: [(x1,y1)(xM,yM)] and [(xM,yM)(xn,yn)].

  1. For ease of calculation, we use the curve calculation formula with parameter tQ(t)=i=0nViBin(t),t[0,1]

  2. For 3rd degree Bezier curves with control points P1,P2,P3,P4 then the tangent to the curve at the endpoints P1 and P2 lies on the line containing the segment P1P2 and the line contains the segment P3P4. This is shown through the formula:

dQdt=Q(t)=ni=0n1(Vi+1Vi)Bin1(t)

Then, we can compute P2=α1t1^+P1 and P3=α2t2^+P4 with t1^,t2^respectively are tangent vectors at P1 and P4

  1. So fitting a curve with a set of points is essentially finding the appropriate value of α1,α2. 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.

  2. The remaining thing is to calculate the distance from a point P to the curve C, with parametric equation Q(t):

I borrowed the drawing from the paper. In order to calculate the distance from P to Q(t) which means we need to calculate dist=||PQ(t)||. Thus, curve fitting means we need to minimize the distance of all points in the set points to Q(t)i=1n||PiQ(ti)||, with ti is the value of the accordant parrameter of Pi. To simplify, we find the minimum of the sum of squared distances of all points in the set points to the curve CS=i=1n[PiQ(ti)]2

  1. In order to calculate ti, wwe approximate it by calculate the rate off its length over the sum of lengths of all segments. Then we try to update ti by solving the equation[Q(ti)Pi](Q(ti))=0 using Newton-Ralphson method with titif(t)f(t).

Subscribe to SkyGLab

Scroll to Top