Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/fallinthewind.mp

raw
1 % fallinthewind.mp
2 % L. Nobre G.
3 % 2014
4
5 input featpost3Dplus2D;
6
7 prologues := 1;
8
9 Spread := 9;
10 f := 4.5*(2.5,-1.3,1.7);
11 viewcentr := (0,0,2);
12 background := 0.9white;
13
14 color referencewind;
15 numeric dragcoef, dragcoeg, horangle, quadcoef;
16 horangle = 90;
17 referencewind = red*cosd( horangle ) + green*sind( horangle );
18 dragcoef = 0.065;
19 dragcoeg = 0.009;
20 quadcoef = 0.99;
21
22 def vecfunc( expr posit, veloc )=
23 begingroup
24 save heig, wind, field, wint, blow;
25 color wind, field, blow;
26 numeric heig, wint;
27 heig = Z( posit );
28 wind = referencewind*quadcoef*sqrt( heig+0.05 );
29 wind := wind-veloc;
30 wint = conorm( wind );
31 blow = N( wind );
32 field = (dragcoef+dragcoeg*wint)*wind-blue;
33 ( field )
34 endgroup
35 enddef;
36
37 beginfig(1);
38 numeric i, j, k, numa, sa, ea, diffstep, ray;
39 color stp, svl, arrbe, arren;
40 path oneline[];
41 pen grossa, fina;
42 arrbe = (0,-8,5);
43 arren = (0,-5.5,5);
44 setthestage( 18, 20 );
45 TDAtiplen := 0.75;
46 TDAhalftipbase := 0.3;
47 TDAhalfthick := 0.15;
48 grossa = pencircle scaled 1.8pt;
49 fina = pencircle scaled 1.2pt;
50 diffstep = 0.015;
51 ray = 3.95;
52 numa = 3.45;
53 sa = 38;
54 ea = 142;
55 j = 0;
56 for i=sa step numa until ea:
57 j := j+1;
58 stp := black;
59 svl := ray*(green*cosd(i)+blue*sind(i));
60 oneline[j] := dragtrajectorypath( stp, svl, diffstep, vecfunc );
61 draw oneline[j] withpen grossa withcolor white;
62 endfor;
63 for k=1 upto j:
64 draw oneline[k] withpen fina withcolor red;
65 endfor;
66 tdarrow( arrbe, arren );
67 draw rp(black)--rp((0,0,4.5)) dashed withdots withpen fina withcolor blue;
68 produce_vga_border;
69 endfig;
70
71 end.
72
73 ray := 3.25;
74 numeric min, rst;
75 min = 0.5;
76 rst = 0.1;
77 for i=min step rst until ray:
78 %show i;
79 numeric xa, xb, xc, fa, fb, fc;
80 xa = 85;
81 svl := i*(green*cosd(xa)+blue*sind(xa));
82 oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
83 fa = PrintStep;
84 xb = 89;
85 svl := i*(green*cosd(xb)+blue*sind(xb));
86 oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
87 fb = PrintStep;
88 xc = 0;
89 forever:
90 exitif ( abs( fb - fa ) < 0.005 );
91 xc := xb - fb*(xb-xa)/(fb-fa);
92 svl := i*(green*cosd(xc)+blue*sind(xc));
93 oneline := dragtrajectorypath( black, svl, diffstep, vecfunc );
94 fc := PrintStep;
95 exitif ( abs( fc - fa ) < 0.0005 );
96 xa := xb;
97 fa := fb;
98 xb := xc;
99 fb := fc;
100 endfor;
101 message decimal( i ) & " " & decimal( xc );
102 endfor;
103 message " ";
104
105
106