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.13 by greg, Fri Feb 18 00:40:25 2011 UTC vs.
Revision 2.18 by greg, Wed Apr 3 00:22:12 2013 UTC

# Line 29 | Line 29 | const FVECT p2
29   {
30          FVECT  delta;
31  
32 <        delta[0] = p2[0] - p1[0];
33 <        delta[1] = p2[1] - p1[1];
34 <        delta[2] = p2[2] - p1[2];
32 >        VSUB(delta, p2, p1);
33  
34          return(DOT(delta, delta));
35   }
# Line 87 | Line 85 | const FVECT v1,
85   const FVECT v2
86   )
87   {
88 <        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];
88 >        VCROSS(vres, v1, v2);
89   }
90  
91  
# Line 101 | Line 97 | const FVECT v1,
97   double f
98   )
99   {
100 <        vres[0] = v0[0] + f*v1[0];
105 <        vres[1] = v0[1] + f*v1[1];
106 <        vres[2] = v0[2] + f*v1[2];
100 >        VSUM(vres, v0, v1, f);
101   }
102  
103  
# Line 119 | Line 113 | FVECT  v
113          if (d == 0.0)
114                  return(0.0);
115          
116 <        if (d <= 1.0+FTINY && d >= 1.0-FTINY) {
116 >        if ((d <= 1.0+FTINY) & (d >= 1.0-FTINY)) {
117                  len = 0.5 + 0.5*d;      /* first order approximation */
118                  d = 2.0 - len;
119          } else {
# Line 162 | Line 156 | const FVECT rdir1              /* second direction (normalized) */
156  
157   void
158   spinvector(                             /* rotate vector around normal */
159 < FVECT vres,             /* returned vector */
159 > FVECT vres,             /* returned vector (same magnitude as vorig) */
160   const FVECT vorig,              /* original vector */
161   const FVECT vnorm,              /* normalized vector for rotation */
162 < double theta            /* left-hand radians */
162 > double theta            /* right-hand radians */
163   )
164   {
165          double  sint, cost, normprod;
# Line 180 | Line 174 | double theta           /* left-hand radians */
174          cost = cos(theta);
175          sint = sin(theta);
176          normprod = DOT(vorig, vnorm)*(1.-cost);
177 <        fcross(vperp, vnorm, vorig);
177 >        VCROSS(vperp, vnorm, vorig);
178          for (i = 0; i < 3; i++)
179                  vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint;
180 + }
181 +
182 + double
183 + geodesic(               /* rotate vector on great circle towards target */
184 + FVECT vres,             /* returned vector (same magnitude as vorig) */
185 + const FVECT vorig,      /* original vector */
186 + const FVECT vtarg,      /* vector we are rotating towards */
187 + double t,               /* amount along arc directed towards vtarg */
188 + int meas                /* distance measure (radians, absolute, relative) */
189 + )
190 + {
191 +        FVECT   normtarg;
192 +        double  volen, dotprod, sintr, cost;
193 +        int     i;
194 +
195 +        VCOPY(normtarg, vtarg);         /* in case vtarg==vres */
196 +        if (vres != vorig)
197 +                VCOPY(vres, vorig);
198 +        if (t == 0.0)
199 +                return(VLEN(vres));     /* no rotation requested */
200 +        if ((volen = normalize(vres)) == 0.0)
201 +                return(0.0);
202 +        if (normalize(normtarg) == 0.0)
203 +                return(0.0);            /* target vector is zero */
204 +        dotprod = DOT(vres, normtarg);
205 +                                        /* check for colinear */
206 +        if (dotprod >= 1.0-FTINY*FTINY) {
207 +                if (meas != GEOD_REL)
208 +                        return(0.0);
209 +                vres[0] *= volen; vres[1] *= volen; vres[2] *= volen;
210 +                return(volen);
211 +        }
212 +        if (dotprod <= -1.0+FTINY*FTINY)
213 +                return(0.0);
214 +        if (meas == GEOD_ABS)
215 +                t /= volen;
216 +        else if (meas == GEOD_REL)
217 +                t *= acos(dotprod);
218 +        cost = cos(t);
219 +        sintr = sin(t) / sqrt(1. - dotprod*dotprod);
220 +        for (i = 0; i < 3; i++)
221 +                vres[i] = volen*( cost*vres[i] +
222 +                                  sintr*(normtarg[i] - dotprod*vres[i]) );
223 +
224 +        return(volen);                  /* return vector length */
225   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines