% fallinthewind.mp
% L. Nobre G.
% 2007

input featpost3Dplus2D;

Spread := 40;
%f := 0.5[0.3*(15,10,5),0.3*(1.5,1,15)];
f := 1.5*(2.5,1.7,1.5);
viewcentr := (0,0,0.96);
%show f;

prologues := 1;

color referencewind;
numeric dragcoeff, horangle, quadcoef;
horangle = 90;
referencewind = red*cosd( horangle ) + green*sind( horangle );
dragcoef = 0.045;
quadcoef = 0.99;

def vecfunc( expr posit, veloc )=
  begingroup
    save heig, wind, field, wint, blow;
    color wind, field, blow;
    numeric heig, wint;
    heig = Z( posit );
    wind = referencewind*quadcoef*(( heig+0.0001 )**2);
    wind := wind-veloc;
    wint = conorm( wind );
    blow = N( wind );
    field = dragcoef*blow*wint-blue;
    ( field )
  endgroup
enddef;

beginfig(1);
  numeric i, numa, sa, ea, diffstep, ray;
  color stp, svl, arrbe, arren;
  path oneline;
  pen grossa, fina;
  arrbe = (0,-5,1);
  arren = (0,-3,1);
  TDAtiplen := 0.5;      
  TDAhalftipbase := 0.2; 
  TDAhalfthick := 0.1;        
  grossa = pencircle scaled 3pt; 
  fina = pencircle scaled 2pt; 
  diffstep = 0.03;
  ray = 2.2;
%   numa = 0.02;
%   sa = 106.4;
%   ea = 106.6;
  numa = 2;
  sa = 80.5;
  ea = 130.5;
  setthestage( 20, 10 );
  for i=sa step numa until ea:
    stp := black;
    svl := ray*(green*cosd(i)+blue*sind(i));
    oneline := dragtrajectorypath( stp, svl, diffstep, vecfunc );
    draw oneline;
%    draw oneline withpen fina withcolor background;
  endfor;
  tdarrow( arrbe, arren );
  produce_vga_border;
endfig;

ray := 3.25;
numeric min, rst;
min = 0.5;
rst = 0.1;
for i=min step rst until ray:
    %show i;
  numeric xa, xb, xc, fa, fb, fc;
  xa = 85;
  svl := i*(green*cosd(xa)+blue*sind(xa));
  oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
  fa = PrintStep; 
  xb = 89;
  svl := i*(green*cosd(xb)+blue*sind(xb));  
  oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
  fb = PrintStep;
  xc = 0;
  forever:
    exitif ( abs( fb - fa ) < 0.005 );
    xc := xb - fb*(xb-xa)/(fb-fa);
    svl := i*(green*cosd(xc)+blue*sind(xc));  
    oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
    fc := PrintStep;
    exitif ( abs( fc - fa ) < 0.0005 );
    xa := xb;
    fa := fb;
    xb := xc;
    fb := fc;
  endfor;
  message decimal( i ) & "   " & decimal( xc );
endfor;
message " ";

end.

