summaryrefslogtreecommitdiffstats
path: root/doc/bezier-utils-work.txt
blob: 8604c1207c24a0544ebd4692ea1013568cf78bdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)