function Z=max_zingsnis(Sp, T, e)
N=size(Sp, 1);
m=1;
for i=1:N
    Sx=Sp(i,1);
    Sy=Sp(i,2);
    D=Diff_parametrine(Sx, Sy);
    D2=diff(D);
    for j=T(i):0.001:T(i+1)
        t=j;
        kreivis(m)=eval(D2)/(1+(eval(D))^2)^(3/2);
        kreive(m, :)=[i j];
        m=m+1;
    end
end
[max_kreivis i]=max(abs(kreivis));
%surastas taskas funkcijoje, kuriame kreives kreivis yra didziausias
fx=Sp(kreive(i,1),1);
fy=Sp(kreive(i,1),2);
param=kreive(i,2);

%randama koordinate nuo to tasko iki tarpinio
D=Diff_parametrine(fx, fy);
t=param;
% fx1=eval(fx);
% fy1=eval()
% if (s1>0) || (s1==0 && s2>=0)
kr=sign(kreivis(i))*-1;
x=-e*kr*eval(D)/sqrt(1+((eval(D))^2))+eval(fx);
y=e*kr/sqrt(1+((eval(D))^2))+eval(fy);

%liestines-tieses kryptis
k=eval(D);
syms x1 y1 t2
t=t2;
% f3=eval(Sp(kreive(i,1),1))-x1;
% f4=eval(Sp(kreive(i,1),2))-y1;
f3=eval(Sp(N,1))-x1;
f4=eval(Sp(N,2))-y1;
f5=k*(x-x1)-(y-y1);

a=solve(f3, f4, f5);
x1=double(a.x1);
y1=double(a.y1);

clear a
%antras taskas

syms x2 y2 t2
t=t2;
f3=eval(Sp(kreive(i,1),1))-x2;
f4=eval(Sp(kreive(i,1),2))-y2;
f5=k*(x-x2)-(y-y2);
a=solve(f3, f4, f5);
x2=double(a.x2);
y2=double(a.y2);
Z=atstumas(x1(2), x2(2), y1(2), y2(2));




