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.19 by greg, Sat Jun 29 21:03:44 2013 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  
14 + double
15 + Acos(double x)                  /* insurance for touchy math library */
16 + {
17 +        if (x <= -1.+FTINY*FTINY)
18 +                return(M_PI);
19 +        if (x >= 1.-FTINY*FTINY)
20 +                return(.0);
21 +        return(acos(x));
22 + }
23  
24   double
25 + Asin(double x)                  /* insurance for touchy math library */
26 + {
27 +        if (x <= -1.+FTINY*FTINY)
28 +                return(-M_PI/2.);
29 +        if (x >= 1.-FTINY*FTINY)
30 +                return(M_PI/2);
31 +        return(asin(x));
32 + }
33 +
34 + double
35   fdot(                           /* return the dot product of two vectors */
36   const FVECT v1,
37   const FVECT v2
# Line 29 | Line 49 | const FVECT p2
49   {
50          FVECT  delta;
51  
52 <        delta[0] = p2[0] - p1[0];
33 <        delta[1] = p2[1] - p1[1];
34 <        delta[2] = p2[2] - p1[2];
52 >        VSUB(delta, p2, p1);
53  
54          return(DOT(delta, delta));
55   }
# Line 87 | Line 105 | const FVECT v1,
105   const FVECT v2
106   )
107   {
108 <        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];
108 >        VCROSS(vres, v1, v2);
109   }
110  
111  
# Line 101 | Line 117 | const FVECT v1,
117   double f
118   )
119   {
120 <        vres[0] = v0[0] + f*v1[0];
105 <        vres[1] = v0[1] + f*v1[1];
106 <        vres[2] = v0[2] + f*v1[2];
120 >        VSUM(vres, v0, v1, f);
121   }
122  
123  
# Line 180 | Line 194 | double theta           /* right-hand radians */
194          cost = cos(theta);
195          sint = sin(theta);
196          normprod = DOT(vorig, vnorm)*(1.-cost);
197 <        fcross(vperp, vnorm, vorig);
197 >        VCROSS(vperp, vnorm, vorig);
198          for (i = 0; i < 3; i++)
199                  vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint;
200   }
# Line 195 | Line 209 | int meas               /* distance measure (radians, absolute, rela
209   )
210   {
211          FVECT   normtarg;
212 <        double  volen, dotprod, sint, cost;
212 >        double  volen, dotprod, sintr, cost;
213          int     i;
214  
215          VCOPY(normtarg, vtarg);         /* in case vtarg==vres */
# Line 222 | Line 236 | int meas               /* distance measure (radians, absolute, rela
236          else if (meas == GEOD_REL)
237                  t *= acos(dotprod);
238          cost = cos(t);
239 <        sint = sin(t);
239 >        sintr = sin(t) / sqrt(1. - dotprod*dotprod);
240          for (i = 0; i < 3; i++)
241                  vres[i] = volen*( cost*vres[i] +
242 <                                  sint*(normtarg[i] - dotprod*vres[i]) );
242 >                                  sintr*(normtarg[i] - dotprod*vres[i]) );
243  
244          return(volen);                  /* return vector length */
245   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines