CMaths.h File Reference

Various mathematical utility functions. More...

#include "CMatrix3d.h"
#include <math.h>

Functions

bool cZero (const double &a_value)
bool cPositiveBound (const double &a_value, const double &a_boundMax)
template<class T>
cAbs (const T a_value)
template<class T>
cMax (const T a_value1, const T a_value2)
template<class T>
cMin (const T a_value1, const T a_value2)
template<class T>
cMax3 (const T &a_value1, const T &a_value2, const T &a_value3)
template<class T>
cMin3 (const T &a_value1, const T &a_value2, const T &a_value3)
template<class T>
cMaxAbs (const T a_value1, const T a_value2)
template<class T>
cMinAbs (const T a_value1, const T a_value2)
template<class T>
cMax3Abs (const T &a_value1, const T &a_value2, const T &a_value3)
template<class T>
cMin3Abs (const T &a_value1, const T &a_value2, const T &a_value3)
template<class T>
void cSwap (T &a_value1, T &a_value2)
template<class T>
cLerp (const double &a_level, const T &a_value1, const T &a_value2)
template<class T>
cClamp (const T a_value, const T a_low, const T a_high)
template<class T>
cClamp0 (T &a_value)
double cClamp01 (double &a_value)
template<class T, class V>
bool cContains (const T &a_value, const V &a_low, const V &a_high)
double cSqr (const double &a_value)
double cCosDeg (const double &a_angleDeg)
double cSinDeg (const double &a_angleDeg)
double cTanDeg (const double &a_angleDeg)
double cCosRad (const double &a_angleRad)
double cSinRad (const double &a_value)
double cTanRad (const double &a_value)
double cDegToRad (const double &a_angleDeg)
double cRadToDeg (const double &a_angleRad)
cVector3d cAdd (const cVector3d &a_vector1, const cVector3d &a_vector2)
cVector3d cAdd (const cVector3d &a_vector1, const cVector3d &a_vector2, const cVector3d &a_vector3)
cVector3d cSub (const cVector3d &a_vector1, const cVector3d &a_vector2)
cVector3d cNegate (const cVector3d &a_vector)
cVector3d cMul (const double &a_value, const cVector3d &a_vector)
cVector3d cDiv (const double &a_value, const cVector3d &a_vector)
cVector3d cDivVect (const double &a_value, const cVector3d &a_vector)
cVector3d cCross (const cVector3d &a_vector1, const cVector3d &a_vector2)
double cDot (const cVector3d &a_vector1, const cVector3d &a_vector2)
cVector3d cNormalize (const cVector3d &a_vector)
double cDistance (const cVector3d &a_point1, const cVector3d &a_point2)
double cDistanceSq (const cVector3d &a_point1, const cVector3d &a_point2)
bool cEqualPoints (const cVector3d &v1, const cVector3d &v2, const double epsilon=CHAI_SMALL)
cMatrix3d cIdentity3d (void)
cMatrix3d cMul (const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
cVector3d cMul (const cMatrix3d &a_matrix, const cVector3d &a_vector)
cMatrix3d cTrans (const cMatrix3d &a_matrix)
cMatrix3d cInv (const cMatrix3d &a_matrix)
double cAngle (const cVector3d &a_vector0, const cVector3d &a_vector1)
double cCosAngle (const cVector3d &a_vector0, const cVector3d &a_vector1)
cMatrix3d cRotMatrix (const cVector3d &a_axis, const double &a_angleRad)
cMatrix3d cRotate (const cMatrix3d &a_matrix, const cVector3d &a_axis, const double &a_angleRad)
cVector3d cProjectPointOnPlane (const cVector3d &a_point, const cVector3d &a_planePoint, const cVector3d &n)
cVector3d cProjectPointOnPlane (const cVector3d &a_point, const cVector3d &a_planePoint0, const cVector3d &a_planePoint1, const cVector3d &a_planePoint2)
cVector3d cProjectPointOnLine (const cVector3d &a_point, const cVector3d &a_pointOnLine, const cVector3d &a_directionOfLine)
cVector3d cProject (const cVector3d &a_vector0, const cVector3d &a_vector1)
cVector3d cComputeSurfaceNormal (const cVector3d &a_surfacePoint0, const cVector3d &a_surfacePoint1, const cVector3d &a_surfacePoint2)
bool cBoxContains (const cVector3d &p, const cVector3d &box_min, const cVector3d &box_max)


Detailed Description

Various mathematical utility functions.


Function Documentation

template<class T>
T cAbs ( const T  a_value  )  [inline]

Compute absolute value.

Parameters:
a_value Input value
Returns:
Return |a_value|

cVector3d cAdd ( const cVector3d a_vector1,
const cVector3d a_vector2,
const cVector3d a_vector3 
) [inline]

Compute the addition between three vectors. Result = Vector1 + Vector2 + Vector3.

Parameters:
a_vector1 First vector.
a_vector2 Second vector.
a_vector3 Third vector.
Returns:
Return the addition of all three vectors.

cVector3d cAdd ( const cVector3d a_vector1,
const cVector3d a_vector2 
) [inline]

Compute the addition between two vectors. Result = Vector1 + Vector2.

Parameters:
a_vector1 First vector.
a_vector2 Second vector.
Returns:
Return the addition of both vectors.

double cAngle ( const cVector3d a_vector0,
const cVector3d a_vector1 
) [inline]

Compute the angle between two vectors (in radians).

Parameters:
a_vector0 Input vector.
a_vector1 Input vector.
Returns:
Returns the angle (in radians) between the input vectors.

bool cBoxContains ( const cVector3d p,
const cVector3d box_min,
const cVector3d box_max 
) [inline]

Returns true if p is contained in the bounding box defined by min and max

Parameters:
p Test point
box_min Minimum coordinate in the boundary box
box_max Maximum coordinate in the boundary box
Returns:
Returns true if p is in [box_min,box_max], inclusive

template<class T>
T cClamp ( const T  a_value,
const T  a_low,
const T  a_high 
) [inline]

Clamp the input to the specified range.

Parameters:
a_value Input value.
a_low Low boundary.
a_high High boundary.
Returns:
Return clamped value.
Note that this function should _not_ be modified to take inputs by reference.

template<class T>
T cClamp0 ( T &  a_value  )  [inline]

Clamp the input to the range 0 - infinity.

Parameters:
a_value Input value.
Returns:
Return clamped value.

double cClamp01 ( double &  a_value  )  [inline]

Clamp the input to the range [0,1].

Parameters:
a_value Input value of type double.
Returns:
Return clamped value.

cVector3d cComputeSurfaceNormal ( const cVector3d a_surfacePoint0,
const cVector3d a_surfacePoint1,
const cVector3d a_surfacePoint2 
) [inline]

Compute the normal of a surface defined by three point passed as parameters.

Parameters:
a_surfacePoint0 Point 0 of surface.
a_surfacePoint1 Point 1 of surface.
a_surfacePoint2 Point 2 of surface.
Returns:
Return surface normal.

template<class T, class V>
bool cContains ( const T &  a_value,
const V &  a_low,
const V &  a_high 
) [inline]

Check whether input is in the range of [low, high].

Parameters:
a_value Input value.
a_low Low boundary.
a_high High boundary.
Returns:
Return true if value is in the rage of [low, high] and false otherwise.

double cCosAngle ( const cVector3d a_vector0,
const cVector3d a_vector1 
) [inline]

Compute cosine of the angle between two vectors.

Parameters:
a_vector0 Input vector.
a_vector1 Input vector.
Returns:
Returns the cosine of the angle between the input vectors.

double cCosDeg ( const double &  a_angleDeg  )  [inline]

Compute the cosine of an angle defined in degrees.

Parameters:
a_angleDeg Angle in degrees.
Returns:
Return the cosine of angle.

double cCosRad ( const double &  a_angleRad  )  [inline]

Return the cosine of an angle defined in radians.

Parameters:
a_angleRad Angle in radians.
Returns:
Return the cosine of angle.

cVector3d cCross ( const cVector3d a_vector1,
const cVector3d a_vector2 
) [inline]

Compute the cross product between two 3D vectors.

Parameters:
a_vector1 First vector.
a_vector2 Second vector.
Returns:
Returns the cross product between both vectors.

double cDegToRad ( const double &  a_angleDeg  )  [inline]

Convert an angle from degrees to radians.

Parameters:
a_angleDeg Angle in degrees.
Returns:
Return angle in radians.

double cDistance ( const cVector3d a_point1,
const cVector3d a_point2 
) [inline]

Compute the distance between two points.

Parameters:
a_point1 First point.
a_point2 Second point.
Returns:
Return distance between points

double cDistanceSq ( const cVector3d a_point1,
const cVector3d a_point2 
) [inline]

Compute the squared distance between two points.

Parameters:
a_point1 First point.
a_point2 Second point.
Returns:
Return squared distance between points

cVector3d cDiv ( const double &  a_value,
const cVector3d a_vector 
) [inline]

Divide a vector by a scalar.

Parameters:
a_value Scalar.
a_vector Input vector.
Returns:
Returns result of division.

cVector3d cDivVect ( const double &  a_value,
const cVector3d a_vector 
) [inline]

Divide a scalar by components of a 3D vector and return vector

Parameters:
a_value Scalar.
a_vector Input vector.
Returns:
Returns a vector. result = value / vector.

double cDot ( const cVector3d a_vector1,
const cVector3d a_vector2 
) [inline]

Compute the dot product between two vectors.

Parameters:
a_vector1 First vector.
a_vector2 Second vector.
Returns:
Returns the dot product between between both vectors.

bool inline cEqualPoints ( const cVector3d v1,
const cVector3d v2,
const double  epsilon = CHAI_SMALL 
) [inline]

Determine whether two vectors represent the same point.

Parameters:
v1 First point.
v2 Second point.
epsilon Two points will be considered equal if each component is within epsilon units. Defaults to CHAI_SMALL.
Returns:
Return whether the two vectors represent the same point.

cMatrix3d cIdentity3d ( void   )  [inline]

Return the Identity Matrix

Returns:
Return the identity matrix.

cMatrix3d cInv ( const cMatrix3d a_matrix  )  [inline]

Compute the inverse of a matrix.

Parameters:
a_matrix Input matrix.
Returns:
Returns the inverse of the input matrix.

template<class T>
T cLerp ( const double &  a_level,
const T &  a_value1,
const T &  a_value2 
) [inline]

Linear interpolation from value0 (when a=0) to value1 (when a=1).

Parameters:
a_level Interpolation parameter.
a_value1 First value.
a_value2 Second value.
Returns:
Return an interpolated result: (1-a_level) * a_value1 + a_level * a_value2

template<class T>
T cMax ( const T  a_value1,
const T  a_value2 
) [inline]

Compute maximum between two values

Parameters:
a_value1 First value.
a_value2 Second value.
Returns:
Return maximum of a_value1 and a_value2.
Note that this function should _not_ be modified to take inputs by reference.

template<class T>
T cMax3 ( const T &  a_value1,
const T &  a_value2,
const T &  a_value3 
) [inline]

Compute maximum of 3 values.

Parameters:
a_value1 First value.
a_value2 Second value.
a_value3 Third value.
Returns:
Return maximum of a_value1, a_value2 and a_value3.

template<class T>
T cMax3Abs ( const T &  a_value1,
const T &  a_value2,
const T &  a_value3 
) [inline]

Compute maximum of absolute values of 3 values.

Parameters:
a_value1 First value.
a_value2 Second value.
a_value3 Third value.
Returns:
Return max(abs(p), abs(q), abs(r)).

template<class T>
T cMaxAbs ( const T  a_value1,
const T  a_value2 
) [inline]

Compute maximum of absolute values of 2 numbers.

Parameters:
a_value1 First value.
a_value2 Second value.
Returns:
Return max(abs(p), abs(q)).
Note that this function should _not_ be modified to take inputs by reference.

template<class T>
T cMin ( const T  a_value1,
const T  a_value2 
) [inline]

Compute minimum between two values

Parameters:
a_value1 First value.
a_value2 Second value.
Returns:
Return maximum of a_value1 and a_value2.
Note that this function should _not_ be modified to take inputs by reference.

template<class T>
T cMin3 ( const T &  a_value1,
const T &  a_value2,
const T &  a_value3 
) [inline]

Return minimum of 3 values.

Parameters:
a_value1 First value.
a_value2 Second value.
a_value3 Third value.
Returns:
Return minimum of a_value1, a_value2 and a_value3.

template<class T>
T cMin3Abs ( const T &  a_value1,
const T &  a_value2,
const T &  a_value3 
) [inline]

Compute minimum of absolute values of 3 values.

Parameters:
a_value1 First value.
a_value2 Second value.
a_value3 Third value.
Returns:
Return min(abs(p), abs(q), abs(r)).

template<class T>
T cMinAbs ( const T  a_value1,
const T  a_value2 
) [inline]

Compute minimum of absolute values of 2 values.

Parameters:
a_value1 First value.
a_value2 Second value.
Returns:
Return min(abs(p), abs(q)).
Note that this function should _not_ be modified to take inputs by reference.

cVector3d cMul ( const cMatrix3d a_matrix,
const cVector3d a_vector 
) [inline]

Compute the multiplication of a matrix and a vector.

Parameters:
a_matrix Input matrix.
a_vector Input vector.
Returns:
Returns the multiplication of the matrix and vector.

cMatrix3d cMul ( const cMatrix3d a_matrix1,
const cMatrix3d a_matrix2 
) [inline]

Compute the multiplication between two matrices.

Parameters:
a_matrix1 First matrix.
a_matrix2 Second matrix.
Returns:
Returns multiplication of /e matrix1 * /e matrix2.

cVector3d cMul ( const double &  a_value,
const cVector3d a_vector 
) [inline]

Multiply a vector by a scalar.

Parameters:
a_value Scalar.
a_vector Input vector.
Returns:
Returns result of multiplication.

cVector3d cNegate ( const cVector3d a_vector  )  [inline]

Compute the negated vector of a input vector.

Parameters:
a_vector Input vector.
Returns:
Return (-a_vector).

cVector3d cNormalize ( const cVector3d a_vector  )  [inline]

Compute the normalized vector (length = 1) of an input vector.

Parameters:
a_vector Input vector.
Returns:
Returns the normalized vector.

bool cPositiveBound ( const double &  a_value,
const double &  a_boundMax 
) [inline]

Check if value is strictly positive and less than maxBound in case maxBound is positive.

Parameters:
a_value Value to be checked.
a_boundMax Positive bound.
Returns:
Return true if value is greater than 0 and either maxBound is negative, or value is less thanmaxBound. Otherwise return false.

cVector3d cProject ( const cVector3d a_vector0,
const cVector3d a_vector1 
) [inline]

Project a vector V0 onto a second vector V1.

Parameters:
a_vector0 Vector 0.
a_vector1 Vector 1.
Returns:
Returns the projection of a_point on the line.

cVector3d cProjectPointOnLine ( const cVector3d a_point,
const cVector3d a_pointOnLine,
const cVector3d a_directionOfLine 
) [inline]

Compute the projection of a point on a line. the line is expressed by a point located on the line and a direction vector.

Parameters:
a_point Point to project on the line.
a_pointOnLine Point located on the line
a_directionOfLine Vector expressing the direction of the line
Returns:
Returns the projection of a_point on the line.

cVector3d cProjectPointOnPlane ( const cVector3d a_point,
const cVector3d a_planePoint0,
const cVector3d a_planePoint1,
const cVector3d a_planePoint2 
) [inline]

Compute the projection of a point on a plane. the plane is expressed by a set of three points.

Parameters:
a_point Point to project on plane.
a_planePoint0 Point 0 on plane.
a_planePoint1 Point 1 on plane.
a_planePoint2 Point 2 on plane.
Returns:
Returns the projection of a_point on plane.

cVector3d cProjectPointOnPlane ( const cVector3d a_point,
const cVector3d a_planePoint,
const cVector3d n 
) [inline]

Compute the projection of a point on a plane. the plane is expressed by a point and a surface normal.

Parameters:
a_point Point to project on plane.
a_planePoint Point on plane.
n Plane normal.
Returns:
Returns the projection of a_point on plane.

double cRadToDeg ( const double &  a_angleRad  )  [inline]

Convert an angle from radians to degrees

Parameters:
a_angleRad Angle in radians.
Returns:
Return angle in degrees.

cMatrix3d cRotate ( const cMatrix3d a_matrix,
const cVector3d a_axis,
const double &  a_angleRad 
) [inline]

Compute the rotation of a matrix around an axis and an angle.

Parameters:
a_matrix Input matrix.
a_axis Axis of rotation.
a_angleRad Rotation angle in Radian.
Returns:
Returns input matrix after rotation.

cMatrix3d cRotMatrix ( const cVector3d a_axis,
const double &  a_angleRad 
) [inline]

Compute a rotation matrix given a rotation axis and an angle.

Parameters:
a_axis Axis of rotation.
a_angleRad Rotation angle in Radian.
Returns:
Returns a rotation matrix.

double cSinDeg ( const double &  a_angleDeg  )  [inline]

Compute the sine of an angle defined in degrees.

Parameters:
a_angleDeg Angle in degrees.
Returns:
Return the sine of angle.

double cSinRad ( const double &  a_value  )  [inline]

Return the sine of an angle defined in radians.

Parameters:
a_value Angle in radians.
Returns:
Return the sine of angle a_value.

double cSqr ( const double &  a_value  )  [inline]

Compute the square of a double.

Parameters:
a_value Input value.
Returns:
Return (/e value * /e value).

cVector3d cSub ( const cVector3d a_vector1,
const cVector3d a_vector2 
) [inline]

Compute the subtraction between two vectors. Result = Vector1 - Vector2.

Parameters:
a_vector1 First vector.
a_vector2 Second vector.
Returns:
Return result of subtraction.

template<class T>
void cSwap ( T &  a_value1,
T &  a_value2 
) [inline]

Swap two elements.

Parameters:
a_value1 First value.
a_value2 Second value.

double cTanDeg ( const double &  a_angleDeg  )  [inline]

Compute the tangent of an angle defined in degrees.

Parameters:
a_angleDeg Angle in degrees.
Returns:
Return the tangent of angle.

double cTanRad ( const double &  a_value  )  [inline]

Return the tangent of an angle defined in radians.

Parameters:
a_value Angle in radians.
Returns:
Return the tangent of angle a_value.

cMatrix3d cTrans ( const cMatrix3d a_matrix  )  [inline]

Compute the transpose of a matrix

Parameters:
a_matrix Input matrix.
Returns:
Returns the transpose of the input matrix.

bool cZero ( const double &  a_value  )  [inline]

Check if value is equal or near zero.

Parameters:
a_value Value to be checked.
Returns:
Returns true if it's almost zero, otherwise false.


Generated on Mon Jun 11 09:41:46 2007 for CHAI 3D by  doxygen 1.5.2