function Pyth345

% http://geometrie.hs-nb.de/MATLAB-Programme/Pyth345.m   Bearbeitungsstand: 20.10.2004
% (C) Martin Nitschke, nitschke@hs-nb.de

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
a=4;
b=3;
c=sqrt(a^2+b^2);
A=[0;0];
B=A+[a;0];
C=A+[0;b];
drawPolygon(@plot,[A B C A],'k')
hold('on')

drawPolygon(@plot,[A(1)+[0:a];repmat(A(2),1,a+1)],'.k','MarkerSize',90,'color',0.5*[1 1 1])
drawPolygon(@plot,[repmat(A(1),1,b+1);A(2)+[0:b]],'.k','MarkerSize',90,'color',0.5*[1 1 1])
v=C-B;
v=v/norm(v);
drawPolygon(@plot,repmat(B,1,c+1)+[[0:c]*v(1);[0:c]*v(2)],'.k','MarkerSize',90,'color',0.5*[1 1 1])

Schrift((A+B)/2,['{ }' int2str(a)],'HorizontalAlignment','center','VerticalAlignment','top','Rotation',Rot(A,B))
Schrift((A+C)/2,int2str(b),'HorizontalAlignment','center','VerticalAlignment','bottom','Rotation',Rot(A,C))
Schrift((B+C)/2,int2str(c),'HorizontalAlignment','center','VerticalAlignment','bottom','Rotation',Rot(B,C))
hold('off')
axis('off')
axis('equal')
axis(ax+[-0.2 0 -0.4 0])
print('-depsc','Pyth345')

function drawPolygon(draw,P,varargin);
global ax
feval(draw,P(1,:),P(2,:),varargin{:})
if min(P(1,:))<ax(1)
  ax(1)=min(P(1,:));
end
if max(P(1,:))>ax(2)
  ax(2)=max(P(1,:));
end
if min(P(2,:))<ax(3)
  ax(3)=min(P(2,:));
end
if max(P(2,:))>ax(4)
  ax(4)=max(P(2,:));
end

function Schrift(P,txt,varargin)
text(P(1),P(2),txt,'FontName','TimesNewRoman','FontSize',100,varargin{:});

function r=Rot(a,b)
deg=pi/180;
r=atan2(b(2)-a(2),b(1)-a(1))/deg;
if r<0
  r=r+180;
end
if r>90
  r=r-180;
end
