Debian Codegraph @

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

raw
1 % solarconcentrator.mp
2 % L. Nobre G.
3 % 2013
4
5 prologues := 1;
6
7 input featpost3Dplus2D;
8
9 color actpoi, actdir, actperp;
10 boolean finish;
11
12 %def findintersection( expr SourcePoi, RayDir ) =
13 % begingroup
14 %
15 % endgroup
16 %enddef;
17
18 vardef reflectrayr(expr sourcepoi, raydir )=
19 save J, Perp, newdir, cropro, tandir, theangle;
20 color J, Perp, newdir, cropro, tandir;
21 numeric theangle;
22 findintersection( sourcepoi, raydir );
23 if not finish:
24 draw rp(sourcepoi)--rp(actpoi);
25 theangle = 180-getangle( raydir, actperp );
26 if theangle<0.5: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DANGER!
27 cropro = ncrossprod( raydir, actperp );
28 tandir = ncrossprod( actperp, cropro );
29 newdir = planarrotation( actperp, tandir, theangle );
30 else:
31 newdir = actperp;
32 fi;
33 reflectrayr( actpoi, newdir );
34 else:
35 J=sourcepoi+raydir;
36 drawarrow rp(sourcepoi)--rp(J);
37 finish := false;
38 fi;
39 enddef;
40
41 beginfig(1);
42 f := (6,4,5);
43 numeric iz, jang, numcircs, zcoord;
44 numcircs = 10;
45 draw rp((1,0,1))--rp(red)--rp(-red)--rp((-1,0,1));
46 for iz=1 upto numcircs:
47 zcoord := iz/numcircs;
48 draw
49 rp((1-zcoord,zcoord,zcoord))--rp((zcoord-1,zcoord,zcoord))..
50 for jang=5 step 5 until 175:
51 rp((zcoord-1-zcoord*sind(jang),zcoord*cosd(jang),zcoord))..
52 endfor
53 rp((zcoord-1,-zcoord,zcoord))--rp((1-zcoord,-zcoord,zcoord))..
54 for jang=5 step 5 until 175:
55 rp((1-zcoord+zcoord*sind(jang),-zcoord*cosd(jang),zcoord))..
56 endfor
57 cycle;
58 endfor;
59 draw rp(red)--rp((0,1,1))--rp(-red)--rp((0,-1,1))--cycle;
60 endfig;
61
62
63
64 end.