Length 3 Vector Class - vect Summary Template class vect<> provides logical, arithmetic, and assignment operations, as well as other vector math functions for manipulating vectors consisting of three floating point elements. It is advisable to use the type defines 'vectf' and 'vectd' instead of using vect<> directly. Type Definitions typedef vect vectf typedef vect vectd Defines PI = 3.1415926535897 SMALLNUM = 1.0e-6 BIGNUM = 1.0e6 Global Constants static const int X = 0 static const int Y = 1 static const int Z = 2 Methods - constructors, set, access operator, and dump vect() Initialize to [0,0,0]. vect(scalar s) Initialize to [s,s,s]. vect(scalar x, scalar y, scalar z) Initialize to [x,y,z]. vect(const vect &v) Initialize to v. const vect& set(scalar x, scalar y, scalar z){ Set vector to [x,y,z]. Return vector. scalar& operator[](int i) Return vector element i. void dump(char *append="") Dump [vector] followed by append. Methods - component-wise scalar & vector arithmetic vect operator+(scalar s, const vect &v) vect operator+(scalar s) Return vector s + v or v + s. vect operator-(scalar s, const vect &v) vect operator-(scalar s) Return vector s - v or v - s. vect operator*(scalar s, const vect &v) vect operator*(scalar s) Return vector s * v or v * s. vect operator/(scalar s, const vect &v) vect operator/(scalar s) Return vector s / v or v / s. Methods - component-wise scalar & vector arithmetic assignment const vect& operator =(scalar s) Set vector to [s,s,s] and return it. const vect& operator+=(scalar s) Set vector to v + s and return it. const vect& operator-=(scalar s) Set vector to v - s and return it. const vect& operator*=(scalar s) Set vector to v * s and return it. const vect& operator/=(scalar s) Set vector to v / s and return it. Methods - component-wise vector arithmetic vect operator-() Return vector with components negated. vect operator+(const vect &v) Return v1 + v2. vect operator-(const vect &v) Return v1 - v2. vect operator^(const vect &v) Return v1 ^ v2 (multiply component-wise). vect operator/(const vect &v) Return v1 / v2. Methods - dot product and cross product scalar operator*(const vect &v) Return v1 dot v2. vect operator%(const vect &v) Return v1 cross v2. Methods - vector arithmetic assigment const vect& operator =(const vect &v) Assign vector to v and return vector. const vect& operator+=(const vect &v) Assign vector to v1 + v2 and return vector. const vect& operator-=(const vect &v) Assign vector to v1 - v2 and return vector. const vect& operator^=(const vect &v) Assign vector to v1 ^ v2 and return vector. const vect& operator/=(const vect &v) Assign vector to v1 / v2 and return vector. const vect& operator%=(const vect &v) Assign vector to v1 % v2 and return vector. Methods - relational bool operator==(const vect &v) Return true if v1 equals v2, else return false. bool operator!=(const vect &v) Return true if v1 does not equal v2, else return false. bool operator< (const vect &v) Return true if each element of v1 is less than each respective element of v2, else return false. bool operator<=(const vect &v) Return true if each element of v1 is less than or equal to each respective element of v2, else return false. bool operator> (const vect &v) Return true if each element of v1 is greater than each respective element of v2, else return false. bool operator>=(const vect &v) Return true if each element of v1 is greater than or equal to each respective element of v2, else return false. int parallel(vect B) Return 1 if vector A is parallel to vector B and they point in the same direction. Return -1 if they are parallel but point in opposing directions. Return zero if they are not parallel. Methods void swap(vect &v1, vect &v2) Swap two vectors. vect minimum(const vect &v1, const vect &v2) Return a vector having the minimum X-Y-Z components of the two. vect minimum(vect *v, unsigned long i) Return a vector having the minimum X-Y-Z components of all vectors in an array. vect maximum(const vect &v1, const vect &v2) Return a vector having the maximum X-Y-Z components of the two. vect maximum(vect *v, unsigned long i) Return a vector having the maximum X-Y-Z components of all vectors in an array. vect average(const vect &v1, const vect &v2) Return a vector having the average X-Y-Z components of the two. vect average(vect *v, unsigned long i) Return a vector having the average X-Y-Z components of all vectors in an array. vect abs(const vect &v) Return a vector having the absolute value X-Y-Z components of v. const vect& abs(vect *v){ Set v to its own absolute value and return it. vect sqr(const vect &v) Return a vector consisting of the components of v, squared. const vect& sqr(vect *v){ Square the components of v and return it. scalar M(const vect &v) Return the magnitude of v. scalar Msqr(const vect &v) Return the magnitude of v, squared. vect N(vect v) Return the normal of v. const vect& N(vect *v) Normalize v and return it. scalar D(vect v1, vect v2) Return the distance between two vectors. scalar Dsqr(vect v1, vect v2){ Return the distance between two vectors, squared. scalar angle_between(vect v1, vect v2) Return the angle between two vectors, in degrees. void quat_mult(scalar *dstw, vect *dstv, scalar w0,vect v0,scalar w1,vect v1) Multiply quaternions w0 + v0 and w1 + v1, and store the new quaternion in dstw + dstv. vect rotate(vect v, scalar a, vect axis) Rotate v by "a" degrees about axis. Note: Axis must be normalized.