clc;
clear;
m = 85; %[kg]
g = 9.81; %[m^2/s]
v = 23.3; %[mm/s]
G=m*g; %[N]
%G=1;

alfamax = 30*pi/180;
alfamin = -20*pi/180;
alfa = alfamin:pi/(4*180):alfamax;
alfastupne=alfa*180/pi;
n = length(alfa);

a = 0.4624; %[m]
b = 0.4289; %[m]
r1 = 0.993; %[m]
r2 = 0.3985; %[m]
d1 = 0.016; %[m]
d2 = 0.0066; %[m]

for i=1:n
    x1(i)=r2*cos(alfa(i))+d2*sin(alfa(i));
    x2(i)=r2*sin(alfa(i))+d2*cos(alfa(i));
    gama(i) = atan((b-x1(i))/(a-x2(i)));
    
    Gx(i)=G*sin(alfa(i));
    Gy(i)=G*cos(alfa(i));
    
    
    Fx(i)=(-Gx(i)*d1+Gy(i)*r1)/(r2+d2*tan(alfa(i)+gama(i)));
    Fy(i)=Fx(i)*tan(alfa(i)+gama(i));
    F(i)=(Fx(i)^2+Fy(i)^2)^(1/2);
    Rx(i)=Fx(i)-Gx(i);
    Ry(i)=Gy(i)+Fy(i);
    R(i)=(Rx(i)^2+Ry(i)^2)^(1/2);

    om(i)=v*cos(alfa(i)+gama(i))/(r2*1000);
    L(i)=((b-x1(i))^2+(a-x2(i))^2)^(1/2);
end
figure(1)
hold on
xlabel('{\alpha} [°]')
 ylabel('[N]')

 plot(alfastupne, F,'-k', alfastupne, R,'--k')
% plot(alfastupne, gama); %rozsah náklonu převodovky
legend('F','R')
hold off

 
figure(2)
hold on
xlabel('{\alpha} [°]')
colororder({'k','k'})
yyaxis left
plot(alfastupne,om,'-k');
ylabel('úhlová rychlost rotačního pohybu [rad/s]','Color','k')
yyaxis right
plot(alfastupne,L,'--k');
legend('{\omega}','L')
ylabel('vzdálenost mezi ložisky B a C [mm]','Color','k')
hold off


figure(3)
hold on
xlabel('{\alpha} [°]')
 ylabel('[N]')

plot(alfastupne, Fx,'-k', alfastupne, Fy,'--k', alfastupne, Rx,':k', alfastupne, Ry,'-.k')
% plot(alfastupne, gama); %rozsah náklonu převodovky
legend('Fx','Fy','Rx','Ry')
hold off

ZATIZENIF=max(F)
ZATIZENIR=max(R)
OMEGAmax=max(om)
OMEGAmin=min(om)
Delka=max(L)