cscvn of a function, coefficients and breaks

8 次查看(过去 30 天)
Hey all together,
I have another question concerning the cscvn function. When I create a spline for a function with cscvn
yy = cscvn(xges)
and take a look at yy.coefs and yy.breaks
form: 'pp'
breaks: [1x25 double]
coefs: [48x4 double]
pieces: 24
order: 4
dim: 2
then I have nearly twice as much coefs as breaks. How is this possible and what does that mean? How can I create the piecewise polynomial functions out of my coefs? At the end I want to calculate the curvature of the function, but first I have to understand what this coefs mean, and how I can create the piecewise polynoms.
Thank you in advance,
David

回答(1 个)

Bruno Luong
Bruno Luong 2023-11-24
编辑:Bruno Luong 2023-11-24
This is how to use pp
m = 2;
n = 5; % 25 in the original question
points = rand(m,n);
pp = cscvn(points)
pp = struct with fields:
form: 'pp' breaks: [0 0.8735 1.5529 2.4191 3.2527] coefs: [8×4 double] pieces: 4 order: 4 dim: 2
m = pp.dim;
p = pp.pieces;
% https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/INT-APP/PARA-centripetal.html
%D = diff(points,1,2);
%d = sqrt(sqrt(sum(D.^2,1)));
%t = cumsum([0 d]); % Eugene Lee's, equal to pp.breaks, see https://www.mathworks.com/help/curvefit/cscvn.html
t = pp.breaks;
ni = 200;
ti = linspace(t(1),t(end), ni);
loc = discretize(ti, t);
x = zeros(length(ti), m);
coefs = reshape(pp.coefs, m, p, []);
for k=1:p
ink = loc == k;
tik = ti(ink);
dti = tik - t(k);
for d=1:m
P = coefs(d, k, :);
x(ink,d) = polyval(P(:), dti);
end
end
close all
hold on
if m == 2
plot(points(1,:),points(2,:),'or'),
plot(x(:,1), x(:,2),'b.')
elseif m == 3
plot3(points(1,:),points(2,:),points(3,:),'or'),
plot3(x(:,1), x(:,2), x(:,3), 'b.')
else
warning('plotting not supported')
end

类别

Help CenterFile Exchange 中查找有关 Spline Construction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by