--- ray/src/common/fvect.c 1991/03/19 13:14:19 1.5 +++ ray/src/common/fvect.c 1993/12/10 09:53:30 2.3 @@ -10,11 +10,10 @@ static char SCCSid[] = "$SunId$ LBL"; * 8/14/85 */ +#include #include "fvect.h" -#define FTINY 1e-7 - double fdot(v1, v2) /* return the dot product of two vectors */ register FVECT v1, v2; @@ -104,16 +103,15 @@ register FVECT v; if (len <= 0.0) return(0.0); - /****** problematic - if (len >= (1.0-FTINY)*(1.0-FTINY) && - len <= (1.0+FTINY)*(1.0+FTINY)) - return(1.0); - ******/ + if (len <= 1.0+FTINY && len >= 1.0-FTINY) + len = 0.5 + 0.5*len; /* first order approximation */ + else + len = sqrt(len); - len = sqrt(len); v[0] /= len; v[1] /= len; v[2] /= len; + return(len); } @@ -122,20 +120,19 @@ spinvector(vres, vorig, vnorm, theta) /* rotate vector FVECT vres, vorig, vnorm; double theta; { - extern double sin(), cos(); - double sint, cost, dotp; + double sint, cost, normprod; FVECT vperp; register int i; if (theta == 0.0) { - VCOPY(vres, vorig); + if (vres != vorig) + VCOPY(vres, vorig); return; } - sint = sin(theta); cost = cos(theta); - dotp = DOT(vorig, vnorm); + sint = sin(theta); + normprod = DOT(vorig, vnorm)*(1.-cost); fcross(vperp, vnorm, vorig); for (i = 0; i < 3; i++) - vres[i] = vnorm[i]*dotp*(1.-cost) + - vorig[i]*cost + vperp[i]*sint; + vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint; }