function Drehmatrix2d

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

clc;
close('all')
deg=pi/180;
global ax
ax=[inf -inf inf -inf];
xMax=1.06;
yMax=xMax;
O=[0;0];
OS=O;
alpha=55*deg;
xS=[ cos(alpha);sin(alpha)];
yS=[-sin(alpha);cos(alpha)];
hold('on')
h=0.1;
drawPolygon(@fill,[OS+xS [OS(1)+xS(1);OS(2)] [OS(1)+yS(1);OS(2)] OS+yS OS],0.875*[1 1 1],'erase','none')
drawPolygon(@plot,[[-1.1*sin(alpha);0] [xMax;0]],'k')
drawPolygon(@plot,[O [0;yMax]],'k')
drawPolygon(@plot,[O OS],'k')
drawPolygon(@plot,[O+[0;1] O O+[1;0]],'color',0.5*[1 1 1],'linewidth',2.0)
drawPolygon(@plot,[OS+xS OS OS+yS],'k','linewidth',1.5)
Spitze(OS,OS,h,45*pi/180,'k')
Spitze([1;0],[1;0],h,45*pi/180,0.5*[1 1 1])
Schrift([1;0],'{\it\bfe}_1','color',0.5*[1 1 1],'HorizontalAlignment','center','VerticalAlignment','top');
Spitze([0;1],[0;1],h,45*pi/180,0.5*[1 1 1])
Schrift([0;1],'_{ }{\it\bfe}_2','color',0.5*[1 1 1],'HorizontalAlignment','left','VerticalAlignment','middle');
drawPolygon(@plot,[OS+xS [OS(1)+xS(1);OS(2)] [OS(1)+yS(1);OS(2)] OS+yS],'k')
Spitze(OS+xS,xS,h,45*pi/180,'k')
Schrift(OS+xS,'_{ }{\it\bfe}_1''','rotation',alpha/deg,'HorizontalAlignment','left','VerticalAlignment','middle');
Spitze(OS+yS,yS,h,45*pi/180,'k')
Schrift(OS+yS,'{\it\bfe}_2''','rotation',alpha/deg-90,'HorizontalAlignment','right','VerticalAlignment','middle');
Schrift(OS,'^{    }\alpha','FontSize',32,'HorizontalAlignment','left','VerticalAlignment','bottom');
Schrift([0;1/3],'\alpha_{ }','FontSize',32,'HorizontalAlignment','right','VerticalAlignment','top');
Spitze(xS/3, yS,h/2,60*pi/180,'k');
Spitze(yS/3,-xS,h/2,60*pi/180,'k');
Kreisbogen(OS+[1;0]/3,OS,OS+xS/3,0,'k')
Schrift(OS+yS-0.75*h*[0;1],'_{ }\alpha','FontSize',24,'HorizontalAlignment','left','VerticalAlignment','top');
Kreisbogen(OS+xS/3,OS,[0;1/3],0,'--k')
Kreisbogen([0;1/3],OS,OS+yS/3,0,'k')
Kreisbogen(OS+yS/3,OS,[-1/3;0],0,'--k')
Kreisbogen(OS+yS-[0;1]/4,OS+yS,OS+yS-yS/4,0,'k')
Schrift(OS+[xS(1);0]/2,'cos \alpha','FontSize',30,...
  'HorizontalAlignment','center','VerticalAlignment','top');
Schrift(OS+[xS(1);xS(2)/2],'sin \alpha','rotation',90','FontSize',30,...
  'HorizontalAlignment','center','VerticalAlignment','top');
Schrift(OS+[yS(1);0]/2,'sin \alpha','FontSize',30,...
  'HorizontalAlignment','center','VerticalAlignment','top');
Schrift(OS+[yS(1);yS(2)/2],'cos \alpha','rotation',90','FontSize',30,...
  'HorizontalAlignment','center','VerticalAlignment','bottom');
drawPolygon(@plot,[[0;sin(alpha)] [ cos(alpha);sin(alpha)]],'--k');
drawPolygon(@plot,[[0;cos(alpha)] [-sin(alpha);cos(alpha)]],'--k');
drawPolygon(@plot,[[ cos(alpha);0] [-sin(alpha);0] [0;sin(alpha)] [0;cos(alpha)] ...
    [cos(alpha);sin(alpha)] [-sin(alpha);cos(alpha)]],'+k');
Schrift([ cos(alpha);0],'_{    }{\itr}_{11}','FontSize',25,'HorizontalAlignment','center','VerticalAlignment','top');
Schrift([-sin(alpha);0],'{\itr}_{12}','FontSize',25,'HorizontalAlignment','center','VerticalAlignment','top');
Schrift([0; sin(alpha)],'{\itr}_{21 }','FontSize',25,'HorizontalAlignment','right','VerticalAlignment','middle');
Schrift([0; cos(alpha)],'_{ }{\itr}_{22}','FontSize',25,'HorizontalAlignment','left','VerticalAlignment','middle');
hold('off')
axis('off')
axis('equal')
axis(ax+0.5*h*[-1 1 -1 1])
print('-depsc','Drehmatrix2d')

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',30,varargin{:});

function Spitze(P,v,L,alpha,varargin)
if nargin<=2
  L=1;
end
if nargin<=3
  alpha=7.5*pi/180;
end
ta=tan(alpha/2);
v=L*v./repmat(sqrt(dot(v,v)),size(P,1),1);
n=[-v(2,:);v(1,:)];
Q=P-v+ta*n;
R=P-v-ta*n;
for k=1:size(P,2);
  fill([P(1,k) Q(1,k) R(1,k)],[P(2,k) Q(2,k) R(2,k)],varargin{:})
end

function Kreisbogen(A,M,B,offset,varargin)
deg=pi/180;
[t1,r1]=cart2pol(A(1)-M(1),A(2)-M(2));
[t2,r2]=cart2pol(B(1)-M(1),B(2)-M(2));
if abs(r1-r2)>sqrt(eps)
  error('Kreisbogen: A und B liegen nicht auf einem Kreis mit Mittelpunkt M')
end
r=(r1+r2)/2;
t1=t1-offset;
t2=t2+offset;
if t2<t1
  t2=t2+2*pi;
end
t=linspace(t1,t2,round((t2-t1)/deg));
drawPolygon(@plot,repmat(M,size(t))+r*[cos(t);sin(t)],varargin{:});
