Is there a 2-D spline function to interpolate data and specify endpoint derivative information
조회 수: 21 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cam Salzberger
2015년 9월 2일
편집: Cam Salzberger
2015년 9월 3일
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
Donald Yang
2021년 12월 25일
Can you explain why the startSlope takes value [-1; 0] denotes a infinite slope? And why endSlope takes [0; -1] denotes a 0 slope?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Construction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!