global gm gk omegak kor fi0;

%parameetri
gm=3.98604418e+5;
gk=4.9048695e+3;
mkr=6378.;
kkr=1738.;
kor=384399.;
kok=1.022;
omegak=kok/kor;
%fi0=-pi*52.7145/180.;
fi0=-pi*60./180.;
%fi0=-pi/3.62;

%alg tingimused
r0=[-6471.;0.;0.;-11.01];

options = odeset('RelTol',1e-8,'AbsTol',1e-8,'MaxStep',10000.,'InitialStep',1.);
[t,r]=ode45(@kplf2,[0,400000], r0,options);

grid on;

z=r(:,1)*0;
%sphere

th = 0:pi/50:2*pi;
xunit =  cos(th);
yunit = sin(th);
h = plot(xunit, yunit);

x=kor*cos(omegak*t+fi0)./mkr;
y=kor*sin(omegak*t+fi0)./mkr;

axis equal
hold on
nt=size(t);
h=animatedline();
h1=animatedline();
for i=1:nt
addpoints(h,r(i,1)/mkr,r(i,2)/mkr);addpoints(h1,x(i),y(i));
F(i)=getframe;
end

