An addendum to the last email, here's the actual derivation that
led to the C code I just posted:
Spline math:
Initial Equations:
y1 = a*x1^3 + b*x1^2 + c*x1 + d
y2 = a*x2^3 + b*x2^2 + c*x2 + d
k1 = 3*a*x1^2 + 2*b*x1 + c
k2 = 3*a*x2^2 + 2*b*x2 + c
These two equations basically basically express the constraints
as I read them in the 5.10.9 Spline section, and so are probably
the ones relevent to the questions you brought up. The rest of
the math below shows how to get from these constraints to the C-code
math I just posted:
Subtract y2 from y1:
(y1 - y2) = a*(x1^3 - x2^3) + b*(x1^2 - x2^2) + c*(x1 - x2)
Let Q = 1/(x1 - x2)
Q*(y1 - y2) = a*Q*(x1^3 - x2^3) + b*Q*(x1^2 - x2^2) + c
Subtract from k1 and k2 equations:
Q*(y1 - y2) - k1 = a*(Q*(x1^3 - x2^3) - 3*x1^2) + b*(Q*(x1^2 - x2^2) - 2*x1)
Q*(y1 - y2) - k2 = a*(Q*(x1^3 - x2^3) - 3*x2^2) + b*(Q*(x1^2 - x2^2) - 2*x2)
R = 1/(Q*(x1^2 - x2^2) - 2*x1)
S = 1/(Q*(x1^2 - x2^2) - 2*x2)
R*(Q*(y1 - y2) - k1) = a*R*(Q*(x1^3 - x2^3) - 3*x1^2) + b
S*(Q*(y1 - y2) - k2) = a*S*(Q*(x1^3 - x2^3) - 3*x2^2) + b
a = (Q*(y1 - y2)*(R - S) - R*k1 + S*k2)/
(Q*(x1^3 - x2^3)*(R - S) - 3*(R*x1^2 - S*x2^2))
k1 = 3*a*x1^2 + 2*b*x1 + c
k2 = 3*a*x2^2 + 2*b*x2 + c
b = Q*(k1 - k2)/2 - (3/2)*a*Q*(x1^2 - x2^2)
c = k1 - 3*a*x1^2 - 2*b*x1
d = y2 - a*x2^3 - b*x2^2 - c*x2
To prove to yourself that it works, try using these test points:
test: x1 = 1
y1 = 1
x2 = 2
y2 = 10
k1 = 5
k2 = 4
compute Q,R,S,a,b,c,d manually, and plot the result.
Again a caveat, I'm copying this from notes I wrote over a year
ago now, and there may very well be an error in the math above
that either was (or was not!) corrected in the code.
-------------------------------------------------------------------------
John Lazzaro -- Research Specialist -- CS Division -- EECS -- UC Berkeley
lazzaro [at] cs [dot] berkeley [dot] edu www.cs.berkeley.edu/~lazzaro
-------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Mon Jan 28 2002 - 12:03:59 EST