--- ray/src/common/fvect.c 1989/10/17 13:35:30 1.4 +++ ray/src/common/fvect.c 1992/10/02 16:02:43 2.2 @@ -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; @@ -115,4 +114,26 @@ 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; +{ + 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; }