1function [x] = EvalSpline(t,spline)
 2
 3% multipal knots splines
 4n = find(spline.startTime<t, 1, 'last');
 5if isempty(n)
 6    n = 1;
 7end
 8
 9% shift and scale time
10t = (t-spline.startTime(n))/spline.duration(n);
11
12% clip t between 0 and 1
13t = max(t,0);
14t = min(t,1);
15
16% if isfield(spline,'tm')
17%     if t<spline.tm;
18%         spline.coefs = spline.coefs(:,1);
19%     else
20%         spline.coefs = spline.coefs(:,2);
21%     end
22% end
23
24x = [0, 0, 0]; % [pos,vel,acc]
25for i = 1:size(spline.coefs,2)
26    x(1) = x(1) + t^(i-1)*spline.coefs(n, i);
27    if i > 1
28        x(2) = x(2) + (i-1)*t^(i-2)*spline.coefs(n, i);
29    end
30    if i > 2
31        x(3) = x(3) + (i-2)*(i-1)*t^(i-3)*spline.coefs(n, i);
32    end
33end
34
35
36% scale with duration
37x(2) = x(2)/spline.duration(n);
38x(3) = x(3)/spline.duration(n)^2;