--- ray/src/common/fvect.c 2013/06/29 21:03:44 2.19 +++ ray/src/common/fvect.c 2014/12/04 05:26:27 2.20 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: fvect.c,v 2.19 2013/06/29 21:03:44 greg Exp $"; +static const char RCSid[] = "$Id: fvect.c,v 2.20 2014/12/04 05:26:27 greg Exp $"; #endif /* * fvect.c - routines for floating-point vector calculations @@ -10,6 +10,7 @@ static const char RCSid[] = "$Id: fvect.c,v 2.19 2013/ #define _USE_MATH_DEFINES #include #include "fvect.h" +#include "random.h" double Acos(double x) /* insurance for touchy math library */ @@ -147,6 +148,28 @@ FVECT v return(len); } + +int +getperpendicular( /* choose random perpedicular direction */ + FVECT vp, /* returns normalized */ + const FVECT v /* input vector must be normalized */ +) +{ + FVECT v1; + int i; + /* randomize other coordinates */ + v1[0] = 0.5 - frandom(); + v1[1] = 0.5 - frandom(); + v1[2] = 0.5 - frandom(); + for (i = 3; i--; ) + if ((-0.6 < v[i]) & (v[i] < 0.6)) + break; + if (i < 0) + return(0); + v1[i] = 1.0; + VCROSS(vp, v1, v); + return(normalize(vp) > 0.0); +} int closestapproach( /* closest approach of two rays */