Imat Module

This module contains functions for doing matrix operations. A matrix can either 2D or 3D and will consist of 9 or 16 elements in a one-dimensional array.

Header to include: imat.h

The Imat structure


Imat *imodMatNew(int dim)
void imodMatDelete(Imat *mat)
void imodMatId(Imat *mat)
void imodMatPrint(Imat *mat)
void imodMatCopy(Imat *fmat, Imat *tomat)
void imodMatMult(Imat *mat2, Imat *mat1, Imat *matout)
void imodMatTrans(Imat *mat, Ipoint *pt)
int imodMatScale(Imat *mat, Ipoint *pt)
int imodMatRot(Imat *mat, double angle, int axis)
int imodMatRotateVector(Imat *mat, double angle, Ipoint *v)
int imodMatFindVector(Imat *mat, double *angle, Ipoint *v)
int imodMatGetNatAngles(Imat *mat, double *x, double *y, double *z)
void imodMatUniqueAngles(double *x, double *y, double *z)
void imodMatUniqueRotationPt(Ipoint *pt)
void imodMatTransform2D(Imat *mat, Ipoint *pt, Ipoint *rpt)
void imodMatTransform3D(Imat *mat, Ipoint *pt, Ipoint *rpt)
void imodMatTransform(Imat *mat, Ipoint *pt, Ipoint *rpt)
Imat *imodMatInverse(Imat *mat)

The Imat structure is described by:

typedef struct imodel_matrix
{
     float *data;
     int   dim;   /* is 2D or 3D */
     int   size;
}Imat;

Imat *imodMatNew(int dim)

Creates a new matrix structure and sets it to the identity matrix.  The input dimension dim can be 2 or 3.  Returns NULL for error.

void imodMatDelete(Imat *mat)

Frees the matrix mat as well as its data member.

void imodMatId(Imat *mat)

Sets the matrix mat to the identity matrix.

void imodMatPrint(Imat *mat)

Prints matrix in imat.

void imodMatCopy(Imat *fmat, Imat *tomat)

Copies matrix fmat to tomat, provided they are the same dimension.

void imodMatMult(Imat *mat2, Imat *mat1, Imat *matout)

Forms the matrix product mat1 x mat2 and places it into matout; i.e., the input arguments are the matrix applied first and the matrix applied second.

void imodMatTrans(Imat *mat, Ipoint *pt)

Adds the translation in pt to the transformation in mat.

int imodMatScale(Imat *mat, Ipoint *pt)

Applies scaling by the factors in pt to the transformation in mat.

int imodMatRot(Imat *mat, double angle, int axis)

Applies rotation by angle in degrees around one axis to the transformation in mat.  For a 3D matrix, axis must be one of b3dX, b3dY, or b3dZ; for a 2D matrix axis is ignored.  Returns 1 for memory error.

int imodMatRotateVector(Imat *mat, double angle, Ipoint *v)

Applies a rotation by angle (in degrees) about the vector v to the matrix in mat.

int imodMatFindVector(Imat *mat, double *angle, Ipoint *v)

Given a rotation matrix mat, finds a single rotation axis described by vector v and the amount of rotation angle about that axis, in degrees.

int imodMatGetNatAngles(Imat *mat, double *x, double *y, double *z)

Given a 3D rotation matrix in mat, finds the angles of rotation about the three axes, in the order Z, Y, X, and returns them in x, y, and z. Returns 1 if the determinant of the matrix is not near zero.  Angles are in degrees.  Calls matrixToAngles then imodMatUniqueAngles to get a unique set of angles with restricted range.

void imodMatUniqueAngles(double *x, double *y, double *z)

Converts the three angles x, y, and z for rotations about the X, Y, and Z axes into a unique set of angles, with x between +/-90 and y and z between +/-180.  Angles are in degrees.  If x is out of bounds, it inverts the sign of z and takes the complement of y.

void imodMatUniqueRotationPt(Ipoint *pt)

Calls imodMatUniqueAngles with the X, Y, and Z angles in the three members of pt.

void imodMatTransform2D(Imat *mat, Ipoint *pt, Ipoint *rpt)

Applies the 2D transformation in matrix mat to the point pt and returns the transformed position in rpt.

void imodMatTransform3D(Imat *mat, Ipoint *pt, Ipoint *rpt)

Applies the 3D transformation in matrix mat to the point pt and returns the transformed position in rpt.

void imodMatTransform(Imat *mat, Ipoint *pt, Ipoint *rpt)

Applies the transformation in matrix mat to the point pt and returns the transformed position in rpt.  mat can be 2D or 3D.

Imat *imodMatInverse(Imat *mat)

Returns the inverse of the matrix mat, or NULL for memory error.