ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fvect.c
(Generate patch)

Comparing ray/src/common/fvect.c (file contents):
Revision 2.16 by greg, Thu Nov 8 00:31:17 2012 UTC vs.
Revision 2.20 by greg, Thu Dec 4 05:26:27 2014 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
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
# Line 29 | Line 50 | const FVECT p2
50   {
51          FVECT  delta;
52  
53 <        delta[0] = p2[0] - p1[0];
33 <        delta[1] = p2[1] - p1[1];
34 <        delta[2] = p2[2] - p1[2];
53 >        VSUB(delta, p2, p1);
54  
55          return(DOT(delta, delta));
56   }
# Line 87 | Line 106 | const FVECT v1,
106   const FVECT v2
107   )
108   {
109 <        vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
91 <        vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
92 <        vres[2] = v1[0]*v2[1] - v1[1]*v2[0];
109 >        VCROSS(vres, v1, v2);
110   }
111  
112  
# Line 101 | Line 118 | const FVECT v1,
118   double f
119   )
120   {
121 <        vres[0] = v0[0] + f*v1[0];
105 <        vres[1] = v0[1] + f*v1[1];
106 <        vres[2] = v0[2] + f*v1[2];
121 >        VSUM(vres, v0, v1, f);
122   }
123  
124  
# Line 135 | Line 150 | FVECT  v
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 */
176   RREAL t[2],             /* returned distances along each ray */
177   const FVECT rorg0,              /* first origin */
# Line 180 | Line 217 | double theta           /* right-hand radians */
217          cost = cos(theta);
218          sint = sin(theta);
219          normprod = DOT(vorig, vnorm)*(1.-cost);
220 <        fcross(vperp, vnorm, vorig);
220 >        VCROSS(vperp, vnorm, vorig);
221          for (i = 0; i < 3; i++)
222                  vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint;
223   }
# Line 195 | Line 232 | int meas               /* distance measure (radians, absolute, rela
232   )
233   {
234          FVECT   normtarg;
235 <        double  volen, dotprod, sint, cost;
235 >        double  volen, dotprod, sintr, cost;
236          int     i;
237  
238          VCOPY(normtarg, vtarg);         /* in case vtarg==vres */
# Line 222 | Line 259 | int meas               /* distance measure (radians, absolute, rela
259          else if (meas == GEOD_REL)
260                  t *= acos(dotprod);
261          cost = cos(t);
262 <        sint = sin(t);
262 >        sintr = sin(t) / sqrt(1. - dotprod*dotprod);
263          for (i = 0; i < 3; i++)
264                  vres[i] = volen*( cost*vres[i] +
265 <                                  sint*(normtarg[i] - dotprod*vres[i]) );
265 >                                  sintr*(normtarg[i] - dotprod*vres[i]) );
266  
267          return(volen);                  /* return vector length */
268   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines