function vdiff = plotspline(a1, a2, distance, m)
if (m<0),
    vdiff = inf;
    return
end
% a1=60;
% a2=0;
% m=1.30;
p = [
    cos(a1/180.*pi) sin(a1/180.*pi);
    0 0;
    cos(a2/180.*pi) sin(a2/180.*pi);
    ]*distance;


x0 = p(1,1);
y0 = p(1,2);
x1 = p(3,1);
y1 = p(3,2);
xx0 = m.*(p(2,1) - p(1,1)) / distance;
yy0 = m.*(p(2,2) - p(1,2)) / distance;
xx1 = m.*(p(3,1) - p(2,1)) / distance;
yy1 = m.*(p(3,2) - p(2,2)) / distance;

px = [ 
   -3.*xx1-3.*xx0-6.*x0+6.*x1
  7.*xx1+8.*xx0+15.*x0-15.*x1
 -4.*xx1-6.*xx0-10.*x0+10.*x1
                        0
                      xx0
                       x0];
 
 
 
py = [
   -3.*yy1-3.*yy0-6.*y0+6.*y1
  7.*yy1+8.*yy0+15.*y0-15.*y1
 -4.*yy1-6.*yy0-10.*y0+10.*y1
                        0
                      yy0
                       y0];
                       
figure(1);
subplot(2,2,1);
plot(p(:,1), p(:,2), 'r');
hold on
title(sprintf('Angle = %d^o', abs(a1-a2)));
t=0:0.01:1;
plot(polyval(px,t), polyval(py,t), 'b');
axis equal
hold off
grid on

subplot(2,2,2);
kappa = ((5.*(-3.*xx1-3.*xx0-6.*x0+6.*x1).*t.^4+4.*(7.*xx1+8.*xx0+15.*x0-15.*x1).*t.^3+3.*(-4.*xx1-6.*xx0-10.*x0+10.*x1).*t.^2+xx0).*(20.*(-3.*yy1-3.*yy0-6.*y0+6.*y1).*t.^3+12.*(7.*yy1+8.*yy0+15.*y0-15.*y1).*t.^2+6.*(-4.*yy1-6.*yy0-10.*y0+10.*y1).*t)-(5.*(-3.*yy1-3.*yy0-6.*y0+6.*y1).*t.^4+4.*(7.*yy1+8.*yy0+15.*y0-15.*y1).*t.^3+3.*(-4.*yy1-6.*yy0-10.*y0+10.*y1).*t.^2+yy0).*(20.*(-3.*xx1-3.*xx0-6.*x0+6.*x1).*t.^3+12.*(7.*xx1+8.*xx0+15.*x0-15.*x1).*t.^2+6.*(-4.*xx1-6.*xx0-10.*x0+10.*x1).*t))./((5.*(-3.*xx1-3.*xx0-6.*x0+6.*x1).*t.^4+4.*(7.*xx1+8.*xx0+15.*x0-15.*x1).*t.^3+3.*(-4.*xx1-6.*xx0-10.*x0+10.*x1).*t.^2+xx0).^2+(5.*(-3.*yy1-3.*yy0-6.*y0+6.*y1).*t.^4+4.*(7.*yy1+8.*yy0+15.*y0-15.*y1).*t.^3+3.*(-4.*yy1-6.*yy0-10.*y0+10.*y1).*t.^2+yy0).^2).^(3/2);
plot(t, kappa);
title('Curvature');
xlabel('t');
grid on

subplot(2,2,4);
cla
vmin=inf;
vmax=-inf;
v=sqrt(polyval(polyder(px),t).^2+...
           polyval(polyder(py),t).^2);
vmin=min(v);
vmax=max(v);
plot(t, v);
title('Speed');
xlabel('t');
grid on

subplot(2,2,3);
plot(v,kappa, '+');
xlabel('Speed');
ylabel('Curvature');
grid on

vdiff = vmax-vmin;