-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcubic_spline_multiple.m
37 lines (28 loc) · 998 Bytes
/
cubic_spline_multiple.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [s0, s1, s2, s3, qddotLower, qddotUpper, hrep] = cubic_spline_multiple(nvar, h, q, qdot_b)
%% Dimension check
assert(...
isequal(size(q), [length(h) + 1, nvar]), ...
'The trajectory points must be of size (n x nvar)' ...
)
assert(...
isequal(size(qdot_b), [2, nvar]), ...
'The boundary velocities must be of size (2 x nvar)' ...
)
%% Setup
n = length(h) + 1;
hrep = repmat(h, [1, nvar]);
d = (q(2:n, :) - q(1:n-1, :)) ./ hrep;
lower = [h(1:n-1); 0];
main = [2 * h(1); 2 * (h(1:n - 2) + h(2:n - 1)); 2 * h(n - 1)];
upper = [0; h(1:n - 1)];
A = spdiags([lower main upper], [-1 0 1], n, n);
Ainv = inv(A);
for j = 1:nvar
qddot(:, j) = Ainv * [6*(d(1, j) - qdot_b(1, j)); 6*(d(2:n-1, j)-d(1:n-2, j)); 6*(qdot_b(2, j) - d(n-1, j))];
end
qddotLower = qddot(1:end-1, :);
qddotUpper = qddot(2:end, :);
s0 = qddotLower ./ (6 .* hrep);
s1 = qddotUpper ./ (6 .* hrep);
s2 = q(2:end, :) ./ hrep - qddotUpper.* hrep./(6);
s3 = q(1:end-1, :) ./ hrep - qddotLower.* hrep./(6);