function Z=max_zingsnis2(Sp, T, e)
N=size(Sp, 1);
m=1;
for i=1:N
    syms t
    Sx=Sp(i,1);
    Sy=Sp(i,2);
    dx=diff(Sx, t);
    dx2=diff(dx, t);
    dy=diff(Sy, t);
    dy2=diff(dy, t);
    kreiv(i)=(dx*dy2-dx2*dy)/(dx^2+dy^2)^(3/2);
    apacia=(dx^2+dy^2)^(3/2);
    dd=diff(apacia, t);
    ats=double(solve(dd));
    n=size(ats, 1);
    g=1;
    for j=1:n
        if isreal(ats(j))==1 && ats(j)>=T(i) && ats(j)<=T(i+1)
            t=ats(j);
            K(g)=eval(kreiv(i));
            P(g)=ats(j);   
            g=g+1;
        end
    end
    [k(i) indeksas]=max(abs(K));
    kreivis(i)=K(indeksas);
    par(i)=P(indeksas);

end

[max_kreivis i]=max(abs(kreivis));
%surastas taskas funkcijoje, kuriame kreives kreivis yra didziausias
fx=Sp(i,1);
fy=Sp(i,2);
param=par(i);

%randama koordinate nuo to tasko iki tarpinio
D=Diff_parametrine(fx, fy);
t=param;

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(i,1))-x1;
f4=eval(Sp(i,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(i+1,1))-x2;
f4=eval(Sp(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));




