MathEngine
Home Page       Structures       File List       Functions and Macros      

MeMath.h File Reference

Dynamics Toolkit maths helper functions. More...

#include <string.h>
#include <stdio.h>
#include "MePrecision.h"

Functions

MeReal MeVector3AreaOfTriangle (const MeVector3 v1, const MeVector3 v2)
 Calculate area of triangle given one vertex at the origin and other two supplied as arguments. More...

void MeQuaternionFromTM (const MeMatrix4 tm, MeVector4 q)
 Convert rotation matrix of a transformation to a quaternion. More...

void MeQuaternionFiniteRotation (MeVector4 q, const MeVector3 w, const MeReal h)
 Rotate a quaternion. More...

void MeQuaternionForRotation (MeVector4 q, const MeVector3 v1, const MeVector3 v2)
 Calculates quaternion required to rotate v1 into v2; v1 and v2 MUST be normalised. More...

void MeMatrixFPrint (FILE *const file, const MeReal *const A, const int n, const int m, const char *const format)
 Print a matrix to a file with a given format for each element. More...

void MeMatrix3Invert (MeMatrix3 a)
 Replace the matrix m with its inverse. More...

void MeMatrix3InvertTo3x4 (const MeMatrix3 a, MeVector4 inv1, MeVector4 inv2, MeVector4 inv3)
 Find inverse of a and put the results in 3 separate arrays. More...

void MeMatrix3MakeRotationX (const MeReal a, MeMatrix3 m)
 Initialize a 3x3 matrix to be a rotation matrix by a given angle about the X axis. More...

void MeMatrix3MakeRotationY (const MeReal a, MeMatrix3 m)
 Initialize a 3x3 matrix to be a rotation matrix by a given angle about the Y axis. More...

void MeMatrix3MakeRotationZ (const MeReal a, MeMatrix3 m)
 Initialize a 3x3 matrix to be a rotation matrix by a given angle about the Z axis. More...

void MeAccumulateInertiaTensor (MeMatrix4 X_1, MeMatrix3 I_1, MeReal M_1, MeMatrix4 X_2, MeMatrix3 I_2, MeReal M_2, MeMatrix4 *X, MeMatrix3 *I, MeReal *M)
 Combine two inertia tensors and relative centers of mass for a new combined rigid body. More...

MeMathINLINE void MeVectorSetZero (MeReal *const A, const int n)
 Set the first +{n} elements of +{A} to zero. More...

MeMathINLINE void MeVector3Copy (const MeVector3 b, MeVector3 c)
 MeVector3 copy. More...

MeMathINLINE void MeVector3Subtract (const MeVector3 b, const MeVector3 c, MeVector3 a)
 MeVector3 subtraction. More...

MeMathINLINE void MeVector3Add (const MeVector3 b, const MeVector3 c, MeVector3 a)
 MeVector3 addition. More...

MeMathINLINE MeReal MeVector3Dot (const MeVector3 b, const MeVector3 c)
 MeVector3 dot product. More...

MeMathINLINE void MeVector3Cross (const MeVector3 b, const MeVector3 c, MeVector3 a)
 MeVector3 cross product. More...

MeMathINLINE void MeVector3OuterProduct (const MeVector3 b, const MeVector3 c, MeMatrix3 a)
 MeVector3 outer product. More...

MeMathINLINE MeReal MeVector3MagnitudeSqr (const MeVector3 v)
 Return the square of the magnitude of the vector. More...

MeMathINLINE void MeVector3Scale (MeVector3 v, const MeReal a)
 Multiply all elements of a 3 vector by a scalar. More...

MeMathINLINE void MeVector3MultiplyAdd (MeVector3 v, const MeReal a, const MeVector3 v1)
 Add to each element of a 3 vector the corresponding element of another 3 vector multiplied by a scalar. More...

MeMathINLINE void MeVector3Normalize (MeVector3 v)
 Make the given vector unit length. More...

MeMathINLINE void MeVector3MakeOrthogonal (MeVector3 v, const MeVector3 v1)
 Compute a 3 vector orthogonal to another 3 vector. More...

MeMathINLINE void MeVector3PlaneSpace (const MeVector3 n, MeVector3 a, MeVector3 b)
 Make normal 3x1 vectors +{a} and +{b} such that together with the normal 3x1 vector +{n} they form an orthonormal basis. More...

MeMathINLINE void MeVector4Copy (const MeVector4 b, MeVector4 c)
 MeVector4 copy. More...

MeMathINLINE void MeVector4Subtract (const MeVector4 b, const MeVector4 c, MeVector4 a)
 MeVector4 subtraction. More...

MeMathINLINE void MeQuaternionMake (MeVector3 x, MeReal a, MeVector4 q)
 Make a Quaternion (q) given and normalised axis (x) and an angle (a). More...

MeMathINLINE void MeQuaternionToR (const MeVector4 q, MeMatrix3 R)
 Compute a 3x3 rotation matrix +{R} from a 4x1 normalized quaternion +{q}. More...

MeMathINLINE void MeQuaternionToTM (const MeVector4 q, MeMatrix4 tm)
 Convert a quaternion to a rotation matrix. More...

MeMathINLINE void MeQuaternionToD (const MeVector4 q, MeReal D[12])
 Return a 4x3 matrix +{D} corresponding to the 4x1 quaternion +{q} such that m{dq/dt = D * w}, where +{w} is the angular velocity. More...

MeMathINLINE void MeQuaternionWtoDQ (const MeVector4 q, const MeVector3 w, MeVector4 dq)
 Given the angular velocity +{w} and the current quaternion +{q}, return the quaternion derivative +{dq}. More...

MeMathINLINE void MeQuaternionProduct (const MeVector4 p, const MeVector4 q, MeVector4 r)
 Multiplication of quaternions: set m{r = p * q}. More...

MeMathINLINE void MeQuaternionRotateVector3 (MeVector3 vout, const MeVector4 q, const MeVector3 v)
 Rotate a vector using a quaternion. More...

MeMathINLINE void MeMatrix3Copy (const MeMatrix3 B, MeMatrix3 A)
 Matrix_3 Copy: A := B. More...

MeMathINLINE void MeMatrixTranspose (const int n, const int m, const MeReal *const B, MeReal *A)
 Transpose of the n * m matrix B into A. More...

MeMathINLINE void MeMatrixMultiply ( const int p, const int q, const int r, const MeReal *const B, const MeReal *const C, MeReal *A)
 Set m{A=B*C}, where +{A} is p*r, +{B} is p*q, +{C} is q*r. More...

MeMathINLINE void MeMatrixMultiplyT1 ( const int p, const int q, const int r, const MeReal *const B, const MeReal *const C, MeReal *A)
 Set m{A=B^T*C}, where +{A} is p*r, +{B} is q*p, +{C} is q*r. More...

MeMathINLINE void MeMatrix3MakeIdentity (MeMatrix3 tm)
 Make a 3x3 identity matrix. More...

MeMathINLINE void MeMatrix3Transpose (MeMatrix3 A)
 In place (via an internal copy) transpose of the 3x3 matrix +{A}. More...

MeMathINLINE void MeMatrix3CrossFromVector (const MeVector3 a, const MeReal factor, MeVector3 A0, MeVector3 A1, MeVector3 A2)
 Set +{A} to a 3x3 matrix corresponding to the 3x1 vector +{a}, such that m{A*b = a x b} (x is the cross product operator). More...

MeMathINLINE void MeMatrix3MultiplyVector (const MeMatrix3 B, const MeVector3 C, MeVector3 A)
 Multiply a 3x3 matrix by a 3x1 vector. More...

MeMathINLINE void MeMatrix3Subtract (MeMatrix3 B, MeMatrix3 C, MeMatrix3 A)
 Subtract 3x3 matrices. More...

MeMathINLINE void MeMatrix3Add (MeMatrix3 B, MeMatrix3 C, MeMatrix3 A)
 Add 3x3 matrices. More...

MeMathINLINE void MeMatrix3Multiply (const MeMatrix3 B, const MeMatrix3 C, MeMatrix3 A)
 Multiply 3x3 matrixes. More...

MeMathINLINE void MeMatrix3Scale (MeMatrix3 A, const MeReal a)
 Multiply all elements of a 3x3 matrix by a scalar. More...

MeMathINLINE void MeMatrix4MakeIdentityTM (MeMatrix4 tm)
 Make a 4x4 identity matrix. More...

MeMathINLINE void MeMatrix4SetPosition (MeMatrix4 tm, MeReal x, MeReal y, MeReal z)
 Sets position for a MeMatrix4, when interpreted as a transformation matrix. More...

MeMathINLINE void MeMatrix4Copy (const MeMatrix4 B, MeMatrix4 A)
 Matrix_4 Copy. More...

MeMathINLINE void MeMatrix4Transpose (MeMatrix4 A)
 In place (via an internal copy) transpose of the 4x4 matrix +{A}. More...

MeMathINLINE void MeMatrix4Sum (const MeMatrix4 B, const MeMatrix4 C, MeMatrix4 A)
 Matrix_4 Addition. More...

MeMathINLINE void MeMatrix4MultiplyVector (const MeMatrix4 B, const MeVector4 C, MeVector4 A)
 Multiply a 4x4 matrix by a 4x1 vector. More...

MeMathINLINE void MeMatrix4Multiply (const MeMatrix4 B, const MeMatrix4 C, MeMatrix4 A)
 Multiply 4x4 matrixes. More...


Detailed Description

Dynamics Toolkit maths helper functions.


Function Documentation

void MeAccumulateInertiaTensor ( MeMatrix4 X_1,
MeMatrix3 I_1,
MeReal M_1,
MeMatrix4 X_2,
MeMatrix3 I_2,
MeReal M_2,
MeMatrix4 * X,
MeMatrix3 * I,
MeReal * M )

Combine two inertia tensors and relative centers of mass for a new combined rigid body.

This will be extended to Arrays versus pairs. X - CM vector I - Inertial Tensor M - Mass

MeMathINLINE void MeMatrix3Add ( MeMatrix3 B,
MeMatrix3 C,
MeMatrix3 A )

Add 3x3 matrices.

MeMathINLINE void MeMatrix3Copy ( MeMatrix3 B,
MeMatrix3 A )

Matrix_3 Copy: A := B.

MeMathINLINE void MeMatrix3CrossFromVector ( MeVector3 a,
MeReal factor,
MeVector3 A0,
MeVector3 A1,
MeVector3 A2 )

Set +{A} to a 3x3 matrix corresponding to the 3x1 vector +{a}, such that m{A*b = a x b} (x is the cross product operator).

The result is multiplied by +{factor}.

void MeMatrix3Invert ( MeMatrix3 a )

Replace the matrix m with its inverse.

void MeMatrix3InvertTo3x4 ( MeMatrix3 a,
MeVector4 inv1,
MeVector4 inv2,
MeVector4 inv3 )

Find inverse of a and put the results in 3 separate arrays.

MeMathINLINE void MeMatrix3MakeIdentity ( MeMatrix3 tm )

Make a 3x3 identity matrix.

void MeMatrix3MakeRotationX ( MeReal a,
MeMatrix3 m )

Initialize a 3x3 matrix to be a rotation matrix by a given angle about the X axis.

void MeMatrix3MakeRotationY ( MeReal a,
MeMatrix3 m )

Initialize a 3x3 matrix to be a rotation matrix by a given angle about the Y axis.

void MeMatrix3MakeRotationZ ( MeReal a,
MeMatrix3 m )

Initialize a 3x3 matrix to be a rotation matrix by a given angle about the Z axis.

MeMathINLINE void MeMatrix3Multiply ( MeMatrix3 B,
MeMatrix3 C,
MeMatrix3 A )

Multiply 3x3 matrixes.

MeMathINLINE void MeMatrix3MultiplyVector ( MeMatrix3 B,
MeVector3 C,
MeVector3 A )

Multiply a 3x3 matrix by a 3x1 vector.

MeMathINLINE void MeMatrix3Scale ( MeMatrix3 A,
MeReal a )

Multiply all elements of a 3x3 matrix by a scalar.

MeMathINLINE void MeMatrix3Subtract ( MeMatrix3 B,
MeMatrix3 C,
MeMatrix3 A )

Subtract 3x3 matrices.

MeMathINLINE void MeMatrix3Transpose ( MeMatrix3 A )

In place (via an internal copy) transpose of the 3x3 matrix +{A}.

MeMathINLINE void MeMatrix4Copy ( MeMatrix4 B,
MeMatrix4 A )

Matrix_4 Copy.

MeMathINLINE void MeMatrix4MakeIdentityTM ( MeMatrix4 tm )

Make a 4x4 identity matrix.

MeMathINLINE void MeMatrix4Multiply ( MeMatrix4 B,
MeMatrix4 C,
MeMatrix4 A )

Multiply 4x4 matrixes.

MeMathINLINE void MeMatrix4MultiplyVector ( MeMatrix4 B,
MeVector4 C,
MeVector4 A )

Multiply a 4x4 matrix by a 4x1 vector.

MeMathINLINE void MeMatrix4SetPosition ( MeMatrix4 tm,
MeReal x,
MeReal y,
MeReal z )

Sets position for a MeMatrix4, when interpreted as a transformation matrix.

MeMathINLINE void MeMatrix4Sum ( MeMatrix4 B,
MeMatrix4 C,
MeMatrix4 A )

Matrix_4 Addition.

MeMathINLINE void MeMatrix4Transpose ( MeMatrix4 A )

In place (via an internal copy) transpose of the 4x4 matrix +{A}.

void MeMatrixFPrint ( FILE * const file,
const MeReal * const A,
int n,
int m,
const char * const format )

Print a matrix to a file with a given format for each element.

MeMathINLINE void MeMatrixMultiply ( int p,
int q,
int r,
const MeReal * const B,
const MeReal * const C,
MeReal * A )

Set m{A=B*C}, where +{A} is p*r, +{B} is p*q, +{C} is q*r.

This is an inline function for use on SMALL matrices.

MeMathINLINE void MeMatrixMultiplyT1 ( int p,
int q,
int r,
const MeReal * const B,
const MeReal * const C,
MeReal * A )

Set m{A=B^T*C}, where +{A} is p*r, +{B} is q*p, +{C} is q*r.

This is an inline function for use on SMALL matrices.

MeMathINLINE void MeMatrixTranspose ( int n,
int m,
const MeReal * const B,
MeReal * A )

Transpose of the n * m matrix B into A.

void MeQuaternionFiniteRotation ( MeVector4 q,
MeVector3 w,
MeReal h )

Rotate a quaternion.

void MeQuaternionForRotation ( MeVector4 q,
MeVector3 v1,
MeVector3 v2 )

Calculates quaternion required to rotate v1 into v2; v1 and v2 MUST be normalised.

void MeQuaternionFromTM ( MeMatrix4 tm,
MeVector4 q )

Convert rotation matrix of a transformation to a quaternion.

MeMathINLINE void MeQuaternionMake ( MeVector3 x,
MeReal a,
MeVector4 q )

Make a Quaternion (q) given and normalised axis (x) and an angle (a).

MeMathINLINE void MeQuaternionProduct ( MeVector4 p,
MeVector4 q,
MeVector4 r )

Multiplication of quaternions: set m{r = p * q}.

MeMathINLINE void MeQuaternionRotateVector3 ( MeVector3 vout,
MeVector4 q,
MeVector3 v )

Rotate a vector using a quaternion.

vout=(q0^2-qv^2)v + 2(qv.v)qv + 2q0 qv_cross_v

MeMathINLINE void MeQuaternionToD ( MeVector4 q,
MeReal D[12] )

Return a 4x3 matrix +{D} corresponding to the 4x1 quaternion +{q} such that m{dq/dt = D * w}, where +{w} is the angular velocity.

MeMathINLINE void MeQuaternionToR ( MeVector4 q,
MeMatrix3 R )

Compute a 3x3 rotation matrix +{R} from a 4x1 normalized quaternion +{q}.

MeMathINLINE void MeQuaternionToTM ( MeVector4 q,
MeMatrix4 tm )

Convert a quaternion to a rotation matrix.

MeMathINLINE void MeQuaternionWtoDQ ( MeVector4 q,
MeVector3 w,
MeVector4 dq )

Given the angular velocity +{w} and the current quaternion +{q}, return the quaternion derivative +{dq}.

dq/dt = D * w.

MeMathINLINE void MeVector3Add ( MeVector3 b,
MeVector3 c,
MeVector3 a )

MeVector3 addition.

MeReal MeVector3AreaOfTriangle ( MeVector3 v1,
MeVector3 v2 )

Calculate area of triangle given one vertex at the origin and other two supplied as arguments.

MeMathINLINE void MeVector3Copy ( MeVector3 b,
MeVector3 c )

MeVector3 copy.

MeMathINLINE void MeVector3Cross ( MeVector3 b,
MeVector3 c,
MeVector3 a )

MeVector3 cross product.

MeMathINLINE MeReal MeVector3Dot ( MeVector3 b,
MeVector3 c )

MeVector3 dot product.

MeMathINLINE MeReal MeVector3MagnitudeSqr ( MeVector3 v )

Return the square of the magnitude of the vector.

MeMathINLINE void MeVector3MakeOrthogonal ( MeVector3 v,
MeVector3 v1 )

Compute a 3 vector orthogonal to another 3 vector.

MeMathINLINE void MeVector3MultiplyAdd ( MeVector3 v,
MeReal a,
MeVector3 v1 )

Add to each element of a 3 vector the corresponding element of another 3 vector multiplied by a scalar.

MeMathINLINE void MeVector3Normalize ( MeVector3 v )

Make the given vector unit length.

MeMathINLINE void MeVector3OuterProduct ( MeVector3 b,
MeVector3 c,
MeMatrix3 a )

MeVector3 outer product.

MeMathINLINE void MeVector3PlaneSpace ( MeVector3 n,
MeVector3 a,
MeVector3 b )

Make normal 3x1 vectors +{a} and +{b} such that together with the normal 3x1 vector +{n} they form an orthonormal basis.

+{a} and +{b} span the plane that is normal to +{n}, and +{a} x +{b} = +{n}. Note that if +{n} is not normalized then +{b} will not be normalized either.

MeMathINLINE void MeVector3Scale ( MeVector3 v,
MeReal a )

Multiply all elements of a 3 vector by a scalar.

MeMathINLINE void MeVector3Subtract ( MeVector3 b,
MeVector3 c,
MeVector3 a )

MeVector3 subtraction.

MeMathINLINE void MeVector4Copy ( MeVector4 b,
MeVector4 c )

MeVector4 copy.

MeMathINLINE void MeVector4Subtract ( MeVector4 b,
MeVector4 c,
MeVector4 a )

MeVector4 subtraction.

MeMathINLINE void MeVectorSetZero ( MeReal * const A,
int n )

Set the first +{n} elements of +{A} to zero.


MathEngine Utilities: MathEngine Definitions and Tools - Version 0.0.5 Alpha - Reference Manual generated using doxygen at Wed Oct 11 00:34:59 2000

Copyright MathEngine PLC 2000, all rights reserved.