Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Mathematical Operations: add(...), sub(...), mul(...), div(...), invert(...), dot(...), cross(...)

Implements fundamental mathematical operations such as +, -, *, invert, dot product. More...

Matrix Operations

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & identity (Matrix< DATA_TYPE, ROWS, COLS > &result)
 Make identity matrix out the matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & zero (Matrix< DATA_TYPE, ROWS, COLS > &result)
 zero out the matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & mult (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, INTERNAL > &lhs, const Matrix< DATA_TYPE, INTERNAL, COLS > &rhs)
 matrix multiply. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > operator * (const Matrix< DATA_TYPE, ROWS, INTERNAL > &lhs, const Matrix< DATA_TYPE, INTERNAL, COLS > &rhs)
 matrix * matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & sub (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &lhs, const Matrix< DATA_TYPE, ROWS, COLS > &rhs)
 matrix subtraction (algebraic operation for matrix). More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & add (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &lhs, const Matrix< DATA_TYPE, ROWS, COLS > &rhs)
 matrix addition (algebraic operation for matrix). More...

template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & postMult (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand)
 matrix postmultiply. More...

template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & preMult (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand)
 matrix preMultiply. More...

template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & operator *= (Matrix< DATA_TYPE, SIZE, SIZE > &result, const Matrix< DATA_TYPE, SIZE, SIZE > &operand)
 matrix postmult (operator *=). More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & mult (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &mat, float scalar)
 matrix scalar mult. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & mult (Matrix< DATA_TYPE, ROWS, COLS > &result, DATA_TYPE scalar)
 matrix scalar mult. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & operator *= (Matrix< DATA_TYPE, ROWS, COLS > &result, DATA_TYPE scalar)
 matrix scalar mult (operator *=). More...

template<typename DATA_TYPE, unsigned SIZE> Matrix< DATA_TYPE, SIZE, SIZE > & transpose (Matrix< DATA_TYPE, SIZE, SIZE > &result)
 matrix transpose in place. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & transpose (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, COLS, ROWS > &source)
 matrix transpose from one type to another (i.e. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & invertFull (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &src)
 full matrix inversion. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & invert (Matrix< DATA_TYPE, ROWS, COLS > &result, const Matrix< DATA_TYPE, ROWS, COLS > &src)
 smart matrix inversion. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & invert (Matrix< DATA_TYPE, ROWS, COLS > &result)
 smart matrix inversion (in place) Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through. More...


Plane Operations

template<class DATA_TYPE> DATA_TYPE distance (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt)
 Computes the distance from the plane to the point. More...

template<class DATA_TYPE> PlaneSide whichSide (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt)
 Determines which side of the plane the given point lies. More...

template<class DATA_TYPE> PlaneSide whichSide (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt, const DATA_TYPE &eps)
 Determines which side of the plane the given point lies with the given epsilon tolerance. More...

template<class DATA_TYPE> DATA_TYPE findNearestPt (const Plane< DATA_TYPE > &plane, const Point< DATA_TYPE, 3 > &pt, Point< DATA_TYPE, 3 > &result)
 Finds the point on the plane that is nearest to the given point. More...


Quat Operations

template<typename DATA_TYPE> Quat< DATA_TYPE > & mult (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 product of two quaternions (quaternion product) multiplication of quats is much like multiplication of typical complex numbers. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator * (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 product of two quaternions (quaternion product) Does quaternion multiplication. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator *= (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q2)
 quaternion postmult. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & negate (Quat< DATA_TYPE > &result)
 Vector negation - negate each element in the quaternion vector. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator- (const Quat< DATA_TYPE > &quat)
 Vector negation - (operator-) return a temporary that is the negative of the given quat. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & mult (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q, DATA_TYPE s)
 vector scalar multiplication. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator * (const Quat< DATA_TYPE > &q, DATA_TYPE s)
 vector scalar multiplication. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator *= (Quat< DATA_TYPE > &q, DATA_TYPE s)
 vector scalar multiplication. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & div (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, Quat< DATA_TYPE > q2)
 quotient of two quaternions. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator/ (const Quat< DATA_TYPE > &q1, Quat< DATA_TYPE > q2)
 quotient of two quaternions. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator/= (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q2)
 quotient of two quaternions. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & div (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q, DATA_TYPE s)
 quaternion vector scale. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator/ (const Quat< DATA_TYPE > &q, DATA_TYPE s)
 vector scalar division. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator/= (const Quat< DATA_TYPE > &q, DATA_TYPE s)
 vector scalar division. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & add (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector addition. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator+ (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector addition. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator+= (Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector addition. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & sub (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector subtraction. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > operator- (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector subtraction. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & operator-= (Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector subtraction. More...

template<typename DATA_TYPE> DATA_TYPE dot (const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2)
 vector dot product between two quaternions. More...

template<typename DATA_TYPE> DATA_TYPE lengthSquared (const Quat< DATA_TYPE > &q)
 quaternion "norm" (also known as vector length squared) using this can be faster than using length for some operations... More...

template<typename DATA_TYPE> DATA_TYPE length (const Quat< DATA_TYPE > &q)
 quaternion "absolute" (also known as vector length or magnitude) using this can be faster than using length for some operations... More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & normalize (Quat< DATA_TYPE > &result)
 set self to the normalized quaternion of self. More...

template<typename DATA_TYPE> bool isNormalized (const Quat< DATA_TYPE > &q1, const DATA_TYPE eps=(DATA_TYPE) 0.0001f)
 Determines if the given quaternion is normalized within the given tolerance. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & conj (Quat< DATA_TYPE > &result)
 quaternion complex conjugate. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & invert (Quat< DATA_TYPE > &result)
 quaternion multiplicative inverse. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & exp (Quat< DATA_TYPE > &result)
 complex exponentiation. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & log (Quat< DATA_TYPE > &result)
 complex logarithm. More...

template<typename DATA_TYPE> void squad (Quat< DATA_TYPE > &result, DATA_TYPE t, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2, const Quat< DATA_TYPE > &a, const Quat< DATA_TYPE > &b)
 WARNING: not implemented (do not use). More...

template<typename DATA_TYPE> void meanTangent (Quat< DATA_TYPE > &result, const Quat< DATA_TYPE > &q1, const Quat< DATA_TYPE > &q2, const Quat< DATA_TYPE > &q3)
 WARNING: not implemented (do not use). More...


Triangle Operations

template<class DATA_TYPE> Point< DATA_TYPE, 3 > center (const Tri< DATA_TYPE > &tri)
 Computes the point at the center of the given triangle. More...

template<class DATA_TYPE> Vec< DATA_TYPE, 3 > normal (const Tri< DATA_TYPE > &tri)
 Computes the normal for this triangle. More...


Vector/Point Operations

template<typename DATA_TYPE, unsigned SIZE> Vec< DATA_TYPE, SIZE > operator- (const VecBase< DATA_TYPE, SIZE > &v1)
 Negates v1. More...

template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & operator+= (VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2)
 Adds v2 to v1 and stores the result in v1. More...

template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > operator+ (const VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2)
 Adds v2 to v1 and returns the result. More...

template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & operator-= (VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2)
 Subtracts v2 from v1 and stores the result in v1. More...

template<class DATA_TYPE, unsigned SIZE> Vec< DATA_TYPE, SIZE > operator- (const VecBase< DATA_TYPE, SIZE > &v1, const VecBase< DATA_TYPE, SIZE > &v2)
 Subtracts v2 from v1 and returns the result. More...

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > & operator *= (VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar)
 Multiplies v1 by a scalar value and stores the result in v1. More...

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > operator * (const VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar)
 Multiplies v1 by a scalar value and returns the result. More...

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > operator * (const SCALAR_TYPE &scalar, const VecBase< DATA_TYPE, SIZE > &v1)
 Multiplies v1 by a scalar value and returns the result. More...

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > & operator/= (VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar)
 Divides v1 by a scalar value and stores the result in v1. More...

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE> VecBase< DATA_TYPE, SIZE > operator/ (const VecBase< DATA_TYPE, SIZE > &v1, const SCALAR_TYPE &scalar)
 Divides v1 by a scalar value and returns the result. More...


Vector Operations

template<class DATA_TYPE, unsigned SIZE> DATA_TYPE dot (const Vec< DATA_TYPE, SIZE > &v1, const Vec< DATA_TYPE, SIZE > &v2)
 Computes dot product of v1 and v2 and returns the result. More...

template<class DATA_TYPE, unsigned SIZE> DATA_TYPE length (const Vec< DATA_TYPE, SIZE > &v1)
 Computes the length of the given vector. More...

template<class DATA_TYPE, unsigned SIZE> DATA_TYPE lengthSquared (const Vec< DATA_TYPE, SIZE > &v1)
 Computes the square of the length of the given vector. More...

template<class DATA_TYPE, unsigned SIZE> DATA_TYPE normalize (Vec< DATA_TYPE, SIZE > &v1)
 Normalizes the given vector in place causing it to be of unit length. More...

template<class DATA_TYPE, unsigned SIZE> bool isNormalized (const Vec< DATA_TYPE, SIZE > &v1, const DATA_TYPE eps=(DATA_TYPE) 0.0001)
 Determines if the given vector is normalized within the given tolerance. More...

template<class DATA_TYPE> Vec< DATA_TYPE, 3 > cross (const Vec< DATA_TYPE, 3 > &v1, const Vec< DATA_TYPE, 3 > &v2)
 Computes the cross product between v1 and v2 and returns the result. More...

template<class DATA_TYPE> Vec< DATA_TYPE, 3 > & cross (Vec< DATA_TYPE, 3 > &result, const Vec< DATA_TYPE, 3 > &v1, const Vec< DATA_TYPE, 3 > &v2)
 Computes the cross product between v1 and v2 and stores the result in result. More...

template<class DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & reflect (VecBase< DATA_TYPE, SIZE > &result, const VecBase< DATA_TYPE, SIZE > &vec, const Vec< DATA_TYPE, SIZE > &normal)
 Reflect a vector about a normal. More...


Detailed Description

Implements fundamental mathematical operations such as +, -, *, invert, dot product.


Function Documentation

template<typename DATA_TYPE>
Quat<DATA_TYPE>& add Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector addition.

See also:
Quat

Definition at line 256 of file QuatOps.h.

00257    {
00258       result[0] = q1[0] + q2[0];
00259       result[1] = q1[1] + q2[1];
00260       result[2] = q1[2] + q2[2];
00261       result[3] = q1[3] + q2[3];
00262       return result;
00263    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& add Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    lhs,
const Matrix< DATA_TYPE, ROWS, COLS > &    rhs
[inline]
 

matrix addition (algebraic operation for matrix).

@PRE: if lhs is m x n, and rhs is m x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n matrix TODO: enforce the sizes with templates...

Definition at line 163 of file MatrixOps.h.

00166    {
00167       // p. 150 Numerical Analysis (second ed.)
00168       // if A is m x n, and B is m x n, then AB is m x n
00169       // (A - B)ij  = (a)ij + (b)ij     (where:  1 <= i <= m, 1 <= j <= n)
00170       for (unsigned int i = 0; i < ROWS; ++i)           // 1 <= i <= m
00171       for (unsigned int j = 0; j < COLS; ++j)           // 1 <= j <= n
00172          result( i, j ) = lhs( i, j ) + rhs( i, j );
00173 
00174       return result;
00175    }

template<class DATA_TYPE>
Point<DATA_TYPE, 3> center const Tri< DATA_TYPE > &    tri
 

Computes the point at the center of the given triangle.

Parameters:
tri  the triangle to find the center of
Returns:
the point at the center of the triangle

Definition at line 55 of file TriOps.h.

Referenced by gmtl::Sphere::setCenter, and gmtl::Sphere::Sphere.

00056 {
00057    const float one_third = (1.0f/3.0f);
00058    return (tri[0] + tri[1] + tri[2]) * one_third;
00059 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& conj Quat< DATA_TYPE > &    result
 

quaternion complex conjugate.

Postcondition:
set result to the complex conjugate of result.
q* = [s,-v]
result'[x,y,z,w] == result[-x,-y,-z,w]
See also:
Quat

Definition at line 405 of file QuatOps.h.

00406    {
00407       result[Xelt] = -result[Xelt];
00408       result[Yelt] = -result[Yelt];
00409       result[Zelt] = -result[Zelt];
00410       return result;
00411    }

template<class DATA_TYPE>
Vec<DATA_TYPE,3>& cross Vec< DATA_TYPE, 3 > &    result,
const Vec< DATA_TYPE, 3 > &    v1,
const Vec< DATA_TYPE, 3 > &    v2
 

Computes the cross product between v1 and v2 and stores the result in result.

The result is also returned by reference. Use this when you want to reuse an existing Vec to store the result. Note that this only applies to 3-dimensional vectors.

Precondition:
v1 and v2 are 3-D vectors
Postcondition:
result = v1 x v2
Parameters:
result  filled with the result of the cross product between v1 and v2
v1  the first vector
v2  the second vector
Returns:
a reference to result for convenience

Definition at line 390 of file VecOps.h.

Referenced by gmtl::Plane::Plane.

00392 {
00393    result.set( (v1[Yelt]*v2[Zelt]) - (v1[Zelt]*v2[Yelt]),
00394                (v1[Zelt]*v2[Xelt]) - (v1[Xelt]*v2[Zelt]),
00395                (v1[Xelt]*v2[Yelt]) - (v1[Yelt]*v2[Xelt]) );
00396    return result;
00397 }

template<class DATA_TYPE>
Vec<DATA_TYPE,3> cross const Vec< DATA_TYPE, 3 > &    v1,
const Vec< DATA_TYPE, 3 > &    v2
 

Computes the cross product between v1 and v2 and returns the result.

Note that this only applies to 3-dimensional vectors.

Precondition:
v1 and v2 must be 3-D vectors
Postcondition:
result = v1 x v2
Parameters:
v1  the first vector
v2  the second vector
Returns:
the result of the cross product between v1 and v2

Definition at line 367 of file VecOps.h.

00368 {
00369    return Vec<DATA_TYPE,3>( ((v1[Yelt]*v2[Zelt]) - (v1[Zelt]*v2[Yelt])),
00370                             ((v1[Zelt]*v2[Xelt]) - (v1[Xelt]*v2[Zelt])),
00371                             ((v1[Xelt]*v2[Yelt]) - (v1[Yelt]*v2[Xelt])) );
00372 }

template<class DATA_TYPE>
DATA_TYPE distance const Plane< DATA_TYPE > &    plane,
const Point< DATA_TYPE, 3 > &    pt
 

Computes the distance from the plane to the point.

Parameters:
plane  the plane to compare the point to it
pt  a point in space
Returns:
the distance from the point to the plane

Definition at line 59 of file PlaneOps.h.

00060 {
00061    return ( dot(plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt)) - plane.mOffset );
00062 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& div Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

quaternion vector scale.

Postcondition:
result = q / s
See also:
Quat

Definition at line 222 of file QuatOps.h.

00223    {
00224       result[0] = q[0] / s;
00225       result[1] = q[1] / s;
00226       result[2] = q[2] / s;
00227       result[3] = q[3] / s;
00228       return result;
00229    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& div Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q1,
Quat< DATA_TYPE >    q2
 

quotient of two quaternions.

Postcondition:
result = q1 * (1/q2) (where 1/q2 is applied first to any xform'd geometry)
See also:
Quat

Definition at line 191 of file QuatOps.h.

00192    {
00193       // multiply q1 by the multiplicative inverse of the quaternion
00194       return mult( result, q1, invert( q2 ) );
00195    }

template<typename DATA_TYPE>
DATA_TYPE dot const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector dot product between two quaternions.

get the lengthSquared between two quat vectors...

Postcondition:
N(q) = x1*x2 + y1*y2 + z1*z2 + w1*w2
Returns:
dot product of q1 and q2
See also:
Quat

Definition at line 327 of file QuatOps.h.

00328    {
00329       return DATA_TYPE( (q1[0] * q2[0]) +
00330                         (q1[1] * q2[1]) +
00331                         (q1[2] * q2[2]) +
00332                         (q1[3] * q2[3])  );
00333    }

template<class DATA_TYPE, unsigned SIZE>
DATA_TYPE dot const Vec< DATA_TYPE, SIZE > &    v1,
const Vec< DATA_TYPE, SIZE > &    v2
 

Computes dot product of v1 and v2 and returns the result.

Parameters:
v1  the first vector
v2  the second vector
Returns:
the dotproduct of v1 and v2

Definition at line 263 of file VecOps.h.

Referenced by gmtl::Plane::Plane.

00264 {
00265    DATA_TYPE ret_val(0);
00266    for(unsigned i=0;i<SIZE;++i)
00267    {
00268       ret_val += (v1[i] * v2[i]);
00269    }
00270    return ret_val;
00271 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& exp Quat< DATA_TYPE > &    result
 

complex exponentiation.

Precondition:
safe to pass self as argument
Postcondition:
sets self to the exponentiation of quat
See also:
Quat

Definition at line 444 of file QuatOps.h.

00445    {
00446       DATA_TYPE len1, len2;
00447 
00448       len1 = Math::sqrt( result[Xelt] * result[Xelt] +
00449                          result[Yelt] * result[Yelt] +
00450                          result[Zelt] * result[Zelt] );
00451       if (len1 > (DATA_TYPE)0.0)
00452          len2 = Math::sin( len1 ) / len1;
00453       else
00454          len2 = (DATA_TYPE)1.0;
00455 
00456       result[Xelt] = result[Xelt] * len2;
00457       result[Yelt] = result[Yelt] * len2;
00458       result[Zelt] = result[Zelt] * len2;
00459       result[Welt] = Math::cos( len1 );
00460 
00461       return result;
00462    }

template<class DATA_TYPE>
DATA_TYPE findNearestPt const Plane< DATA_TYPE > &    plane,
const Point< DATA_TYPE, 3 > &    pt,
Point< DATA_TYPE, 3 > &    result
 

Finds the point on the plane that is nearest to the given point.

As a convenience, the distance between pt and result is returned.

Parameters:
plane  [in] the plane to compare the point to
pt  [in] the point to test
result  [out] the point on plane closest to pt
Returns:
the distance between pt and result

Definition at line 125 of file PlaneOps.h.

00128 {
00129    // GGI:  p297
00130    // GGII: p223
00131    gmtlASSERT( isNormalized(plane.mNorm) );   // Assert: Normalized
00132    DATA_TYPE dist_to_plane(0);
00133    dist_to_plane = plane.mOffset + dot( plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt) );
00134    result = pt - (plane.mNorm * dist_to_plane);
00135    return dist_to_plane;
00136 }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& identity Matrix< DATA_TYPE, ROWS, COLS > &    result [inline]
 

Make identity matrix out the matrix.

Postcondition:
Every element is 0 except the matrix's diagonal, whose elements are 1.

Definition at line 55 of file MatrixOps.h.

00056    {
00057       if(result.mState != Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY)   // if not already ident
00058       {
00059          // TODO: mp
00060          for (unsigned int r = 0; r < ROWS; ++r)
00061          for (unsigned int c = 0; c < COLS; ++c)
00062             result( r, c ) = (DATA_TYPE)0.0;
00063 
00064          // TODO: mp
00065          for (unsigned int x = 0; x < Math::Min( COLS, ROWS ); ++x)
00066             result( x, x ) = (DATA_TYPE)1.0;
00067 
00068 //         result.mState = Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY;
00069          result.mState = Matrix<DATA_TYPE, ROWS, COLS>::FULL;
00070       }
00071 
00072       return result;
00073    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& invert Quat< DATA_TYPE > &    result
 

quaternion multiplicative inverse.

Postcondition:
self becomes the multiplicative inverse of self
1/q = q* / N(q)
See also:
Quat

Definition at line 419 of file QuatOps.h.

00420    {
00421       // from game programming gems p198
00422       // do result = conj( q ) / norm( q )
00423       conj( result );
00424 
00425       // return if norm() is near 0 (divide by 0 would result in NaN)
00426       DATA_TYPE l = lengthSquared( result );
00427       if (l < (DATA_TYPE)0.0001)
00428          return result;
00429 
00430       DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l;
00431       result[Xelt] *= l_inv;
00432       result[Yelt] *= l_inv;
00433       result[Zelt] *= l_inv;
00434       result[Welt] *= l_inv;
00435       return result;
00436    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& invert Matrix< DATA_TYPE, ROWS, COLS > &    result [inline]
 

smart matrix inversion (in place) Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through.

5 types of inversion: FULL, AFFINE, ORTHONORMAL, ORTHOGONAL, IDENTITY.

Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix.

Definition at line 427 of file MatrixOps.h.

00428    {
00429       return invert( result, result );
00430    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& invert Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    src
[inline]
 

smart matrix inversion.

Does matrix inversion by intelligently selecting what type of inversion to use depending on the types of operations your Matrix has been through.

5 types of inversion: FULL, AFFINE, ORTHONORMAL, ORTHOGONAL, IDENTITY.

Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix.

Definition at line 408 of file MatrixOps.h.

00409    {
00410       if (src.mState == Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY )
00411          return result = src;
00412       else
00413          return invertFull( result, src );
00414    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& invertFull Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    src
[inline]
 

full matrix inversion.

Check for error with Matrix::isError(). @POST: result' = inv( result ) @POST: If inversion failed, then error bit is set within the Matrix.

Definition at line 289 of file MatrixOps.h.

00290    {
00291       /*---------------------------------------------------------------------------*
00292        | mat_inv: Compute the inverse of a n x n matrix, using the maximum pivot   |
00293        |          strategy.  n <= MAX1.                                            |
00294        *---------------------------------------------------------------------------*
00295 
00296          Parameters:
00297              a        a n x n square matrix
00298              b        inverse of input a.
00299              n        dimenstion of matrix a.
00300       */
00301 
00302       const DATA_TYPE* a = src.getData();
00303       DATA_TYPE* b = result.mData;
00304 
00305       int   n = 4;
00306       int    i, j, k;
00307       int    r[ 4], c[ 4], row[ 4], col[ 4];
00308       DATA_TYPE  m[ 4][ 4*2], pivot, max_m, tmp_m, fac;
00309 
00310       /* Initialization */
00311       for ( i = 0; i < n; i ++ )
00312       {
00313          r[ i] = c[ i] = 0;
00314          row[ i] = col[ i] = 0;
00315       }
00316 
00317       /* Set working matrix */
00318       for ( i = 0; i < n; i++ )
00319       {
00320          for ( j = 0; j < n; j++ )
00321          {
00322             m[ i][ j] = a[ i * n + j];
00323             m[ i][ j + n] = ( i == j ) ? (DATA_TYPE)1.0 : (DATA_TYPE)0.0 ;
00324          }
00325       }
00326 
00327       /* Begin of loop */
00328       for ( k = 0; k < n; k++ )
00329       {
00330          /* Choosing the pivot */
00331          for ( i = 0, max_m = 0; i < n; i++ )
00332          {
00333             if ( row[ i]  )
00334                continue;
00335             for ( j = 0; j < n; j++ )
00336             {
00337                if ( col[ j] )
00338                   continue;
00339                tmp_m = gmtl::Math::abs( m[ i][ j]);
00340                if ( tmp_m > max_m)
00341                {
00342                   max_m = tmp_m;
00343                   r[ k] = i;
00344                   c[ k] = j;
00345                }
00346             }
00347          }
00348          row[ r[k] ] = col[ c[k] ] = 1;
00349          pivot = m[ r[ k] ][ c[ k] ];
00350 
00351 
00352          if ( gmtl::Math::abs( pivot) <= 1e-20)
00353          {
00354             std::cerr << "*** pivot = " << pivot << " in mat_inv. ***\n";
00355             result.setError();
00356             return result;
00357          }
00358 
00359          /* Normalization */
00360          for ( j = 0; j < 2*n; j++ )
00361          {
00362             if ( j == c[ k] )
00363                m[ r[ k]][ j] = (DATA_TYPE)1.0;
00364             else
00365                m[ r[ k]][ j] /= pivot;
00366          }
00367 
00368          /* Reduction */
00369          for ( i = 0; i < n; i++ )
00370          {
00371             if ( i == r[ k] )
00372                continue;
00373 
00374             for ( j=0, fac = m[ i][ c[k]]; j < 2*n; j++ )
00375             {
00376                if ( j == c[ k] )
00377                   m[ i][ j] = (DATA_TYPE)0.0;
00378                else
00379                   m[ i][ j] -= fac * m[ r[k]][ j];
00380             }
00381          }
00382       }
00383 
00384       /* Assign inverse to a matrix */
00385       for ( i = 0; i < n; i++ )
00386          for ( j = 0; j < n; j++ )
00387             row[ i] = ( c[ j] == i ) ? r[ j] : row[ i];
00388 
00389       for ( i = 0; i < n; i++ )
00390          for ( j = 0; j < n; j++ )
00391             b[ i * n +  j] = m[ row[ i]][ j + n];
00392 
00393       // It worked
00394       return result;
00395    }

template<class DATA_TYPE, unsigned SIZE>
bool isNormalized const Vec< DATA_TYPE, SIZE > &    v1,
const DATA_TYPE    eps = (DATA_TYPE)0.0001
 

Determines if the given vector is normalized within the given tolerance.

The vector is normalized if its lengthSquared is 1.

Parameters:
v1  the vector to test
eps  the epsilon tolerance
Returns:
true if the vector is normalized, false otherwise

Definition at line 348 of file VecOps.h.

00350 {
00351    return Math::isEqual( lengthSquared( v1 ), (DATA_TYPE)1.0, eps );
00352 }

template<typename DATA_TYPE>
bool isNormalized const Quat< DATA_TYPE > &    q1,
const DATA_TYPE    eps = (DATA_TYPE)0.0001f
 

Determines if the given quaternion is normalized within the given tolerance.

The quaternion is normalized if its lengthSquared is 1.

Parameters:
q1  the quaternion to test
eps  the epsilon tolerance
Returns:
true if the quaternion is normalized, false otherwise

Definition at line 393 of file QuatOps.h.

00394    {
00395       return Math::isEqual( lengthSquared( q1 ), DATA_TYPE(1), eps );
00396    }

template<class DATA_TYPE, unsigned SIZE>
DATA_TYPE length const Vec< DATA_TYPE, SIZE > &    v1
 

Computes the length of the given vector.

Parameters:
v1  the vector with which to compute the length
Returns:
the length of v1

Definition at line 281 of file VecOps.h.

Referenced by gmtl::LineSeg::getLength.

00282 {
00283    DATA_TYPE ret_val = lengthSquared(v1);
00284    if (ret_val == 0.0f)
00285       return 0.0f;
00286    else
00287       return Math::sqrt(ret_val);
00288 }

template<typename DATA_TYPE>
DATA_TYPE length const Quat< DATA_TYPE > &    q
 

quaternion "absolute" (also known as vector length or magnitude) using this can be faster than using length for some operations...

Postcondition:
returns the magnitude of the 4D vector.
result = sqrt( lengthSquared( q ) )
See also:
Quat

Definition at line 355 of file QuatOps.h.

00356    {
00357       return Math::sqrt( lengthSquared( q ) );
00358    }

template<class DATA_TYPE, unsigned SIZE>
DATA_TYPE lengthSquared const Vec< DATA_TYPE, SIZE > &    v1
 

Computes the square of the length of the given vector.

This can be used in many calculations instead of length to increase speed by saving you an expensive sqrt call.

Parameters:
v1  the vector with which to compute the squared length
Returns:
the square of the length of v1

Definition at line 300 of file VecOps.h.

00301 {
00302    DATA_TYPE ret_val(0);
00303    for(unsigned i=0;i<SIZE;++i)
00304    {
00305       ret_val += (v1[i] * v1[i]);
00306    }
00307 
00308    return ret_val;
00309 }

template<typename DATA_TYPE>
DATA_TYPE lengthSquared const Quat< DATA_TYPE > &    q
 

quaternion "norm" (also known as vector length squared) using this can be faster than using length for some operations...

Postcondition:
returns the vector length squared
N(q) = x^2 + y^2 + z^2 + w^2
result = x*x + y*y + z*z + w*w
See also:
Quat

Definition at line 343 of file QuatOps.h.

00344    {
00345       return dot( q, q );
00346    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& log Quat< DATA_TYPE > &    result
 

complex logarithm.

Postcondition:
sets self to the log of quat
See also:
Quat

Definition at line 469 of file QuatOps.h.

00470    {
00471       DATA_TYPE length;
00472 
00473       length = Math::sqrt( result[Xelt] * result[Xelt] +
00474                            result[Yelt] * result[Yelt] +
00475                            result[Zelt] * result[Zelt] );
00476 
00477       // avoid divide by 0
00478       if (Math::isEqual( result[Welt], (DATA_TYPE)0.0, (DATA_TYPE)0.00001 ) == false)
00479          length = Math::aTan( length / result[Welt] );
00480       else
00481          length = Math::PI_OVER_2;
00482 
00483       result[Welt] = (DATA_TYPE)0.0;
00484       result[Xelt] = result[Xelt] * length;
00485       result[Yelt] = result[Yelt] * length;
00486       result[Zelt] = result[Zelt] * length;
00487       return result;
00488    }

template<typename DATA_TYPE>
void meanTangent Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2,
const Quat< DATA_TYPE > &    q3
 

WARNING: not implemented (do not use).

Definition at line 499 of file QuatOps.h.

00500    {
00501        gmtlASSERT( false );
00502    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& mult Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

vector scalar multiplication.

Postcondition:
result' = [qx*s, qy*s, qz*s, qw*s]
See also:
Quat

Definition at line 156 of file QuatOps.h.

00157    {
00158       result[0] = q[0] * s;
00159       result[1] = q[1] * s;
00160       result[2] = q[2] * s;
00161       result[3] = q[3] * s;
00162       return result;
00163    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& mult Matrix< DATA_TYPE, ROWS, COLS > &    result,
DATA_TYPE    scalar
[inline]
 

matrix scalar mult.

mult each elt in a matrix by a scalar value. @POST: result *= scalar

Definition at line 228 of file MatrixOps.h.

00229    {
00230       for (unsigned i = 0; i < ROWS * COLS; ++i)
00231          result.mData[i] *= scalar;
00232       return result;
00233    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& mult Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    mat,
float    scalar
[inline]
 

matrix scalar mult.

mult each elt in a matrix by a scalar value. @POST: result = mat * scalar

Definition at line 216 of file MatrixOps.h.

00217    {
00218       for (unsigned i = 0; i < ROWS * COLS; ++i)
00219          result.mData[i] = mat.mData[i] * scalar;
00220       return result;
00221    }

template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& mult Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, INTERNAL > &    lhs,
const Matrix< DATA_TYPE, INTERNAL, COLS > &    rhs
[inline]
 

matrix multiply.

@PRE: With regard to size (ROWS/COLS): if lhs is m x p, and rhs is p x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n sized matrix @post: result = lhs * rhs (where rhs is applied first)

Definition at line 106 of file MatrixOps.h.

00109    {
00110       Matrix<DATA_TYPE, ROWS, COLS> ret_mat; // prevent aliasing
00111       zero( ret_mat );
00112 
00113       // p. 150 Numerical Analysis (second ed.)
00114       // if A is m x p, and B is p x n, then AB is m x n
00115       // (AB)ij  =  [k = 1 to p] (a)ik (b)kj     (where:  1 <= i <= m, 1 <= j <= n)
00116       for (unsigned int i = 0; i < ROWS; ++i)           // 1 <= i <= m
00117       for (unsigned int j = 0; j < COLS; ++j)           // 1 <= j <= n
00118       for (unsigned int k = 0; k < INTERNAL; ++k)       // [k = 1 to p]
00119          ret_mat( i, j ) += lhs( i, k ) * rhs( k, j );
00120 
00121       return result = ret_mat;
00122    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& mult Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

product of two quaternions (quaternion product) multiplication of quats is much like multiplication of typical complex numbers.

Postcondition:
q1q2 = (s1 + v1)(s2 + v2)
result = q1 * q2 (where q2 would be applied first to any xformed geometry)
See also:
Quat

Definition at line 55 of file QuatOps.h.

00056    {
00057       // Here is the easy to understand equation: (grassman product)
00058       // scalar_component = q1.s * q2.s - dot(q1.v, q2.v)
00059       // vector_component = q2.v * q1.s + q1.v * q2.s + cross(q1.v, q2.v)
00060 
00061       // Here is another version (euclidean product, just FYI)...
00062       // scalar_component = q1.s * q2.s + dot(q1.v, q2.v)
00063       // vector_component = q2.v * q1.s - q1.v * q2.s - cross(q1.v, q2.v)
00064 
00065       // Here it is, using vector algebra (grassman product)
00066       /*
00067       const float& w1( q1[Welt] ), w2( q2[Welt] );
00068       Vec3 v1( q1[Xelt], q1[Yelt], q1[Zelt] ), v2( q2[Xelt], q2[Yelt], q2[Zelt] );
00069 
00070       float w = w1 * w2 - v1.dot( v2 );
00071       Vec3 v = (w1 * v2) + (w2 * v1) + v1.cross( v2 );
00072 
00073       vec[Welt] = w;
00074       vec[Xelt] = v[0];
00075       vec[Yelt] = v[1];
00076       vec[Zelt] = v[2];
00077       */
00078 
00079       // Here is the same, only expanded... (grassman product)
00080       Quat<DATA_TYPE> temporary; // avoid aliasing problems...
00081       temporary[Xelt] = q1[Welt]*q2[Xelt] + q1[Xelt]*q2[Welt] + q1[Yelt]*q2[Zelt] - q1[Zelt]*q2[Yelt];
00082       temporary[Yelt] = q1[Welt]*q2[Yelt] + q1[Yelt]*q2[Welt] + q1[Zelt]*q2[Xelt] - q1[Xelt]*q2[Zelt];
00083       temporary[Zelt] = q1[Welt]*q2[Zelt] + q1[Zelt]*q2[Welt] + q1[Xelt]*q2[Yelt] - q1[Yelt]*q2[Xelt];
00084       temporary[Welt] = q1[Welt]*q2[Welt] - q1[Xelt]*q2[Xelt] - q1[Yelt]*q2[Yelt] - q1[Zelt]*q2[Zelt];
00085 
00086       // use a temporary, in case q1 or q2 is the same as self.
00087       result[Xelt] = temporary[Xelt];
00088       result[Yelt] = temporary[Yelt];
00089       result[Zelt] = temporary[Zelt];
00090       result[Welt] = temporary[Welt];
00091 
00092       // don't normalize, because it might not be rotation arithmetic we're doing
00093       // (only rotation quats have unit length)
00094       return result;
00095    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& negate Quat< DATA_TYPE > &    result
 

Vector negation - negate each element in the quaternion vector.

the negative of a rotation quaternion is geometrically equivelent to the original. there exist 2 quats for every possible rotation.

Returns:
returns the negation of the given quat.

Definition at line 131 of file QuatOps.h.

00132    {
00133       result[0] = -result[0];
00134       result[1] = -result[1];
00135       result[2] = -result[2];
00136       result[3] = -result[3];
00137       return result;
00138    }

template<class DATA_TYPE>
Vec<DATA_TYPE, 3> normal const Tri< DATA_TYPE > &    tri
 

Computes the normal for this triangle.

Parameters:
tri  the triangle for which to compute the normal
Returns:
the normal vector for tri

Definition at line 69 of file TriOps.h.

00070 {
00071    Vec<DATA_TYPE, 3> normal = cross( tri[1] - tri[0], tri[2] - tri[0] );
00072    normalize( normal );
00073    return normal;
00074 }

template<class DATA_TYPE, unsigned SIZE>
DATA_TYPE normalize Vec< DATA_TYPE, SIZE > &    v1
 

Normalizes the given vector in place causing it to be of unit length.

If the vector is already of length 1.0, nothing is done. For convenience, the original length of the vector is returned.

Postcondition:
length(v1) == 1.0 unless length(v1) is originally 0.0, in which case it is unchanged
Parameters:
v1  the vector to normalize
Returns:
the length of v1 before it was normalized

Definition at line 323 of file VecOps.h.

Referenced by gmtl::Plane::Plane.

00324 {
00325    DATA_TYPE len = length(v1);
00326 
00327    if(len != 0.0f)
00328    {
00329       for(unsigned i=0;i<SIZE;++i)
00330       {
00331          v1[i] /= len;
00332       }
00333    }
00334 
00335    return len;
00336 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& normalize Quat< DATA_TYPE > &    result
 

set self to the normalized quaternion of self.

Precondition:
magnitude should be > 0, otherwise no calculation is done.
Postcondition:
result' = normalize( result ), where normalize makes length( result ) == 1
See also:
Quat

Definition at line 366 of file QuatOps.h.

00367    {
00368       DATA_TYPE l = length( result );
00369 
00370       // return if no magnitude (already as normalized as possible)
00371       if (l < (DATA_TYPE)0.0001)
00372          return result;
00373 
00374       DATA_TYPE l_inv = ((DATA_TYPE)1.0) / l;
00375       result[Xelt] *= l_inv;
00376       result[Yelt] *= l_inv;
00377       result[Zelt] *= l_inv;
00378       result[Welt] *= l_inv;
00379 
00380       return result;
00381    }

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE>
VecBase<DATA_TYPE, SIZE> operator * const SCALAR_TYPE &    scalar,
const VecBase< DATA_TYPE, SIZE > &    v1
 

Multiplies v1 by a scalar value and returns the result.

Thus result = scalar * v1. This is equivalent to result = v1 * scalar.

Parameters:
scalar  the amount by which to scale v1
v1  the vector to scale
Returns:
the result of multiplying v1 by scalar

Definition at line 197 of file VecOps.h.

00199 {
00200    VecBase<DATA_TYPE, SIZE> ret_val(v1);
00201    ret_val *= scalar;
00202    return ret_val;
00203 
00204    //return VecBase<DATA_TYPE, SIZE>(v1) *= scalar;
00205 }

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE>
VecBase<DATA_TYPE, SIZE> operator * const VecBase< DATA_TYPE, SIZE > &    v1,
const SCALAR_TYPE &    scalar
 

Multiplies v1 by a scalar value and returns the result.

Thus result = v1 * scalar.

Parameters:
v1  the vector to scale
scalar  the amount by which to scale v1
Returns:
the result of multiplying v1 by scalar

Definition at line 177 of file VecOps.h.

00179 {
00180    VecBase<DATA_TYPE, SIZE> ret_val(v1);
00181    ret_val *= scalar;
00182    return ret_val;
00183 
00184    //return VecBase<DATA_TYPE, SIZE>(v1) *= scalar;
00185 }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator * const Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

vector scalar multiplication.

Postcondition:
result' = [qx*s, qy*s, qz*s, qw*s]
See also:
Quat

Definition at line 170 of file QuatOps.h.

00171    {
00172       Quat<DATA_TYPE> temporary;
00173       return mult( temporary, q, s );
00174    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator * const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

product of two quaternions (quaternion product) Does quaternion multiplication.

Postcondition:
temp' = q1 * q2 (where q2 would be applied first to any xformed geometry)
See also:
Quat
Todo:
metaprogramming on quat operator *()

Definition at line 104 of file QuatOps.h.

00105    {
00106       // (grassman product - see mult() for discussion)
00107       // don't normalize, because it might not be rotation arithmetic we're doing
00108       // (only rotation quats have unit length)
00109       return Quat<DATA_TYPE>( q1[Welt]*q2[Xelt] + q1[Xelt]*q2[Welt] + q1[Yelt]*q2[Zelt] - q1[Zelt]*q2[Yelt],
00110                               q1[Welt]*q2[Yelt] + q1[Yelt]*q2[Welt] + q1[Zelt]*q2[Xelt] - q1[Xelt]*q2[Zelt],
00111                               q1[Welt]*q2[Zelt] + q1[Zelt]*q2[Welt] + q1[Xelt]*q2[Yelt] - q1[Yelt]*q2[Xelt],
00112                               q1[Welt]*q2[Welt] - q1[Xelt]*q2[Xelt] - q1[Yelt]*q2[Yelt] - q1[Zelt]*q2[Zelt] );
00113    }

template<typename DATA_TYPE, unsigned ROWS, unsigned INTERNAL, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS> operator * const Matrix< DATA_TYPE, ROWS, INTERNAL > &    lhs,
const Matrix< DATA_TYPE, INTERNAL, COLS > &    rhs
[inline]
 

matrix * matrix.

@PRE: With regard to size (ROWS/COLS): if lhs is m x p, and rhs is p x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n sized matrix == lhs * rhs (where rhs is applied first) returns a temporary, is slower.

Definition at line 130 of file MatrixOps.h.

00132    {
00133       Matrix<DATA_TYPE, ROWS, COLS> temporary;
00134       return mult( temporary, lhs, rhs );
00135    }

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE>
VecBase<DATA_TYPE, SIZE>& operator *= VecBase< DATA_TYPE, SIZE > &    v1,
const SCALAR_TYPE &    scalar
 

Multiplies v1 by a scalar value and stores the result in v1.

This is equivalent to the expression v1 = v1 * scalar.

Parameters:
v1  the vector to scale
scalar  the amount by which to scale v1
Returns:
v1 after it has been mutiplied by scalar

Definition at line 156 of file VecOps.h.

00158 {
00159    for(unsigned i=0;i<SIZE;++i)
00160    {
00161       v1[i] *= (DATA_TYPE)scalar;
00162    }
00163 
00164    return v1;
00165 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator *= Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

vector scalar multiplication.

Postcondition:
result' = [resultx*s, resulty*s, resultz*s, resultw*s]
See also:
Quat

Definition at line 181 of file QuatOps.h.

00182    {
00183       return mult( q, q, s );
00184    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator *= Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q2
 

quaternion postmult.

Postcondition:
result' = result * q2 (where q2 is applied first to any xformed geometry)
See also:
Quat

Definition at line 120 of file QuatOps.h.

00121    {
00122       return mult( result, result, q2 );
00123    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& operator *= Matrix< DATA_TYPE, ROWS, COLS > &    result,
DATA_TYPE    scalar
[inline]
 

matrix scalar mult (operator *=).

multiply matrix elements by a scalar @POST: result *= scalar

Definition at line 240 of file MatrixOps.h.

00241    {
00242       return mult( result, scalar );
00243    }

template<typename DATA_TYPE, unsigned SIZE>
Matrix<DATA_TYPE, SIZE, SIZE>& operator *= Matrix< DATA_TYPE, SIZE, SIZE > &    result,
const Matrix< DATA_TYPE, SIZE, SIZE > &    operand
[inline]
 

matrix postmult (operator *=).

does a postmult on the matrix. @PRE: args must both be n x n sized (this function is undefined otherwise) @POST: result' = result * operand (where operand is applied first)

Definition at line 205 of file MatrixOps.h.

00207    {
00208       return postMult( result, operand );
00209    }

template<class DATA_TYPE, unsigned SIZE>
VecBase<DATA_TYPE, SIZE> operator+ const VecBase< DATA_TYPE, SIZE > &    v1,
const VecBase< DATA_TYPE, SIZE > &    v2
 

Adds v2 to v1 and returns the result.

Thus result = v1 + v2.

Parameters:
v1  the first vector
v2  the second vector
Returns:
the result of adding v2 to v1

Definition at line 100 of file VecOps.h.

00102 {
00103    VecBase<DATA_TYPE, SIZE> ret_val(v1);
00104    ret_val += v2;
00105    return ret_val;
00106 }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator+ const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector addition.

Postcondition:
result' = [qx+s, qy+s, qz+s, qw+s]
See also:
Quat

Definition at line 270 of file QuatOps.h.

00271    {
00272       Quat<DATA_TYPE> temporary;
00273       return add( temporary, q1, q2 );
00274    }

template<class DATA_TYPE, unsigned SIZE>
VecBase<DATA_TYPE, SIZE>& operator+= VecBase< DATA_TYPE, SIZE > &    v1,
const VecBase< DATA_TYPE, SIZE > &    v2
 

Adds v2 to v1 and stores the result in v1.

This is equivalent to the expression v1 = v1 + v2.

Parameters:
v1  the first vector
v2  the second vector
Returns:
v1 after v2 has been added to it

Definition at line 80 of file VecOps.h.

00082 {
00083    for(unsigned i=0;i<SIZE;++i)
00084    {
00085       v1[i] += v2[i];
00086    }
00087 
00088    return v1;
00089 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator+= Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector addition.

Postcondition:
result' = [resultx+s, resulty+s, resultz+s, resultw+s]
See also:
Quat

Definition at line 281 of file QuatOps.h.

00282    {
00283       return add( q1, q1, q2 );
00284    }

template<class DATA_TYPE, unsigned SIZE>
Vec<DATA_TYPE, SIZE> operator- const VecBase< DATA_TYPE, SIZE > &    v1,
const VecBase< DATA_TYPE, SIZE > &    v2
 

Subtracts v2 from v1 and returns the result.

Thus result = v1 - v2.

Parameters:
v1  the first vector
v2  the second vector
Returns:
the result of subtracting v2 from v1

Definition at line 138 of file VecOps.h.

00140 {
00141    Vec<DATA_TYPE, SIZE> ret_val(v1);
00142    ret_val -= v2;
00143    return ret_val;
00144 }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator- const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector subtraction.

Postcondition:
result' = [qx-s, qy-s, qz-s, qw-s]
See also:
Quat

Definition at line 304 of file QuatOps.h.

00305    {
00306       Quat<DATA_TYPE> temporary;
00307       return sub( temporary, q1, q2 );
00308    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator- const Quat< DATA_TYPE > &    quat
 

Vector negation - (operator-) return a temporary that is the negative of the given quat.

the negative of a rotation quaternion is geometrically equivelent to the original. there exist 2 quats for every possible rotation.

Returns:
returns the negation of the given quat

Definition at line 146 of file QuatOps.h.

00147    {
00148       return Quat<DATA_TYPE>( -quat[0], -quat[1], -quat[2], -quat[3] );
00149    }

template<typename DATA_TYPE, unsigned SIZE>
Vec<DATA_TYPE, SIZE> operator- const VecBase< DATA_TYPE, SIZE > &    v1
 

Negates v1.

The result = -v1.

Parameters:
v1  the vector.
Returns:
the result of negating v1.

Definition at line 60 of file VecOps.h.

00061 {
00062    Vec<DATA_TYPE, SIZE> ret_val;
00063    for ( unsigned i=0; i < SIZE; ++i )
00064    {
00065       ret_val[i] = -v1[i];
00066    }
00067    return ret_val;
00068 }

template<class DATA_TYPE, unsigned SIZE>
VecBase<DATA_TYPE, SIZE>& operator-= VecBase< DATA_TYPE, SIZE > &    v1,
const VecBase< DATA_TYPE, SIZE > &    v2
 

Subtracts v2 from v1 and stores the result in v1.

This is equivalent to the expression v1 = v1 - v2.

Parameters:
v1  the first vector
v2  the second vector
Returns:
v1 after v2 has been subtracted from it

Definition at line 118 of file VecOps.h.

00120 {
00121    for(unsigned i=0;i<SIZE;++i)
00122    {
00123       v1[i] -= v2[i];
00124    }
00125 
00126    return v1;
00127 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator-= Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector subtraction.

Postcondition:
result' = [resultx-s, resulty-s, resultz-s, resultw-s]
See also:
Quat

Definition at line 315 of file QuatOps.h.

00316    {
00317       return sub( q1, q1, q2 );
00318    }

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE>
VecBase<DATA_TYPE, SIZE> operator/ const VecBase< DATA_TYPE, SIZE > &    v1,
const SCALAR_TYPE &    scalar
 

Divides v1 by a scalar value and returns the result.

Thus result = v1 / scalar.

Parameters:
v1  the vector to scale
scalar  the amount by which to scale v1
Returns:
the result of dividing v1 by scalar

Definition at line 238 of file VecOps.h.

00240 {
00241    VecBase<DATA_TYPE, SIZE> ret_val(v1);
00242    ret_val /= scalar;
00243    return ret_val;
00244    // return VecBase<DATA_TYPE, SIZE>(v1)( /= scalar;
00245 }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator/ const Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

vector scalar division.

Postcondition:
result' = [qx/s, qy/s, qz/s, qw/s]
See also:
Quat

Definition at line 236 of file QuatOps.h.

00237    {
00238       Quat<DATA_TYPE> temporary;
00239       return div( temporary, q, s );
00240    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> operator/ const Quat< DATA_TYPE > &    q1,
Quat< DATA_TYPE >    q2
 

quotient of two quaternions.

Postcondition:
result = q1 * (1/q2) (where 1/q2 is applied first to any xform'd geometry)
See also:
Quat

Definition at line 202 of file QuatOps.h.

00203    {
00204       return q1 * invert( q2 );
00205    }

template<class DATA_TYPE, unsigned SIZE, class SCALAR_TYPE>
VecBase<DATA_TYPE, SIZE>& operator/= VecBase< DATA_TYPE, SIZE > &    v1,
const SCALAR_TYPE &    scalar
 

Divides v1 by a scalar value and stores the result in v1.

This is equivalent to the expression v1 = v1 / scalar.

Parameters:
v1  the vector to scale
scalar  the amount by which to scale v1
Returns:
v1 after it has been divided by scalar

Definition at line 217 of file VecOps.h.

00219 {
00220    for(unsigned i=0;i<SIZE;++i)
00221    {
00222       v1[i] /= scalar;
00223    }
00224 
00225    return v1;
00226 }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator/= const Quat< DATA_TYPE > &    q,
DATA_TYPE    s
 

vector scalar division.

Postcondition:
result' = [resultx/s, resulty/s, resultz/s, resultw/s]
See also:
Quat

Definition at line 247 of file QuatOps.h.

00248    {
00249       return div( q, q, s );
00250    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& operator/= Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q2
 

quotient of two quaternions.

Postcondition:
result = result * (1/q2) (where 1/q2 is applied first to any xform'd geometry)
See also:
Quat

Definition at line 212 of file QuatOps.h.

00213    {
00214       return div( result, result, q2 );
00215    }

template<typename DATA_TYPE, unsigned SIZE>
Matrix<DATA_TYPE, SIZE, SIZE>& postMult Matrix< DATA_TYPE, SIZE, SIZE > &    result,
const Matrix< DATA_TYPE, SIZE, SIZE > &    operand
[inline]
 

matrix postmultiply.

@PRE: args must both be n x n (this function is undefined otherwise) @POST: result' = result * operand

Definition at line 182 of file MatrixOps.h.

00184    {
00185       return mult( result, result, operand );
00186    }

template<typename DATA_TYPE, unsigned SIZE>
Matrix<DATA_TYPE, SIZE, SIZE>& preMult Matrix< DATA_TYPE, SIZE, SIZE > &    result,
const Matrix< DATA_TYPE, SIZE, SIZE > &    operand
[inline]
 

matrix preMultiply.

@PRE: args must both be n x n (this function is undefined otherwise) @POST: result' = operand * result

Definition at line 193 of file MatrixOps.h.

00195    {
00196       return mult( result, operand, result );
00197    }

template<class DATA_TYPE, unsigned SIZE>
VecBase<DATA_TYPE, SIZE>& reflect VecBase< DATA_TYPE, SIZE > &    result,
const VecBase< DATA_TYPE, SIZE > &    vec,
const Vec< DATA_TYPE, SIZE > &    normal
 

Reflect a vector about a normal.

Parameters:
result  the vector to store the result i
vec  the original vector that we want to reflect
normal  the normal vector
Postcondition:
result contains the reflected vector

Definition at line 408 of file VecOps.h.

00411 {
00412    result = vec - DATA_TYPE( 2.0 ) * dot( (Vec<DATA_TYPE, SIZE>)vec, normal ) * normal;
00413    return result;
00414 }

template<typename DATA_TYPE>
void squad Quat< DATA_TYPE > &    result,
DATA_TYPE    t,
const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2,
const Quat< DATA_TYPE > &    a,
const Quat< DATA_TYPE > &    b
 

WARNING: not implemented (do not use).

Definition at line 492 of file QuatOps.h.

00493    {
00494       gmtlASSERT( false );
00495    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& sub Quat< DATA_TYPE > &    result,
const Quat< DATA_TYPE > &    q1,
const Quat< DATA_TYPE > &    q2
 

vector subtraction.

See also:
Quat

Definition at line 290 of file QuatOps.h.

00291    {
00292       result[0] = q1[0] - q2[0];
00293       result[1] = q1[1] - q2[1];
00294       result[2] = q1[2] - q2[2];
00295       result[3] = q1[3] - q2[3];
00296       return result;
00297    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& sub Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    lhs,
const Matrix< DATA_TYPE, ROWS, COLS > &    rhs
[inline]
 

matrix subtraction (algebraic operation for matrix).

@PRE: if lhs is m x n, and rhs is m x n, then result is m x n (mult func undefined otherwise) @POST: returns a m x n matrix @TODO: enforce the sizes with templates...

Definition at line 143 of file MatrixOps.h.

00146    {
00147       // p. 150 Numerical Analysis (second ed.)
00148       // if A is m x n, and B is m x n, then AB is m x n
00149       // (A - B)ij  = (a)ij - (b)ij     (where:  1 <= i <= m, 1 <= j <= n)
00150       for (unsigned int i = 0; i < ROWS; ++i)           // 1 <= i <= m
00151       for (unsigned int j = 0; j < COLS; ++j)           // 1 <= j <= n
00152          result( i, j ) = lhs( i, j ) - rhs( i, j );
00153 
00154       return result;
00155    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& transpose Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Matrix< DATA_TYPE, COLS, ROWS > &    source
 

matrix transpose from one type to another (i.e.

3x4 to 4x3) @PRE: source needs to be an M x N matrix, while dest needs to be N x M @POST: flip along diagonal

Definition at line 265 of file MatrixOps.h.

00266    {
00267       // in case result is == source... :(
00268       Matrix<DATA_TYPE, COLS, ROWS> temp = source;
00269 
00270       // p. 149 Numerical Analysis (second ed.)
00271       for (unsigned i = 0; i < ROWS; ++i)
00272       {
00273          for (unsigned j = 0; j < COLS; ++j)
00274          {
00275             result( i, j ) = temp( j, i );
00276          }
00277       }
00278 
00279       return result;
00280    }

template<typename DATA_TYPE, unsigned SIZE>
Matrix<DATA_TYPE, SIZE, SIZE>& transpose Matrix< DATA_TYPE, SIZE, SIZE > &    result
 

matrix transpose in place.

@PRE: needs to be an N x N matrix @POST: flip along diagonal

Definition at line 250 of file MatrixOps.h.

00251    {
00252       // p. 27 game programming gems #1
00253       for (unsigned c = 0; c < SIZE; ++c)
00254          for (unsigned r = c + 1; r < SIZE; ++r)
00255             std::swap( result( r, c ), result( c, r ) );
00256 
00257       return result;
00258    }

template<class DATA_TYPE>
PlaneSide whichSide const Plane< DATA_TYPE > &    plane,
const Point< DATA_TYPE, 3 > &    pt,
const DATA_TYPE &    eps
 

Determines which side of the plane the given point lies with the given epsilon tolerance.

Parameters:
plane  the plane to compare the point to
pt  the point to test
eps  the epsilon tolerance to use while testing
Returns:
the PlaneSide enum describing on which side of the plane the point lies

Definition at line 100 of file PlaneOps.h.

00103 {
00104    DATA_TYPE dist = distance( plane, pt );
00105 
00106    if ( dist < eps )
00107       return NEG_SIDE;
00108    else if ( dist > eps )
00109       return POS_SIDE;
00110    else
00111       return ON_PLANE;
00112 }

template<class DATA_TYPE>
PlaneSide whichSide const Plane< DATA_TYPE > &    plane,
const Point< DATA_TYPE, 3 > &    pt
 

Determines which side of the plane the given point lies.

This operation is done with ZERO tolerance.

Parameters:
plane  the plane to compare the point to
pt  the point to test
Returns:
the PlaneSide enum describing on which side of the plane the point lies

Definition at line 75 of file PlaneOps.h.

00077 {
00078    DATA_TYPE dist = distance( plane, pt );
00079 
00080    if ( dist < DATA_TYPE(0) )
00081       return NEG_SIDE;
00082    else if ( dist > DATA_TYPE(0) )
00083       return POS_SIDE;
00084    else
00085       return ON_PLANE;
00086 }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& zero Matrix< DATA_TYPE, ROWS, COLS > &    result [inline]
 

zero out the matrix.

Postcondition:
every element is 0.

Definition at line 80 of file MatrixOps.h.

00081    {
00082       if (result.mState == Matrix<DATA_TYPE, ROWS, COLS>::IDENTITY)
00083       {
00084          for (unsigned int x = 0; x < Math::Min( ROWS, COLS ); ++x)
00085          {
00086             result( x, x ) = (DATA_TYPE)0;
00087          }
00088       }
00089       else
00090       {
00091          for (unsigned int x = 0; x < ROWS*COLS; ++x)
00092          {
00093             result.mData[x] = (DATA_TYPE)0;
00094          }
00095       }
00096       return result;
00097    }


Generated on Mon Apr 7 15:29:24 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002