clear, clc, close all
format compact

figure(1)
data = textread('Cam_Horizontal.txt');

x = (((data(1,13):0.01:data(1,14))-data(1,13))/(data(1,14)-data(1,13)));
y = data(1,1) + data(1,2).*x.^1 + data(1,3).*x.^2 + data(1,4).*x.^3 + data(1,5).*x.^4+ data(1,6).*x.^5 + data(1,7).*x.^6;
p = plot(x.*(data(1,14) - data(1,13))+data(1,13),data(1,15)+y*(data(1,16) - data(1,15)),'r');
set(p,'linewidth',1);
hold on

x = [data(2,13) data(2,14)];
y = [data(2,15) data(2,16)];
p = plot(x,y,'r');
set(p,'linewidth',1);

x = (((data(3,13):0.01:data(3,14))-data(3,13))/(data(3,14)-data(3,13)));
y = data(3,1) + data(3,2).*x.^1 + data(3,3).*x.^2 + data(3,4).*x.^3 + data(3,5).*x.^4+ data(3,6).*x.^5 + data(3,7).*x.^6;
p = plot(x.*(data(3,14) - data(3,13))+data(3,13),data(3,15)+y*(data(3,16) - data(3,15)),'r');
set(p,'linewidth',1);

axis([0 85 0 120]);
set(gca,'ytick',0:5:120);
set(gca,'fontsize',15);
title('Horizontálna vačka','fontsize',22)
xlabel('Master [mm]','fontsize',18)
ylabel('Slave [°]','fontsize',18)
grid

figure(2)
data = textread('Cam_Vertical.txt');
p11 = plot(data(:,1),data(:,2),'k');
set(p11,'linewidth',1.5);
hold on

data = textread('Cam_Vertical_Bezier.txt');
for index = 1:16
    x = (((data(index,13):0.01:data(index,14))-data(index,13))/(data(index,14)-data(index,13)));
    y = data(index,1) + data(index,2).*x.^1 + data(index,3).*x.^2 + data(index,4).*x.^3 + data(index,5).*x.^4+ data(index,6).*x.^5 + data(index,7).*x.^6;
    p = plot(x.*(data(index,14) - data(index,13))+data(index,13),data(index,15)+y*(data(index,16) - data(index,15)),'r');
    set(p,'linewidth',1);
    hold on
end

title('Vertikálna vačka','fontsize',22)
xlabel('Master [mm]','fontsize',18)
ylabel('Slave [°]','fontsize',18)
axis([0 90 0 60]);
set(gca,'ytick',0:5:60);
set(gca,'fontsize',15);
l = legend('Lineárna interpolácia','Interpolácia Bezierovými splinami');
set(l,'fontsize',18);
grid

shg