--- ray/src/common/fvect.c 1989/05/08 08:40:56 1.3 +++ ray/src/common/fvect.c 1991/10/23 13:43:15 1.7 @@ -12,9 +12,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "fvect.h" -#define FTINY 1e-7 - double fdot(v1, v2) /* return the dot product of two vectors */ register FVECT v1, v2; @@ -83,6 +81,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; @@ -105,4 +113,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; }