7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
+ |
#define _USE_MATH_DEFINES |
11 |
|
#include <math.h> |
12 |
|
#include "fvect.h" |
13 |
+ |
#include "random.h" |
14 |
|
|
15 |
+ |
double |
16 |
+ |
Acos(double x) /* insurance for touchy math library */ |
17 |
+ |
{ |
18 |
+ |
if (x <= -1.+FTINY*FTINY) |
19 |
+ |
return(M_PI); |
20 |
+ |
if (x >= 1.-FTINY*FTINY) |
21 |
+ |
return(.0); |
22 |
+ |
return(acos(x)); |
23 |
+ |
} |
24 |
|
|
25 |
|
double |
26 |
+ |
Asin(double x) /* insurance for touchy math library */ |
27 |
+ |
{ |
28 |
+ |
if (x <= -1.+FTINY*FTINY) |
29 |
+ |
return(-M_PI/2.); |
30 |
+ |
if (x >= 1.-FTINY*FTINY) |
31 |
+ |
return(M_PI/2); |
32 |
+ |
return(asin(x)); |
33 |
+ |
} |
34 |
+ |
|
35 |
+ |
double |
36 |
|
fdot( /* return the dot product of two vectors */ |
37 |
|
const FVECT v1, |
38 |
|
const FVECT v2 |
148 |
|
return(len); |
149 |
|
} |
150 |
|
|
151 |
+ |
|
152 |
+ |
int |
153 |
+ |
getperpendicular( /* choose random perpedicular direction */ |
154 |
+ |
FVECT vp, /* returns normalized */ |
155 |
+ |
const FVECT v /* input vector must be normalized */ |
156 |
+ |
) |
157 |
+ |
{ |
158 |
+ |
FVECT v1; |
159 |
+ |
int i; |
160 |
+ |
/* randomize other coordinates */ |
161 |
+ |
v1[0] = 0.5 - frandom(); |
162 |
+ |
v1[1] = 0.5 - frandom(); |
163 |
+ |
v1[2] = 0.5 - frandom(); |
164 |
+ |
for (i = 3; i--; ) |
165 |
+ |
if ((-0.6 < v[i]) & (v[i] < 0.6)) |
166 |
+ |
break; |
167 |
+ |
if (i < 0) |
168 |
+ |
return(0); |
169 |
+ |
v1[i] = 1.0; |
170 |
+ |
VCROSS(vp, v1, v); |
171 |
+ |
return(normalize(vp) > 0.0); |
172 |
+ |
} |
173 |
|
|
174 |
|
int |
175 |
|
closestapproach( /* closest approach of two rays */ |