how to draw piecewise hermite curve.

Answers (2)

Here's how to draw one "piece". Let (x1,y1) and (x2,y2) be the coordinates of the two end points and m1 and m2 the respective desired derivatives at these two points.
A = [x1^3,x2^3,3*x1^2,3*x2^2;x1^2,x2^2,2*x1,2*x2;x1,x2,1,1;1,1,0,0];
C = [y1,y2,m1,m2]/A; % Solve for the four cubic Hermite coefficients
n = 1000;
X = linspace(x1,x2,n);
Y = C*[X.^3;X.^2;X;ones(1,n)];
plot(X,Y,'y-') % Plot the cubic between the two given points
I'll leave it to you to figure out how to put together many adjacent pieces.
As Roger showed, you can do it wit some modest effort (not really that hard.) Or you can use a tool that does it for you. Download my SLM toolbox from the file exchange.
For example, to create the cubic hermite segment that at...
x = 0, y = 0, y' = 1
x = 10, y = 5, y' = 2
Do this:
slm.form = 'slm';
slm.degree = 3;
slm.knots = [0;10];
slm.coef = [0 1;5 2];
plotslm(slm)
If you have more segments, just add extra knots, then add extra rows to the coef array.

2 Comments

how can i know the parametric equation for this slm hermite curve?
F = slmpar(slm,'symabs')
F =
2×1 cell array
{1×2 double}
{1×1 sym }
>> F{1,1}
ans =
0 10
>> F{2,1}
ans =
0.02*x^3 - 0.25*x^2 + x
So, on the interval [0,10], the function was as given. With a more complicated spline, there would be multiple intervals, and thuis different polynomial segments.

Sign in to comment.

Categories

Tags

No tags entered yet.

Asked:

on 23 Aug 2014

Edited:

on 10 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!