function [p, pd, pdd ] = linearSegWithParabolicBlends(x0, xf, tvec)
%linearSegWithParabolicBlends 1-D trapezoidal-velocity-profile trajectory

% Copyright 2016 The MathWorks, Inc.
validateattributes(tvec, {'numeric'}, {'increasing', '>=', 0, '<=', 1 });
% params

tb = 0.2;
vmax = (xf -x0)/ (1-tb);
a = vmax/tb;

n = length(tvec);
p = zeros(1,n);
pd = zeros(1,n);
pdd = zeros(1,n);
for i = 1:n
    if tvec(i) < tb
       pdd(i) =  a;
       pd(i) = a*tvec(i);
       p(i) = x0 + 0.5*a*tvec(i)*tvec(i);
    else
        if tvec(i) >= tb && tvec(i) < 1 -tb
            pdd(i) =  0;
            pd(i) = vmax;
            p(i) = x0 + 0.5*a*tb*tb + vmax*(tvec(i)-tb);                
        else
            pdd(i) =  -a;
            pd(i) = vmax -a*(tvec(i) - 1 + tb);
            p(i) = x0 + 0.5*a*tb*tb + vmax*(1-2*tb) + vmax*(tvec(i)-1 + tb) - 0.5*a*(tvec(i)-1 + tb)*(tvec(i)-1 + tb);                       
        end

    end
end
    
end