// Fatigue Strenght Diagramms

//function Fatigue_Strenght_Diagramms (K1, K2, Rm, Rp)
    K1=0.44
    K2=1
    Rm=870
    Rp=495
    //K1=sigma_W ./ Rm
    //K2=sigma_F ./ Rp
    sigma_W_pos = +K1*Rm
    sigma_W_neg = -K1*Rm
    sigma_W_half = 0.5*K1*Rm
    PointApos = [0;sigma_W_pos]
    PointAneg = [0;sigma_W_neg]
    PointB = [Rm;Rm]
    PointC = [Rm-sigma_W_half;Rm]
    PointD = [(PointC(1) ./ (Rm - PointApos(2))) .* (Rp - PointApos(2));Rp]
    PointE = [Rp;Rp]
    PointF = [PointD(1);PointD(1)]
    PointG = [PointD(1);PointD(2) - 2 .* (PointD(2)-PointF(2))]
    A1 = [(PointD(2)-PointG(2)) / (PointE(1)-PointD(1))]
    A2 = [(PointG(2)-PointAneg(2)) / (PointG(1)-PointAneg(1))]
    A3 = [(PointD(2)-PointApos(2)) / (PointD(1)-PointApos(1))]
   
    if PointG(2)<0 then 
        X1 = linsolve(A1, PointG(2))
        PointH=[X1+PointG(1);0]
    elseif  PointG(2)>0 then
        X2 = linsolve(A2, PointAneg(2))
        PointH=[X2;0]
    end
    
     Y3 = PointApos(2)+A3*PointH(1)
    
    if Y3<Rp then 
        PointK=[PointH(1);Y3]
    elseif  Y3>Rp then
        PointK=[PointH(1);Rp]
    end
    
    polyx_Smith =[PointApos(1),PointD(1),PointE(1),PointG(1),PointAneg(1)]
    polyy_Smith =[PointApos(2),PointD(2),PointE(2),PointG(2),PointAneg(2)]
    
    polyx_Haigh =[PointApos(1),PointK(1),PointE(1)]
    polyy_Haigh =[PointApos(2),PointK(2)/2,0]
    
    
    n=8
    a=1.70
    b=0.82
    Ticks_Smith_X = [0:Rm/n:Rm]
    Ticks_Smith_Y = [Rm .* ones(1,(n+1))]
    Ticks_Smith = string(["k=-1", "k=0", "k=+1"])
    
    Ticks_Haigh_X = [0:Rm/n:Rm]
    Ticks_Haigh_Y = Rm - [0:Rm/n:Rm]
    Ticks_Haigh = string(["k=-1", "k=0", "k=+1"])
    
    
    
    
//Diagram Smith
figure("figure_name",gettext("Smith Diagramm"),"Position",[50,50,500,500],"BackgroundColor",[1.0,1.0,1.0])
title('$Smith\ Diagram$','color','black','fontsize',5)
plot([0,Rp*a],[0,Rp*a], 'r-.' )
plot([0,PointK(1),PointK(1)*a],[0,PointK(2),PointK(2)*a], 'g-.' )
plot([0,Rm],[Rm,Rm], 'c-' )
plot([Ticks_Smith_X],[Ticks_Smith_Y], 'c+' )

xstring(Ticks_Smith_X(1),Ticks_Smith_Y(1),Ticks_Smith(1))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xstring(Ticks_Smith_X(n/2+1),Ticks_Smith_Y(n/2+1),Ticks_Smith(2))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xstring(Ticks_Smith_X(n+1),Ticks_Smith_Y(n+1),Ticks_Smith(3))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xpoly(polyx_Smith,polyy_Smith)
p=gce();
p.foreground=2;
p.thickness=1;
p.mark_style=9;
p.mark_size=0;
xgrid()
xlabel('Sigma [N/mm2]')
ylabel('Sigma [N/mm2]')

//Diagram Haigh
figure("figure_name",gettext("Haigh Diagramm"),"Position",[50,50,500,500],"BackgroundColor",[1.0,1.0,1.0])
title('$Haigh\ Diagram$','color','black','fontsize',5)

plot([0,Rp],[Rp,0], 'r-.' )
plot([0,Rp*b],[0,Rp*b], 'g-.' )
plot([Rm,0],[0,Rm], 'c-' )
plot([Ticks_Haigh_X],[Ticks_Haigh_Y], 'c+' )

xstring(Ticks_Haigh_X(1),Ticks_Haigh_Y(1),Ticks_Haigh(1))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xstring(Ticks_Haigh_X(n/2+1),Ticks_Haigh_Y(n/2+1),Ticks_Haigh(2))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xstring(Ticks_Haigh_X(n+1),Ticks_Haigh_Y(n+1),Ticks_Haigh(3))
m=gce();
m.font_size = 4;
m.font_style = 1;
m.font_color = 4

xpoly(polyx_Haigh,polyy_Haigh)
q=gce();
q.foreground=2;
q.thickness=1;
q.mark_style=9;
q.mark_size=0;
xgrid()
xlabel('Sigma [N/mm2]')
ylabel('Sigma [N/mm2]')

//Diagram Moore-Kommers-Jasper
//figure("figure_name",gettext("Moore-Kommers-Jasper Diagramm"),"Position",[50,50,500,500],"BackgroundColor",[1.0,1.0,1.0])
//title('$Moore-Kommers-Jasper\ Diagram$','color','black','fontsize',5)
//endfunction
