--- ray/src/common/fvect.c 1989/05/07 21:41:40 1.2 +++ ray/src/common/fvect.c 1991/04/02 15:27:44 1.6 @@ -83,6 +83,16 @@ register FVECT vres, v1, v2; } +fvsum(vres, v0, v1, f) /* vres = v0 + f*v1 */ +FVECT vres, v0, v1; +double f; +{ + vres[0] = v0[0] + f*v1[0]; + vres[1] = v0[1] + f*v1[1]; + vres[2] = v0[2] + f*v1[2]; +} + + double normalize(v) /* normalize a vector, return old magnitude */ register FVECT v; @@ -91,7 +101,7 @@ register FVECT v; len = DOT(v, v); - if (len <= FTINY*FTINY) + if (len <= 0.0) return(0.0); /****** problematic @@ -105,4 +115,27 @@ register FVECT v; v[1] /= len; v[2] /= len; return(len); +} + + +spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ +FVECT vres, vorig, vnorm; +double theta; +{ + extern double cos(), sin(); + double sint, cost, normprod; + FVECT vperp; + register int i; + + if (theta == 0.0) { + if (vres != vorig) + VCOPY(vres, vorig); + return; + } + cost = cos(theta); + sint = sin(theta); + normprod = DOT(vorig, vnorm)*(1.-cost); + fcross(vperp, vnorm, vorig); + for (i = 0; i < 3; i++) + vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint; }