clc
close all
clear all
%% nacteni zmerenych souradnic z DGPS 
load S0;
load S1;
load S2;
load S3;
load S4;
load S5;
load S6;
load S7;

korekcex  = 1.499; % korekce je zde kvuli laserove a gps vzdalenosti z jednoho bodu
korekcey = -0.9379; % korekce je zde kvuli laserove a gps vzdalenosti z jednoho bodu
close all;
plot(S0(:,1)+korekcex,S0(:,2)+korekcey,'+r')
hold on;
plot(S1(:,1)+korekcex,S1(:,2)+korekcey,'+b')
plot(S2(:,1)+korekcex,S2(:,2)+korekcey,'+r')
plot(S3(:,1)+korekcex,S3(:,2)+korekcey,'+b')
plot(S4(:,1)+korekcex,S4(:,2)+korekcey,'+r')
plot(S5(:,1)+korekcex,S5(:,2)+korekcey,'+b')
plot(S6(:,1)+korekcex,S6(:,2)+korekcey,'+r')
plot(S7(:,1)+korekcex,S7(:,2)+korekcey,'+b')

axis  equal
grid on
%% vzdalenosti zmerene laserem
presna_vzdalenost = [0 10.03 19.48 30.34 40.88 50.99 60.11 77.08]; 


S0X = median(S0(:,1))+korekcex;
S0Y = median(S0(:,2))+korekcey;

S1X = median(S1(:,1))+korekcex;
S1Y = median(S1(:,2))+korekcey;
S2X = median(S2(:,1))+korekcex;
S2Y = median(S2(:,2))+korekcey;

S3X = median(S3(:,1))+korekcex;
S3Y = median(S3(:,2))+korekcey;

S4X = median(S4(:,1))+korekcex;
S4Y = median(S4(:,2))+korekcey;

S5X = median(S5(:,1))+korekcex;
S5Y = median(S5(:,2))+korekcey;

S6X = median(S6(:,1))+korekcex;
S6Y = median(S6(:,2))+korekcey;

S7X = median(S7(:,1))+korekcex;
S7Y = median(S7(:,2))+korekcey;

%%% zde jsou pouze body vyfiltrovane medianem nebudeme je zobrazovat

% plot(S0X,S0Y,'k+');
% hold on;
% plot(S1X,S1Y,'k+');
% 
% plot(S2X,S2Y,'k+');
% plot(S3X,S3Y,'k+');
% 
% plot(S4X,S4Y,'k+');
% plot(S5X,S5Y,'k+');
% 
% plot(S6X,S6Y,'k+');
% plot(S7X,S7Y,'k+');
% 
plot(0,0,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)
plot(2.98,9.546,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)
hold on;
plot(5.636,18.58,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)

plot(8.69,28.96,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)
plot(11.65,39.04,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)

plot(14.50,48.70,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)
plot(17.06,57.42,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)

plot(21.83,73.65,'m-+','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',15)

x = [S0X S1X S2X S3X S4X S5X S6X S7X];
y = [S0Y S1Y S2Y S3Y S4Y S5Y S6Y S7Y];
xp = 0:0.1:25;
k = polyfit(x,y,1);
y1=polyval(k,xp);
plot(xp,y1);
hold on
 t = 0:pi/18:pi/2;
 r = presna_vzdalenost; 
  for i=1:8
     x = r(i)*cos(t);
     y = r(i)*sin(t);
     plot(x, y, 'k-.') %kruznice (sisata, protoze má r?tka na osach x, y jsou ru zna)
 
 end
 axis equal; %presna kruznice

 
 t = 0:0.01:2*pi;
 % 0.okoli kolem presneho bodu 
 x = 1.34*cos(t);
 y = 1.34*sin(t);
 plot(x,y,'g');

 
 t = 0:pi/18:2*pi;
 % 1.okoli kolem presneho bodu 
 x = 1.29*cos(t)+2.98;
 y = 1.29*sin(t)+9.55;
 plot(x,y,'g');

  % 2.okoli kolem presneho bodu 
 x = 1.31*cos(t)+5.636;
 y = 1.31*sin(t)+18.58;
 plot(x,y,'g');

  % 3.okoli kolem presneho bodu 
 x = 1.30*cos(t)+8.69;
 y = 1.30*sin(t)+28.96;
 plot(x,y,'g');

  % 4.okoli kolem presneho bodu 
 x = 0.85*cos(t)+11.65;
 y = 0.85*sin(t)+39.04;
 plot(x,y,'g');

  % 5.okoli kolem presneho bodu 
 x = 1.16*cos(t)+14.50;
 y = 1.16*sin(t)+48.70;
 plot(x,y,'g');

  % 6.okoli kolem presneho bodu 
 x = 0.52*cos(t)+17.06;
 y = 0.52*sin(t)+57.42;
 plot(x,y,'g');

  % 7.okoli kolem presneho bodu 
 x = 0.57*cos(t)+21.83;
 y = 0.57*sin(t)+73.65;
 plot(x,y,'g');
 
 title('Relativní přesnost DGPS')
 xlabel('x[m]')
 ylabel('y[m]')






