OpenSim::Mtx Class Reference

A class for performing vector and matrix operations. More...

#include <Mtx.h>

List of all members.

Static Public Member Functions

static double Angle (const SimTK::Vec3 &aV1, const SimTK::Vec3 &aV2)
 Find the angle between two vectors: theta = acos( aV1*aV2/(|aV1|*|aV2|)).
static double Normalize (int aN, const SimTK::Vec3 &aV, SimTK::Vec3 &rV)
 Normalize a vector.
static double Magnitude (int aN, const SimTK::Vec3 &aV)
 Compute the magnitude of a vector.
static double DotProduct (int aN, const SimTK::Vec3 &aV1, const SimTK::Vec3 &aV2)
 Compute the dot product of two vectors.
static void CrossProduct (SimTK::Vec3 &aV1, SimTK::Vec3 &aV2, SimTK::Vec3 &aV)
 Compute the cross product of two vectors.
static void PerpendicularUnitVector (SimTK::Vec3 &aV, SimTK::Vec3 &rV)
 Get a unit vector that is perpendicular to a specified vector.
static void Interpolate (int aN, double aT1, double *aY1, double aT2, double *aY2, double t, double *aY)
 Linearly interpolate or extrapolate an array of data.
static double Interpolate (double aT1, double aY1, double aT2, double aY2, double t)
 Linearly interpolate or extrapolate two data points.
static void Translate (double aX, double aY, double aZ, const double aP[3], double rP[3])
 Translate a point by a specified amount.
static void Rotate (int aXYZ, double aRadians, const double aP[3], double rP[3])
 Rotate a point about the X, Y, or Z axis by a specified amount.
static void Rotate (const double aAxis[3], double aRadians, const double aP[3], double rP[3])
 Rotate a point about a specified axis by a specified amount.
static void RotateDeg (int aXYZ, double aDegrees, const double aP[3], double rP[3])
 Rotate a point about the X axis by a specified amount.
static void RotateDeg (const double aAxis[3], double aDegrees, const double aP[3], double rP[3])
 Rotate a point about a specified axis by a specified amount.
static int Identity (int aNR, double *rI)
 Assign a square matrix to the identidy matrix: rI = I.
static int Add (int aNR, int aNC, const double *aM1, const double *aM2, double *aM)
 Assign all elements of a matrix to a specified value: rMij = aScalar.
static int Subtract (int aNR, int aNC, const double *aM1, const double *aM2, double *aM)
 Subtract two matrices.
static int Multiply (int aNR, int aNC, const double *aM, double aScalar, double *rM)
 Multiply a matrix by a scalar.
static int Multiply (int aNR1, int aNCR, int aNC2, const double *aM1, const double *aM2, double *aM)
 Multiply two matrices.
static int Invert (int aN, const double *aM, double *aMInv)
 Compute the inverse of a matrix.
static int Transpose (int aNR, int aNC, const double *aM, double *aMT)
 Transpose a matrix.
static void Print (int aNR, int aNC, const double *aM, int aPrecision=8)
 Print a matrix.
static int FindIndex (int aStartIndex, double aTime, int aNT, double *aT)
 Starting at aIndex, move through the array aT and find the index of the element whose value is closest to but less than aTime.
static int FindIndexLess (int aNX, double *aX, double aValue)
 Scan from the beginning of the array, aX, and find the index of the element such that the element's value is less than or equal to aValue and the next element's value is greater than aValue.
static int FindIndexGreater (int aNX, double *aX, double aValue)
 Scan from the end of the array, aX, and find the index of the element such that the element's value is greater than or equal to aValue and such that the next element's value is less than aValue.
static int ComputeIndex (int i2, int n1, int i1)
 Compute the index for an element of a three dimensional matrix as though the matrix were laid out in one dimension.
static int ComputeIndex (int i3, int n2, int i2, int n1, int i1)
 Compute the index for an element of a three dimensional matrix as though the matrix were laid out in one dimension.
static void GetDim3 (int n3, int n2, int n1, int i2, int i1, double *m, double *a)
 Get elements *,i2,i1 of a three dimensional matrix as an array, where * varies along the 3rd dimension, i2 the 2nd, and i1 the 1st.
static void SetDim3 (int n3, int n2, int n1, int i2, int i1, double *m, double *a)
 Set elements *,i2,i1 of a three dimensional matrix to the values in array a, where * varies along the 3rd dimension, i2 the 2nd, and i1 the 1st.
static int EnsureWorkSpaceCapacity (int aN)
 Ensure that the work space is at least of size aN.
static int EnsurePointerSpaceCapacity (int aN)
 Ensure that the pointer spaces is at least of size aN.
static void FreeWorkAndPointerSpaces ()
 Free the work and pointer spaces.

Detailed Description

A class for performing vector and matrix operations.

Most all the methods in this class are static.


Member Function Documentation

int Mtx::Add ( int  aNR,
int  aNC,
const double *  aM1,
const double *  aM2,
double *  aM 
) [static]

Assign all elements of a matrix to a specified value: rMij = aScalar.

It is permissible for

Parameters:
aNR Number of rows in the matrix.
aNC Number of columns in the matrix.
aScalar Scalar value to which to set the element of the matrix.
rM Ouput matrix (rMij = aScalar for all i,j).
Returns:
0 on success, -1 on error.

int Mtx:: Assign(int aNR,int aNC,double aScalar,double *rM) { if(rM==NULL) return(-1); if(aNR<=0) return(-1); if(aNC<=0) return(-1);

ASSIGN int i,n=aNR*aNC; for(i=0;i<n;i++,rM++) *rM = aScalar;

return(0); } _____________________________________________________________________________ /** Assign two matrices: rM = aM.

Parameters:
aNR Number of rows in the matrices.
aNC Number of columns in the matrices.
aM Input matrix.
rM Ouput matrix (rM = aM).
Returns:
0 on success, -1 on error.

int Mtx:: Assign(int aNR,int aNC,const double *aM,double *rM) { if(aM==NULL) return(-1); if(rM==NULL) return(-1); if(aNR<=0) return(-1); if(aNC<=0) return(-1);

ASSIGN int i,n=aNR*aNC; for(i=0;i<n;i++,aM++,rM++) *rM = *aM;

return(0); } _____________________________________________________________________________ /** Add a scalar to a matrix.

If the arguments are not valid, then a -1 is returned. Othersise, 0 is returned.

It is permissible for aM to coincide with aM1.

int Mtx:: Add(int aNR,int aNC,const double *aM1,double aScalar,double *aM) { if(aM1==NULL) return(-1); if(aM ==NULL) return(-1); if(aNR<=0) return(-1); if(aNC<=0) return(-1);

MULTIPLY int i,n=aNR*aNC; for(i=0;i<n;i++,aM1++,aM++) *aM = *aM1 + aScalar;

return(0); } _____________________________________________________________________________ /** Add two matrices.

If the arguments are not valid, then a -1 is returned. Othersise, 0 is returned.

It is permissible for aM to coincide with either aM1 or aM2.

static double OpenSim::Mtx::Angle ( const SimTK::Vec3 &  aV1,
const SimTK::Vec3 &  aV2 
) [inline, static]

Find the angle between two vectors: theta = acos( aV1*aV2/(|aV1|*|aV2|)).

Parameters:
aV1 Vector 1.
aV2 Vector 2.
Returns:
Angle between two vectors in radians.
int Mtx::ComputeIndex ( int  i3,
int  n2,
int  i2,
int  n1,
int  i1 
) [static]

Compute the index for an element of a three dimensional matrix as though the matrix were laid out in one dimension.

int Mtx::ComputeIndex ( int  i2,
int  n1,
int  i1 
) [static]

Compute the index for an element of a three dimensional matrix as though the matrix were laid out in one dimension.

static void OpenSim::Mtx::CrossProduct ( SimTK::Vec3 &  aV1,
SimTK::Vec3 &  aV2,
SimTK::Vec3 &  aV 
) [inline, static]

Compute the cross product of two vectors.

If the arguments are not valid (aR=aS=NULL), -1 is returned.

static double OpenSim::Mtx::DotProduct ( int  aN,
const SimTK::Vec3 &  aV1,
const SimTK::Vec3 &  aV2 
) [inline, static]

Compute the dot product of two vectors.

If the arguments are not valid (aV1=aV2=NULL), 0.0 is returned.

int Mtx::EnsurePointerSpaceCapacity ( int  aN  )  [static]

Ensure that the pointer spaces is at least of size aN.

If the capacity could not be increased to aN, -1 is returned. Otherwise, 0 is returned.

int Mtx::EnsureWorkSpaceCapacity ( int  aN  )  [static]

Ensure that the work space is at least of size aN.

If the capacity could not be increased to aN, -1 is returned. Otherwise, 0 is returned.

int Mtx::FindIndex ( int  aIndex,
double  aTime,
int  aNT,
double *  aT 
) [static]

Starting at aIndex, move through the array aT and find the index of the element whose value is closest to but less than aTime.

It is assumed that the array aT is monotonically increasing and has at least 2 elements.

If aTime lies outside the interval of aT, the index of either the first point or second to last point is returned depending on whether aTime is below or above the interval of aT.

-1 is if an error is encountered.

int Mtx::FindIndexGreater ( int  aNX,
double *  aX,
double  aValue 
) [static]

Scan from the end of the array, aX, and find the index of the element such that the element's value is greater than or equal to aValue and such that the next element's value is less than aValue.

If no value in the array is less than aValue, the index of the first element in the array is returned.

If no value in the array is greater than or equal to aValue, -1 is returned.

int Mtx::FindIndexLess ( int  aNX,
double *  aX,
double  aValue 
) [static]

Scan from the beginning of the array, aX, and find the index of the element such that the element's value is less than or equal to aValue and the next element's value is greater than aValue.

If no value in the array is greater than aValue, the index of the last element in the array is returned.

If no value in the array is less than or equal to aValue, -1 is returned.

void Mtx::FreeWorkAndPointerSpaces (  )  [static]

Free the work and pointer spaces.

void Mtx::GetDim3 ( int  n3,
int  n2,
int  n1,
int  i2,
int  i1,
double *  m,
double *  a 
) [static]

Get elements *,i2,i1 of a three dimensional matrix as an array, where * varies along the 3rd dimension, i2 the 2nd, and i1 the 1st.

The first dimension is the dimension which varies most rapidly when the data is laid out in a one dimensional array, and the second dimension is the one which varies second most rapidly, and so on.

For now, it is assumed that parameter a has enough memory allocated to hold the array.

int Mtx::Identity ( int  aN,
double *  rI 
) [static]

Assign a square matrix to the identidy matrix: rI = I.

The matrix must be square.

Parameters:
aN Dimension of the matrix (aN=nRows, aN=nCols).
rI Ouput identity matrix (rI = I).
Returns:
0 on success, -1 on error.
double Mtx::Interpolate ( double  aT1,
double  aY1,
double  aT2,
double  aY2,
double  t 
) [static]

Linearly interpolate or extrapolate two data points.

void Mtx::Interpolate ( int  aN,
double  aT1,
double *  aY1,
double  aT2,
double *  aY2,
double  t,
double *  aY 
) [static]

Linearly interpolate or extrapolate an array of data.

int Mtx::Invert ( int  aN,
const double *  aM,
double *  rMInv 
) [static]

Compute the inverse of a matrix.

If the arguments are not valid (aM==NULL), then -1 is returned. If the matrix is not invertible, then -2 is returned. Othersise, 0 is returned.

It is permissible for aM to overlap in memory with aMInv.

static double OpenSim::Mtx::Magnitude ( int  aN,
const SimTK::Vec3 &  aV 
) [inline, static]

Compute the magnitude of a vector.

Parameters:
aV Vector.
Returns:
Square root of the dot product aV*aV.
int Mtx::Multiply ( int  aNR1,
int  aNCR,
int  aNC2,
const double *  aM1,
const double *  aM2,
double *  rM 
) [static]

Multiply two matrices.

If the arguments are not valid (aM1,aM2,aM==NULL), then a -1 is returned. Othersise, 0 is returned.

It is permissible for aM to overlap with either aM1 or aM2.

int Mtx::Multiply ( int  aNR,
int  aNC,
const double *  aM,
double  aScalar,
double *  rM 
) [static]

Multiply a matrix by a scalar.

It is permissible for aM and rM to coincide in memory.

Parameters:
aNR Number of rows in aM.
aNC Number of columns in aM.
aM Matirx laid out in memory as aM[aNR][aNC].
aScalar Scalar value by which to multiply aM.
rM Result of aScalar * aM.
Returns:
-1 if an error is encountered, 0 otherwise.
static double OpenSim::Mtx::Normalize ( int  aN,
const SimTK::Vec3 &  aV,
SimTK::Vec3 &  rV 
) [inline, static]

Normalize a vector.

If aV has a magnitude of zero, all elements of rV are set to 0.0. It is permissible for aV and rV to coincide in memory.

Parameters:
aV Vector to be normalized.
rV Result of the normalization.
Returns:
Magnitude of aV.
static void OpenSim::Mtx::PerpendicularUnitVector ( SimTK::Vec3 &  aV,
SimTK::Vec3 &  rV 
) [inline, static]

Get a unit vector that is perpendicular to a specified vector.

The unit vector is arbitrary, in the sense that it is one of an infinite number of vectors that are perpendicular to the original specified vector.

Parameters:
aV Input vector.
rV Perpendicular unit vector.
void Mtx::Print ( int  aNR,
int  aNC,
const double *  aM,
int  aPrecision = 8 
) [static]

Print a matrix.

void Mtx::Rotate ( const double  aAxis[3],
double  aRadians,
const double  aP[3],
double  rP[3] 
) [static]

Rotate a point about a specified axis by a specified amount.

Parameters:
aAxis Axis about which to rotate. The axis is not assumed to be a unit vector; however, if the axis is the zero vector, no rotation is performed.
aRadians Amount of rotation in radians.
aP Point to rotate.
rP Rotated point. aP and rP may coincide in memory.
void Mtx::Rotate ( int  aXYZ,
double  aRadians,
const double  aP[3],
double  rP[3] 
) [static]

Rotate a point about the X, Y, or Z axis by a specified amount.

Parameters:
aXYZ Specify whether to rotate about the X (aXYZ=0), Y (aXYZ=1), or Z (aXYZ=2) axes. If aXYZ is not 0, 1, or 2, no rotation is performed.
aRadians Amount of rotation in radians.
aP Point to rotate.
rP Rotated point. aP and rP may coincide in memory.
void Mtx::RotateDeg ( const double  aAxis[3],
double  aDegrees,
const double  aP[3],
double  rP[3] 
) [static]

Rotate a point about a specified axis by a specified amount.

Parameters:
aAxis Axis about which to rotate.
aDegrees Amount of rotation in degrees.
aP Point to rotate.
rP Rotated point. aP and rP may coincide in memory.
void Mtx::RotateDeg ( int  aXYZ,
double  aDegrees,
const double  aP[3],
double  rP[3] 
) [static]

Rotate a point about the X axis by a specified amount.

Parameters:
aXYZ Specify whether to rotate about the X (aXYZ=0), Y (aXYZ=1), or Z (aXYZ=2) axis. If aXYZ is not 0, 1, or 2, no rotation is performed.
aDegrees Amount of rotation in degrees.
aP Point to rotate.
rP Rotated point. aP and rP may coincide in memory.
void Mtx::SetDim3 ( int  n3,
int  n2,
int  n1,
int  i2,
int  i1,
double *  m,
double *  a 
) [static]

Set elements *,i2,i1 of a three dimensional matrix to the values in array a, where * varies along the 3rd dimension, i2 the 2nd, and i1 the 1st.

The first dimension is the dimension which varies most rapidly when the data is laid out in a one dimensional array, and the second dimension is the one which varies second most rapidly, and so on.

int Mtx::Subtract ( int  aNR,
int  aNC,
const double *  aM1,
const double *  aM2,
double *  aM 
) [static]

Subtract two matrices.

If the arguments are not valid, then a -1 is returned. Othersise, 0 is returned.

It is permissible for aM to coincide with either aM1 or aM2. aM1 - aM2

void Mtx::Translate ( double  aX,
double  aY,
double  aZ,
const double  aP[3],
double  rP[3] 
) [static]

Translate a point by a specified amount.

Parameters:
aX Amount to translate in the X direction.
aY Amount to translate in the Y direction.
aZ Amount to translate in the Z direction.
aP Point to translate.
rP Translated point. aP and rP may coincide in memory.
int Mtx::Transpose ( int  aNR,
int  aNC,
const double *  aM,
double *  rMT 
) [static]

Transpose a matrix.

If the arguments are invalid (e.g.,aM==NULL), then a -1 is returned. Othersise, 0 is returned.

It is permissible for aM to overlap in memory with aMT.


The documentation for this class was generated from the following files:

Generated on Wed Dec 16 15:03:40 2009 for OpenSim by  doxygen 1.6.1