function prujezd = plotspline(a1, a2, distance, m)
if (m<0),
    prujezd = 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);
    ];


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

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(4,1,1);
cla
axis equal
hold on
plot(p(:,1), p(:,2));
title(sprintf('Angle = %d^o', abs(a1-a2)));
for t=0:0.01:1,
    plot(polyval(px,t), polyval(py,t), '.');
end


% vypocet drahy
subplot(4,1,2);
cla
hold on
grid on
title('Distance');
xlabel('t');

s = 0:1:100;
s(1) = 0;
for t=0:1:100,
    if (t~=0)
        deltaS = sqrt((polyval(px, t/100)-polyval(px, t/100-0.01))^2 + (polyval(py, t/100)-polyval(py, t/100-0.01))^2);
        s(t + 1) = s(t) + deltaS;
    end
    plot(t/100, s(t+1), '+');
end


subplot(4,1,3);
cla
title('Curvature');
xlabel('t');
grid on
hold on

kappa = 0:1:100;
for i=0:1:100,
    t=i/100;
    kappa(i+1) = ((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(i+1), '+');
end

subplot(4,1,4);
cla
plot(s, kappa, '+');
title('Curvature on Distance');
xlabel('s');
grid on
hold off

%vytvoreni deltaKappa
deltaKappa = 0:1:100;
for i=2:1:101,
    deltaKappa(i) = kappa(i) - kappa(i-1);
end

prujezd = 0;
for i=2:1:101,
    deltaKK = abs(deltaKappa(i) - deltaKappa(i-1)) / (s(i) - s(i-1));
    prujezd = prujezd + deltaKK;
end

    
    
    
