Matrix Operations

MatrixScaleXYZ

Scales matrix in X (first column), Y(second column) and Z (third column).

This function assumes a [4x4] matrix.

Parameters

Direction Name Type Description
In matIN double* Pointer to matrix [4x4]
Out matOUT double* Pointer to scaled matrix [4x4]
In X double Scale value for the first column
In Y double Scale value for the second column
In Z double Scale value for the third column
Return BOOL Always 0

Usage

unsigned char MatrixScaleXYZ(double* In, double* Out, double X, double Y, double Z);

MatrixScale

Wrapper function around MatrixScaleXYZ that uses the same scale for X, Y, and Z.

This function assumes a [4x4] matrix.

Parameters

Direction Name Type Description
In matIN double* Pointer to matrix [4x4]
Out matOUT double* Pointer to scaled matrix [4x4]
In scale double Scale factor
Return USINT Always 0

Usage

plcbit MatrixScale(double* In, double* Out, double scale);

MatrixScaleX

Function multiplies every element in a matrix of any size by a double scale factor.

Parameters

Direction Name Type Description
In matIN double* Pointer to matrix [RowxCol]
Out matOUT double* Pointer to scaled matrix [RowxCol]
IN scale double Scale factor
In Row INT Number of rows
In Col INT Number of columns
Return BOOL Always 0

Usage

unsigned char MatrixScaleX(double* matIN, double* matOUT, double scale, signed short Row, signed short Col);

MatrixMultiply

Multiply two 4x4 double matrices

Parameters

Direction Name Type Description
In a double* Pointer to first matrix [4x4]
In b double* Pointer to second matrix [4x4]
Out product double* Pointer to calculated matrix [4x4]
Return BOOL Always 0

Usage

plcbit MatrixMultiply(double* a, double* b, double* product);

MatrixMultiplyX

Multiply two size x size double matrices

Parameters

Direction Name Type Description
In a double* Pointer to first matrix [sizexsize]
In b double* Pointer to second matrix [sizexsize]
Out product double* Pointer to calculated matrix [sizexsize]
In size INT Number of rows/cols in the matrices
Return BOOL Always 0

Usage

plcbit MatrixMultiplyX(double* a, double* b, double* product, signed short size);

MatrixMultipyXXX

Multiply two double matrices

  • First matrix is size Row1 x Col1Row2
  • Second matrix is size Col1Row2 x Col
  • product is size Row1 x Col

Parameters

Direction Name Type Description
In a double* Pointer to first matrix [Row1xCol1Row2]
In b double* Pointer to second matrix [Col1Row2xCol]
Out product double* Pointer to calculated matrix [Row1xCol]
In Row1 INT Number of rows in matrix a
In Col1Row2 INT Number of rows in matrix b and columns in a
In Col INT Number of cols in matrix b
Return BOOL Always 0

Usage

plcbit MatrixMultiplyXXX(double* a, double* b, double* product, signed short Row1, signed short Col1Row2, signed short Col);

MatrixIdentitiy

Set a 4x4 matrix to the identity matrix

Parameters

Direction Name Type Description
In a double* Pointer to a matrix [4x4]
Return BOOL Always 0

Usage

plcbit MatrixIdentity(double* a);

MatrixTranspose

Takes the transpose of a RowxCol transformation matrix.

Parameters

Direction Name Type Description
In matrix double* Pointer to matrix [RowxCol]
Out matrixT double* Pointer to transposed matrix [ColxRow]
In Row INT Number of rows in matrix
In Col INT Number of columns in matrix
Return BOOL Always 0

Usage

Trans_Matrix_typ matrix;
Trans_Matrix_typ matrixT;

plcbit MatrixTranspose( (double*) matrix, (double*) matrixT, Row, Col);

MatrixInverse

Takes the inverse of a 4x4 affine transformation matrix.

Parameters

Direction Name Type Description
In In double* Pointer to matrix [4x4]
Out Out double* Pointer to inverted matrix [4x4]
Return BOOL 0 on success, 1 if m * m^-1 != Identity

Usage

Trans_Matrix_typ m;
Trans_Matrix_typ mI;

bool inverseFailed = MatrixInverse( (double*) m, (double*) mI);

MatrixInverseGeneral

Find the inverse of a square matrix of the size Size x Size.

(Slow - not recommended for cyclic operation)

Parameters

Direction Name Type Description
In In double* Pointer to matrix [SizexSize]
In Size UDINT Number of rows/cols in the matrix
Out Out double* Pointer to inverted matrix [SizexSize]
Return BOOL 0 on success, 1 if the determinant is 0

Usage

plcbit MatrixInverseGeneral(double* In, double* Out, unsigned long Size);

PsuedoInverse

Psuedo Inverse using the Moore–Penrose inverse

Parameters

Direction Name Type Description
In a double* Pointer to matrix [rowsxcols] to be inverted
Out aI double* Pointer to inverted matrix [colsxrows]
In rows USINT Number of rows in matrix a
In cols USINT Number of columns in matrix a
Return BOOL Always 0

Usage

plcbit PsuedoInverse(double* a, double* aI, unsigned short rows, unsigned short cols);

SVD

Implementation of the Singular value decomposition function

Parameters

Direction Name Type Description
In a double* Pointer to matrix [rowsxcols]
In rows USINT Number of rows in the matrix
In cols USINT Number of columns in the matrix
In u double* Pointer containing matrix u[rows x cols]
In s double* Pointer containing matrix s[cols x cols]
In v double* Pointer containing matrix v[cols x cols]
Return BOOL Always 0

Usage

plcbit SVD(double* a, unsigned short rows, unsigned short cols, double* u, double* s, double* v);
Made by Loupe