bezier-utils-work.txt revision 208e5a33acc4a8ad9d8c0488f047c260346f1258
min .5 * sum_i lensq(bez_pt(b, u[i]) - d[i])
lensq(d)=dot(d, d) = d.x * d.x + d.y * d.y
sum_i (f(i) + g(i)) = sum_i f(i) + sum_i g(i), so
we can separate into x,y parts. Since they are the same, we write `z' in the below
to mean either x or y.
.5 * sum_i (bez_pt(b, u[i]) - d[i]).z^2
= .5 * sum_i (B0(u[i]) * b[0] +
B1(u[i]) * b[1] +
B2(u[i]) * b[2] +
B3(u[i]) * b[3]
- d[i] ).z^2
= H.
Suppose that b[0,1,3] are fixed (with b[1] perhaps being calculated
from a prior call to existing generate_bezier).
d H / d b[2].z = sum_i B2(u[i]) * (bez_pt(b, u[i]) - d[i]).z
Solve for dH/db[2].z==0:
-sum_i B2(u[i]) B2(u[i]) * b[2].z = sum_i B2(u[i]) * (B0(u[i]) * b[0] +
B1(u[i]) * b[1] +
B3(u[i]) * b[3]
- d[i] ).z
b[2].z = ((sum_i B2(u[i]) * (B0(u[i]) * b[0] +
B1(u[i]) * b[1] +
B3(u[i]) * b[3]
- d[i] ).z)
/ -sum_i (B2(u[i]))^2)