Mapping Digitised Points to a Trial Quadratic Bezier Curve
While the quadratic Bezier curve equation is quite simple, it evaded me how to convert a digitised point to the Bezier curve parameter "t".
Upon research I came upon a paper by Nouri A. Suleiman (2013), "Least Squares Data Fitting with Quadratic Bezier Curves".
Although I did not follow the Least Squares route, the paper presents a method for mapping a digitised point (i.e. finding the t parameter) to a trial quadratic bezier curve.
For each digitised point Xi[i] and Yi[i], and the trial Bezier curve:
A*(1-t)^2+2*B*(1-t)*t+C*t*t
Calculate the following (Suleiman) values:
d0=(Ax-Xi[i])*(Ax-Xi[i])+(Ay-Yi[i])*(Ay-Yi[i]);
d1=(*Bx-Ax)*(Ax-Xi[i])+(*By-Ay)*(Ay-Yi[i]);
d2=(Ax-2*(*Bx)+Cx)*(Ax-Xi[i])+2*(*Bx-Ax)*(*Bx-Ax)+(Ay-2*(*By)+Cy)*(Ay-Yi[i])
+2*(*By-Ay)*(*By-Ay);
d3=(Ax-2*(*Bx)+Cx)*(*Bx-Ax)+(Ay-2*(*By)+Cy)*(*By-Ay);
d4=Ax*(Ax-2*(*Bx)+Cx)-2*(*Bx)*(Ax-2*(*Bx)+Cx)+Cx*(Ax-2*(*Bx)+Cx)
+Ay*(Ay-2*(*By)+Cy)-2*(*By)*(Ay-2*(*By)+Cy)+Cy*(Ay-2*(*By)+Cy);
Then calculate the (Suleiman) parameter mapping error:
e2=d4*t*t*t*t+4*d3*t*t*t+2*d2*t*t+4*d1*t+d0;
Then solve the minimisation problem of e2 for t. We can use the Newton-Raphson method:
t=t-e2'/e2"
Where:
e2'=4*(d4*t*t*t+3*d3*t*t+d2*t+d1);
e2"=4*(3*d4*t*t+6*d3*t+d2);
After finding the trial Bezier curve parameter t for each digitized point, we need to solve the minimisation problem of e2 for Bx of the control point (i.e calculate the first and second derivatives for the sum of e2):
Sum[e2]=Sum[(Ax*s*s+2*Bx*s*t+Cx*t*t-Xi[i])^2], for each i
Sum[e2']=Sum[4*s*t*(Ax*s*s+2*Bx*s*t+Cx*t*t-Xi[i])], for each i
=Sum[4*(Ax*s*s*s*s+2*Bx*s*s*t*t+Cx*s*t*t*t-Xi[i]*s*t)], for each i
Sum[e2"]=Sum[8*s*s*t*t], for each i
Then apply Newton-Raphson:
Bx=Bx-e2'/e2''
Repeat for By.
In the files directory is some C code implimenting the psudo code above.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.