summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/featpost/example/solarconcentrator.mp
blob: af05771602fef5a80e58b27512d546e8bd3ce154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
% solarconcentrator.mp
% L. Nobre G.
% 2013

prologues := 1;

input featpost3Dplus2D;

color actpoi, actdir, actperp;
boolean finish;

%def findintersection( expr SourcePoi, RayDir ) =
%  begingroup
%    
%  endgroup
%enddef;

vardef reflectrayr(expr sourcepoi, raydir )=
  save J, Perp, newdir, cropro, tandir, theangle;
  color J, Perp, newdir, cropro, tandir;
  numeric theangle;
  findintersection( sourcepoi, raydir );
  if not finish:
    draw rp(sourcepoi)--rp(actpoi);
    theangle = 180-getangle( raydir, actperp );
    if theangle<0.5: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DANGER!
      cropro = ncrossprod( raydir, actperp );
      tandir = ncrossprod( actperp, cropro );
      newdir = planarrotation( actperp, tandir, theangle );
    else:
      newdir = actperp;
    fi;
    reflectrayr( actpoi, newdir );
  else:
    J=sourcepoi+raydir;
    drawarrow rp(sourcepoi)--rp(J);
    finish := false;
  fi;
enddef;

beginfig(1);
  f := (6,4,5);
  numeric iz, jang, numcircs, zcoord;
  numcircs = 10;
  draw rp((1,0,1))--rp(red)--rp(-red)--rp((-1,0,1));
  for iz=1 upto numcircs:
    zcoord := iz/numcircs;
    draw
      rp((1-zcoord,zcoord,zcoord))--rp((zcoord-1,zcoord,zcoord))..
      for jang=5 step 5 until 175:
      rp((zcoord-1-zcoord*sind(jang),zcoord*cosd(jang),zcoord))..
      endfor
      rp((zcoord-1,-zcoord,zcoord))--rp((1-zcoord,-zcoord,zcoord))..
      for jang=5 step 5 until 175:
      rp((1-zcoord+zcoord*sind(jang),-zcoord*cosd(jang),zcoord))..
      endfor
      cycle;
  endfor;
  draw rp(red)--rp((0,1,1))--rp(-red)--rp((0,-1,1))--cycle;    
endfig;



end.