Is there a 2-D spline function to interpolate data and specify endpoint derivative information
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Clay
el 26 de Ag. de 2015
Comentada: Donald Yang
el 25 de Dic. de 2021
I have a set of [x,y] points representing starting, intermediate and final condition waypoints for a trajectory. I'd like to connect them using a spline, but I'd like to specify the initial derivative (initial heading) and preferably the endpoint derivative condition (final heading). Most searches provide solutions for 1-D spline functions with specified end conditions OR 2-D spline functions without the ability to specify the end conditions. To complicate, I want the initial derivative (heading, dy/dx) to be infiniti. Are there tools in the MATLAB toolbox that will help me interpolate these points with specified derivatives at the endpoints?
0 comentarios
Respuesta aceptada
Cam Salzberger
el 2 de Sept. de 2015
Editada: Cam Salzberger
el 3 de Sept. de 2015
Hello Clay,
I understand that you want to fit a spline to points, and also specify the slopes at the end points. You can do this with the standard spline function in MATLAB.
The standard syntax allows for fitting all of the x-y points:
% x, y - data points, xx - x-values to evaluate at, yy - y-values at those points
yy = spline(x,y,xx);
If you add values at the ends of the y input, it allows you to specify the slope at the endpoints:
yy = spline(x,[startSlope y endSlope],xx);
However, infinite values are not allowed as slope. Therefore, you have to get a little trickier and use angles as the independent variable, and both x and y values as the dependent variables. Here is a full example, with infinite slope at the start, and 0 slope at the end, along with visualization:
% Sample data (from unit circle)
x = [-1 -1/sqrt(2) 0];
y = [0 1/sqrt(2) 1];
startSlope = [-1 ; 0];
endSlope = [0 ; -1];
% Get angles of data points
[theta, ~] = cart2pol(x,y);
% Create angles to evaluate the spline at
thetaEval = linspace(pi,pi/2,1000);
% Calculate the spline
spPts = spline(theta,[startSlope [x ; y] endSlope],thetaEval);
plot(spPts(1,:),spPts(2,:),'-b',x,y,'or'); axis equal
I hope this helps with what you need.
-Cam
4 comentarios
Donald Yang
el 25 de Dic. de 2021
Can you explain why the startSlope takes value [-1; 0] denotes a infinite slope? And why endSlope takes [0; -1] denotes a 0 slope?
Más respuestas (0)
Ver también
Categorías
Más información sobre Spline Construction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!