% conoscopy.mp
% L. Nobre G. 
% 2013

input featpost3Dplus2D;

verbatimtex \documentclass{article}\begin{document} etex

beginfig(1);
  f := (6,5,5);
  Spread := 125;
  numeric maja, raya, angphi, angthe, decl, valy, valz, rectsiz;
  color majav, aphiv, aphip, majbv, perpv, perpvl;
  maja = 0.72;
  raya = 0.5;
  angphi = 15;
  angthe = 30;
  rectsiz = 0.06;
  majav = (0,0,maja);
  aphiv = raya*(cosd(angphi),sind(angphi),0);
  aphip = raya*(sind(angphi),-cosd(angphi),0);
  majbv = planarrotation( majav, aphip, angthe );
  perpv = ncrossprod(majbv,aphiv);
  decl = Z(perpv)/(Y(perpv)++X(perpv));
  valy = maja*raya/((decl*raya)++maja);
  valz = valy*decl;
  if angthe>90: valy:=-valy; fi;
  perpv := blue*valz-N(aphip)*valy;
  perpvl = maja*N(perpv);
  spheroid( black, majav, raya );
  drawoptions( dashed (withdots scaled 0.25) );
  cartaxes( 1, 1, 1 );
  draw rigorouscircle( black, blue, raya );
  draw rp(black)--rp(-aphiv);
  draw rp(black)--rp(-majbv);
  %draw rp(black)--rp(-majav);
  %draw rp(black)--rp(-aphip);
  %draw rp(black)--rp(-perpv);
  draw ellipticpath( black, majbv, aphiv );
  drawoptions();
  drawarrow rp((raya,0,0))--rp((1,0,0));
  drawarrow rp((0,raya,0))--rp((0,1,0));
  drawarrow rp(majav)--rp((0,0,1));
  drawoptions( withpen pencircle scaled 1.7pt withcolor 0.65blue );
  drawarrow rp(black)--rp(aphiv);
  drawarrow rp(black)--rp(majbv);
  %draw rp(black)--rp(majav);
  %drawarrow rp(black)--rp(aphip);
  drawarrow rp(black)--rp(perpvl);
  drawoptions( withpen pencircle scaled 1.3pt );
  draw subpath (-1,15) of ellipticpath( black, majbv, aphiv ) dashed evenly;
  %draw ellipticpath( black, aphip, majav ) dashed evenly;
  % draw ellipticpath( black, green, 2*blue ) dashed evenly;
  drawoptions();
  squareangline( perpv, aphiv, black, rectsiz);
  squareangline( perpv, majbv, black, rectsiz);
  squareangline( majbv, aphiv, black, rectsiz);
  angline(majav, perpv, black, maja-raya, btex $\theta$ etex)(rt);
  pickup pencircle scaled 3.6pt;
  draw rp(-aphiv); %label.bot("aphiv",rp(aphiv));
  draw rp(-majbv); %label.lft("majbv",rp(majbv));
  %draw rp(majav); label.rt("majav",rp(majav));
  %draw rp(-aphip); label.rt("aphip",rp(aphip));
  draw rp(perpv); %label.rt("perpv",rp(perpvl));
  label.llft(btex $\vec{n}^{\prime\prime}$ etex,rp(aphiv));
  label.ulft(btex $\vec{n}^{\prime}$ etex,rp(majbv));
  label.top(btex $\vec{p}$ etex,rp(perpvl));
endfig;

beginfig(2);
  f := (6,4,3);
  Spread := 125;
  numeric maja, raya, angphi, angthe, pes;
  color majav, aphiv, aphip, majbv;
  path ell;
  maja = 0.82;
  raya = 0.5;
  angphi = -15;
  angthe = 55;
  pes = 1.3pt;
  drawoptions( withpen pencircle scaled pes );
  majav = (0,0,maja);
  aphiv = raya*(cosd(angphi),sind(angphi),0);
  aphip = raya*(sind(angphi),-cosd(angphi),0);
  majbv = planarrotation( majav, aphip, angthe );
  spheroid( black, majav, raya );
  ell = ellipticpath( black, majbv, aphiv );
  draw subpath (3,20) of ell;
  drawoptions( withpen pencircle scaled pes dashed (withdots scaled 0.42) );
  draw rigorouscircle( black, blue, raya );
  draw rp(aphip)--rp(-aphip);
  draw rp(aphiv)--rp(-aphiv);
  draw rp(majbv)--rp(-majbv);
  draw ell;
endfig;

beginfig(3); %%%%%%%%%%%%%%%% don't change the parameters... %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% and forget this (it is wrong). %%%%%%%%%%%%  
  f := (6,4,7);
  Spread := 125;
  numeric maja, raya, angphi, angthe, pes, decl;
  numeric valy, valz, begp, endp, rectsiz;
  color majav, aphiv, aphip, majbv, majcv, perpv, perqv;
  path ell, fll, cir;
  maja = 0.82;
  raya = 0.5;
  angphi = 17;
  angthe = 82;
  pes = 1.3pt;
  begp = 14;
  endp = 18;
  rectsiz = 0.08;
  drawoptions( withpen pencircle scaled pes );
  majav = (0,0,maja);
  aphiv = raya*(cosd(angphi),sind(angphi),0);
  aphip = raya*(sind(angphi),-cosd(angphi),0);
  majbv = planarrotation( majav, aphip, angthe );
  majcv = planarrotation( majav, -aphip, angthe );
  perpv = ncrossprod(majbv,aphiv);
  decl = Z(perpv)/(Y(perpv)++X(perpv));
  valy = maja*raya/((decl*raya)++maja);
  valz = valy*decl;
  if angthe>90: valy:=-valy; fi;
  perpv := blue*valz-N(aphip)*valy;
  perqv = (-X(perpv),-Y(perpv),Z(perpv));
  spheroid( black, majav, raya );
  squareangline( -majbv, perpv, black, rectsiz);
  squareangline( -majcv, perqv, black, rectsiz);
  drawoptions( withpen pencircle scaled 1.095pes );
  cir = spatialhalfcircle(black, majav, raya, true );
  undraw subpath (0,0.9*(length cir)) of cir;
  ell = ellipticpath( black, majbv, aphiv );
  fll = ellipticpath( black, majcv, aphiv );
  drawoptions( withpen pencircle scaled pes dashed (withdots scaled 0.42) );
  draw ellipticpath( black, majav, aphip );
  draw rp(aphiv)--rp(-aphiv);
  draw rp(majbv)--rp(-majbv);
  draw rp(majcv)--rp(-majcv);
  drawoptions( withpen pencircle scaled 2pes );
  draw subpath (begp,endp) of fll withcolor blue;
  draw ell withcolor red;
  draw subpath (endp-36, begp) of fll withcolor blue;
  drawarrow rp(black)--rp(perpv) withcolor red;
  drawarrow rp(black)--rp(perqv) withcolor blue;
endfig;

beginfig(4);
  f := (6,4,7);
  Spread := 40;
  numeric axa, axb, axc;
  color d[];
  axa = 2.618;
  axb = 1.618;
  axc = 1.0;
  d1 = (axa,0,0);
  d2 = (0,axb,0);
  d3 = (0,0,axc);
  draw ellipticpath(black,d1,d2);
  draw ellipticpath(black,d1,d3);
  draw ellipticpath(black,d2,d3);
  drawarrow rp(black)--rp(d1);
  drawarrow rp(black)--rp(d2);
  drawarrow rp(black)--rp(d3);
  draw ellipsoid(black,d1,d2,d3) withpen pencircle scaled 2.5pt withcolor blue;
endfig;

beginfig(5);
  f := (4,3,6.5);
  Spread := 100;
  numeric axa, axb, axc, vz, vy;
  color va, vb, d[];
  axa = 0.505;
  axb = 0.495;
  axc = 0.82;
  d1 = (axa,0,0);
  d2 = (0,axb,0);
  d3 = (0,0,axc);
  vy = axb*(axc+-+axa)/(axc+-+axb);
  vz = axa+-+vy;
  va = (0,vy,vz);
  vb = (0,-vy,vz);
  drawarrow rp(black)--rp(d2);
  draw ellipticpath(black,d1,va) withcolor red;
  draw ellipticpath(black,d1,vb) withcolor green;
  draw ellipticpath(black,d2,d3) dashed withdots scaled 0.333;
  draw rp(black)--rp(-d1) dashed withdots scaled 0.333;
  drawarrow rp(black)--rp(va) withcolor red;
  drawarrow rp(black)--rp(vb) withcolor green;
  draw rp(black)--rp(-va) dashed withdots scaled 0.333 withcolor red;
  draw rp(black)--rp(-vb) dashed withdots scaled 0.333 withcolor green;
  draw ellipsoid(black,d1,d2,d3) withpen pencircle scaled 2pt withcolor blue;
  drawarrow rp(black)--rp(d3);
  drawarrow rp(black)--rp(d1);
  draw subpath (0,9) of ellipticpath(black,d1,d2);
  draw subpath (0,9) of ellipticpath(black,d1,d3);
  draw subpath (0,9) of ellipticpath(black,d2,d3);
  labeloffset := 1pt;
  label.lrt(btex $n_\alpha$ etex,rp(d2));
  label.bot(btex $n_\beta$ etex,rp(d1));
  label.top(btex $n_\gamma$ etex,rp(d3));
  label.rt(btex $n_\beta$ etex,rp(va));
  label.bot(btex $n_\beta$ etex,rp(vb));
  color perpv, perqv;
  numeric decl, valy, valz, fact;
  fact = 1.55;
  perpv = ncrossprod(d1,va);
  decl = Z(perpv)/Y(perpv);
  valy = axc*axb/((decl*axb)++axc);
  valz = -valy*decl;
  perpv := blue*valz-green*valy;
  perqv := blue*valz+green*valy;
  drawarrow rp(black)--rp(fact*perpv) withcolor red;
  drawarrow rp(black)--rp(fact*perqv) withcolor green;
  draw rp(perpv) withpen pencircle scaled 2pt withcolor red;
  draw rp(perqv) withpen pencircle scaled 2pt withcolor green;
  label.lft(btex OA etex,rp(fact*perpv));
  label.rt(btex OA etex,rp(fact*perqv));
endfig;


verbatimtex \end{document} etex

end;

