r1 = 2;
r2 = 3;
x1 = 4*pi/6;
x2 = 2*pi/6;
x3 = 3*pi/6;
x4 = 2*pi - (x1 + x2 + x3);
t_table = cumsum([ 0, x1, x2, x3, x4, x1]);
r_table = [r1, r1, r2, r2, r1, r1];
n = 1000;
method = {'linear', 'pchip', 'spline'};
theta = linspace(0, 2*pi, n + 1);
for k = 1:numel(method)
radius = interp1(t_table, r_table, theta, method{k});
hf{k} = figure('WindowStyle', 'Docked');
ha{k}(1) = subplot(2, 1, 1);
plot(theta, radius);
xlabel('\theta [rad]')
ylabel('r [u]')
axis([0, 2*pi, 0, r2*1.1])
grid('on')
ha{k}(2) = subplot(2, 1, 2);
plot(radius.*cos(theta), radius.*sin(theta));
title(['Cam Shape (', method{k}, ')'])
axis('equal')
grid('on')
axis([-1, 1, -1, 1]*r2*1.1)
end