1/*
2    Copyright 2010 by Mark Weyer
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17*/
18
19
20#include "mdEgo.inc"
21
22#declare maxanz = 100000;
23#declare pos = array[maxanz];
24#declare norm = array[maxanz];
25#declare anz = 0;
26#declare koerper=Koerper(0);
27#declare s=seed(234687);
28#declare haar_laenge = 0.07;
29#declare minabstand = Haardicke;
30
31#declare i=0;
32#while (i<maxanz)
33  #declare p=<rand(s)-0.5,rand(s)*0.8,rand(s)-0.5>;
34  #if (inside(koerper,p))
35    // Schneller Vortest, um möglichst viele schon früh rauszuwerfen
36    #declare abstand=100;
37    #declare j=0;
38    #while (j<anz)
39      #declare abstand_ = vlength(p-pos[j]);
40      #if (abstand_ < abstand) #declare abstand=abstand_; #end
41      #declare j=j+1;
42      #if (abstand<minabstand) #declare j=anz; #end
43    #end
44    #if (abstand>=minabstand)
45      #declare hitnorm=<0,0,0>;
46      #declare abstand=100;
47      #declare j=0;
48      #while (j<1000)
49        #declare h=rand(s)*2-1;
50        #declare phi=rand(s)*2*pi;
51        #declare dir=<sqrt(1-h*h)*cos(phi),sqrt(1-h*h)*sin(phi),h>;
52        #declare hit=trace(koerper,p,dir,hitnorm);
53        #declare d=vlength(hit-p);
54        #if (d<abstand & vlength(hitnorm)>0)
55          #declare abstand=d;
56          #declare pos[anz]=hit;
57          #declare norm[anz]=dir;
58        #end
59        #declare j=j+1;
60      #end
61      #if (abstand<100)
62        #declare abstand=100;
63        #declare j=0;
64        #while (j<anz)
65          #declare abstand_ = vlength(pos[anz]-pos[j]);
66          #if (abstand_ < abstand) #declare abstand=abstand_; #end
67          #declare j=j+1;
68          #if (abstand<minabstand) #declare j=anz; #end
69        #end
70        #if (abstand>=minabstand) #declare anz=anz+1; #end
71      #end
72    #end
73  #end
74  #declare i=i+1;
75#end
76
77#fopen raus "mdEgoHaare.data" write
78#declare i=0;
79#while (i<anz)
80  #write(raus, pos[i])
81  #write(raus, ", ")
82  #write(raus, norm[i])
83  #write(raus, ",\n")
84  #declare i=i+1;
85#end
86#fclose raus
87
88