#ifndef RIGEOMETRY_H #define RIGEOMETRY_H #ifndef RIVECTOR3_H #include #endif /************************************************************ * geometry class declaration ************************************************************/ /*************************************************************** CLASS RiGeometry Handles general geometric queries on RiVector3 and RiVector2 DESCRIPTION Class to hold all support functions for geometry (ie RiVector3 and RiVector2). All checks for coplanarity, colinearity, non-exact RiVector3 equality, and other general queries that shouldn't clutter up RiVector3 and RiVector2 belong here. ****************************************************************/ class RiGeometry { public: //// Return the index [0-2] for the minimum element of the absolute value of the vector static int IndexOfMinAbsComponent( const RiVector3& v ); //// Return the index [0-2] for the maximum element of the absolute value of the vector static int IndexOfMaxAbsComponent( const RiVector3& v ); //// Return a vector perpendicular to the given vector. static RiVector3 PerpendicularVector(const RiVector3 &v); //// Return the angle between two RiVectors in radians static RiReal AngleBetweenVectors(const RiVector3& v1, const RiVector3& v2); //// returns reflection of a with respect to n static RiVector3 Reflect( const RiVector3& a, const RiVector3& n ); //// returns unit reflection of unit a with respect to unit n static RiUnitVector3 UnitReflect( const RiUnitVector3& a, const RiUnitVector3& n ); //// returns unit vector v in direction (theta, phi), // where theta is angle in radians between v and z-axis, // and phi is the azimuthal angle relative to x-axis static RiUnitVector3 DirectionFromSphericalCoordinates( RiReal theta, RiReal phi ); private: RiGeometry(); }; inline int RiGeometry::IndexOfMinAbsComponent( const RiVector3& v ) { RiReal x = fabs(v[0]); RiReal y = fabs(v[1]); RiReal z = fabs(v[2]); if (x < y && x < z) return 0; else if (y < z) return 1; else return 2; } inline int RiGeometry::IndexOfMaxAbsComponent( const RiVector3& v ) { if (fabs(v[0]) > fabs(v[1]) && fabs(v[0]) > fabs(v[2])) return 0; else if (fabs(v[1]) > fabs(v[2])) return 1; else return 2; } #endif // RIGEOMETRY_H