| New Reply |
Cubic Spline Interpolation Tutorial |
Share Thread | Thread Tools |
| Jul31-07, 10:14 PM | #1 |
|
Recognitions:
|
Cubic Spline Interpolation Tutorial
Attached below are two cubic spline tutorials:
1. Explanation of the classic tri-diagonal cubic spline formulation. Included are 2 example problems. 2. Extension to parametric cubic splines. Included are 2 example problems .
|
| Oct19-07, 01:51 AM | #2 |
|
|
wow,
After a very long search in google i found this tutorial. And it was the first one, which describes parametric cubic splines in a good way. Thank you very much :-) Now i can lay streets through my landscape :-) |
| Oct31-07, 09:29 PM | #3 |
|
|
Sigh....Thank You!
I was missing something very stupid and now I know what it is! |
| Jan15-08, 10:20 AM | #4 |
|
|
Cubic Spline Interpolation Tutorial
Thank you for tutorials. This has helped me very mush.
|
| Mar2-08, 01:21 AM | #5 |
|
|
Hey there -
Thanks for the great tutorials - they really helped me! I'm trying to duplicate your results for cubic interpolation of a circle with 4 points and I got the same solution for the 2nd derivatives in the x and y directions. However, when I solve for the coefficients and plot the cubic polynomials I can't seem to get the same result as you - Heres the code that calculates the coefficients (in MATLAB) mx - x'' my - y'' Sx - x coefficients Sy - y coefficients s - arc length [0 0.25 0.5 0.75 1] for i = 1:n-1 Sx(i,1) = (mx(i+1) - mx(i))/6*h; Sx(i,2) = mx(i)/2; Sx(i,3) = (x(i+1) - x(i))/h - h*(mx(i+1) + 2*mx(i))/6; Sx(i,4) = x(i); Sy(i,1) = (my(i+1) - my(i))/6*h; Sy(i,2) = my(i)/2; Sy(i,3) = (y(i+1) - y(i))/h - h*(my(i+1) + 2*my(i))/6; Sy(i,4) = y(i); end %Plotting the function ds = 0.01; m=1; i=1; for i = 1:n-1 for k = s(i):ds:s(i+1) genpnx(m) = Sx(i,1)*(k - s(i))^3 + Sx(i,2)*(k-s(i))^2 + Sx(i,3)*(k-s(i)) + Sx(i,4); genpny(m) = Sy(i,1)*(k - s(i))^3 + Sy(i,2)*(k-s(i))^2 + Sy(i,3)*(k-s(i)) + Sy(i,4); m = m+1; end i end plot(genpnx,genpny,'r') Do you have any idea what I might be doing wrong? (Ive attached an image of what the spline looks like for 4 points) Thanks! |
| Mar3-08, 02:22 PM | #6 |
|
Recognitions:
|
Though I'm not a MATLAB person, your expressions for calculating the coefficients look correct. Make sure you are using 0.25 for h. Also, for plotting, t should vary from 0 to 0.25 for each segment.
Here are the coefficient values I got for the 1st segment: ax = 32 bx = -24 cx = 0 dx = 1 ay = -32 by = 0 cy = 6 dy = 0 Actually, this isn't the best way to fit a circle with cubic polynomials. It is better to fit a quarter circle with a single parametric cubic. The tutorial has been updated - check it out. |
| Mar3-08, 06:08 PM | #7 |
|
|
Thanks for the coefficients - they helped me figure out what the problem was - a syntax problem - the correct expression for the coefficients are
Sx(i,1) = (mx(i+1) - mx(i))/(6*h) while I had Sx(i,1) = (mx(i+1) - mx(i))/6*h Thanks a ton! |
| Mar3-08, 06:35 PM | #8 |
|
Recognitions:
|
Glad to help. Fyi, the problem can be made even simpler by making h = 1, meaning s = [0 1 2 3 4]. Second deriveratives are x" = [-3 0 3 -3], y" = [0 -3 0 3 0] and plotting can be done for t varying from 0 to 1 for each segment.
I encourage you to review the updated tutorial on circle fitting. |
| Mar12-08, 01:10 PM | #9 |
|
Recognitions:
|
Attached is an update to the Cubic Spline Tutorial.
To Staff, Would someone be willing to replace the 1st attachment in this thread with the below? Thanks. |
| Nov22-08, 02:08 AM | #10 |
|
|
thanks a lot buddy.
|
| Dec17-08, 11:29 AM | #11 |
|
|
Hi hotvette,
I have been looking for a good tutorial on Cubic Splines, nice work. I have found what I think might be an error in one of your examples, however. Example Problem #1 shows c2 = 0, but when I plug in the values: y3 = 1 y2 = 0.125 h2 = .5 y3" = 0 y2" = 4.5 I come up with c2 = 1, not 0. Plugging 0.5 into the second polynomial with c2 = 1, I get y2 = 1, thus resulting in a discontinuity with the first polynomial. I'm too lazy to try to work out the root of the problem, but I figured I'd flag the discrepancy. Cheers |
| Dec17-08, 06:35 PM | #12 |
|
Recognitions:
|
Agree that C2 = 1.0 (typo), but I think the evaluation of the 2nd poly is OK:
[tex]y = a2(x - x_2)^3 + b2(x - x_2)^2 + c2(x - x_2) + d2[/tex] Update with typo fixed is attached. |
| Dec17-08, 06:38 PM | #13 |
|
|
Yep, my mistake. I used ax^3 + bx^2 + cx + d rather than using (x-x0), etc.
Thanks again for the excellent tutorial. |
| Dec29-08, 09:54 PM | #14 |
|
|
For the cubic spline interpolation if we have
A=(x2-x)/h; B=(x-x1/h); C=1/6*(A^3-A)*h^2; D=1/6*(B^3-B)*h^2; y=A y1 + B y2 + C y1'' + D y2'' What is the interpolation error of above? For example for Hermitian cubic spline it is smaller than 5/384 ||f^{(4)}|| h^4 |
| Apr8-09, 01:51 PM | #15 |
|
|
Thanks very much my friend! The tutorial for the parametric C Splines was very helpful to me!
You see, every book I ve read doesn t say how we can relate the derivatives of the actual curve to the derivatives of the parametric equations of x & y. Ok, its easy to proof with the chain rule but what about the values of these derivatives on bounds!! Simply, x'(t)/y'(t) must be constant on bounds, so give x'(t),y'(t) any value you want to keep this ratio constant! HAHAHAH, i feel stupid... Very helpful! Thanks again! |
| Oct16-09, 04:19 AM | #16 |
|
|
Thanks! Just what i was looking for! :)
|
| Nov15-09, 01:31 PM | #17 |
|
|
Any reading suggestion to smooth out a curve using spline or similar approach.
|
| New Reply |
| Thread Tools | |
Similar Threads for: Cubic Spline Interpolation Tutorial
|
||||
| Thread | Forum | Replies | ||
| Spline degree?? | General Math | 2 | ||
| Deriving Greens Theorem for 3D Thin Plate Spline | Calculus | 0 | ||
| Spline in N dimensions | General Math | 1 | ||
| Interpolation | Calculus & Beyond Homework | 1 | ||
| Shortest distance from point to Catmull-Rom spline | General Math | 2 | ||