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 1.5 by greg, Tue Mar 19 13:14:19 1991 UTC vs.
Revision 2.3 by greg, Fri Dec 10 09:53:30 1993 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     8/14/85
11   */
12  
13 + #include  <math.h>
14   #include  "fvect.h"
15  
15 #define  FTINY          1e-7
16  
17
17   double
18   fdot(v1, v2)                    /* return the dot product of two vectors */
19   register FVECT  v1, v2;
# Line 104 | Line 103 | register FVECT  v;
103          if (len <= 0.0)
104                  return(0.0);
105          
106 <        /****** problematic
107 <        if (len >= (1.0-FTINY)*(1.0-FTINY) &&
108 <                        len <= (1.0+FTINY)*(1.0+FTINY))
109 <                return(1.0);
111 <        ******/
106 >        if (len <= 1.0+FTINY && len >= 1.0-FTINY)
107 >                len = 0.5 + 0.5*len;    /* first order approximation */
108 >        else
109 >                len = sqrt(len);
110  
113        len = sqrt(len);
111          v[0] /= len;
112          v[1] /= len;
113          v[2] /= len;
114 +
115          return(len);
116   }
117  
# Line 122 | Line 120 | spinvector(vres, vorig, vnorm, theta)  /* rotate vector
120   FVECT  vres, vorig, vnorm;
121   double  theta;
122   {
123 <        extern double  sin(), cos();
126 <        double  sint, cost, dotp;
123 >        double  sint, cost, normprod;
124          FVECT  vperp;
125          register int  i;
126          
127          if (theta == 0.0) {
128 <                VCOPY(vres, vorig);
128 >                if (vres != vorig)
129 >                        VCOPY(vres, vorig);
130                  return;
131          }
134        sint = sin(theta);
132          cost = cos(theta);
133 <        dotp = DOT(vorig, vnorm);
133 >        sint = sin(theta);
134 >        normprod = DOT(vorig, vnorm)*(1.-cost);
135          fcross(vperp, vnorm, vorig);
136          for (i = 0; i < 3; i++)
137 <                vres[i] = vnorm[i]*dotp*(1.-cost) +
140 <                                vorig[i]*cost + vperp[i]*sint;
137 >                vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint;
138   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines