function GrosskreisbogenNBRio

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

clc
deg=pi/180;
dms2rad=inline('(d+m/60+s/3600)*pi/180','d','m','s');  % deg min sec -> rad
lambdaA= dms2rad(13,15,43); phiA= dms2rad(53,33,22);   % NB
lambdaB=-dms2rad(43,13,22); phiB=-dms2rad(22,53,42);   % Rio
[xA,yA,zA]=sph2cart(lambdaA,phiA,1)
[xB,yB,zB]=sph2cart(lambdaB,phiB,1)
e1S=[xA;yA;zA]
ab=cross(e1S,[xB;yB;zB])
q=norm(ab)
e3S=ab/q
e2S=cross(e3S,e1S)
R=[e1S e2S e3S];
dS=acos(dot(e1S,[xB;yB;zB]))
for t=linspace(0,dS,4)
  Z=  cos(t)*e1S+sin(t)*e2S;
  dZ=-sin(t)*e1S+cos(t)*e2S;
  [lambda,phi]=cart2sph(Z(1),Z(2),Z(3));
  [dL,mL,sL]=rad2dms(abs(lambda));
  [dB,mB,sB]=rad2dms(abs(phi));
  fprintf('%.7f & %.7f & %.7f & %.0f^\\circ%.0f''%.0f'''' & %.0f^\\circ%.0f''%.0f''''\n',...
    Z,sign(lambda)*dL,mL,sL,sign(phi)*dB,mB,sB)
  eN=[-sin(phi)*cos(lambda);-sin(phi)*sin(lambda);cos(phi)];
  eO=[-sin(lambda);cos(lambda);0];
  K=atan2(dot(eO,dZ),dot(eN,dZ));
  K=K+2*pi*(K<0);
  [dK,mK,sK]=rad2dms(K);
  fprintf('%.7f & %.7f & %.7f & %.7f & %.7f & %.7f &  %.7f & %.7f & %.7f & %.0f^\\circ%.0f''%.0f''''\n',...
   dZ,eO,eN,dK,mK,sK)
end


function [d,m,s]=rad2dms(rad)
  D=rad/pi*180;
  d=fix(D);
  M=(D-d)*60;
  m=fix(M);
  s=(M-m)*60;
