Table of Contents

Class MatrixHelper

Namespace
HelixToolkit.Maths
Assembly
HelixToolkit.Maths.dll

Represents a 4x4 mathematical matrix.

public static class MatrixHelper
Inheritance
MatrixHelper
Inherited Members

Fields

Identity

The identity Matrix4x4.

public static readonly Matrix4x4 Identity

Field Value

Matrix4x4

SizeInBytes

The size of the Matrix4x4 type, in bytes.

public static readonly uint SizeInBytes

Field Value

uint

Zero

A Matrix4x4 with all of its components set to zero.

public static readonly Matrix4x4 Zero

Field Value

Matrix4x4

Methods

AffineTransformation(float, Quaternion, Vector3)

Creates a 3D affine transformation matrix.

public static Matrix4x4 AffineTransformation(float scaling, Quaternion rotation, Vector3 translation)

Parameters

scaling float

Scaling factor.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

Returns

Matrix4x4

The created affine transformation matrix.

AffineTransformation(float, ref Quaternion, ref Vector3, out Matrix4x4)

Creates a 3D affine transformation matrix.

public static void AffineTransformation(float scaling, ref Quaternion rotation, ref Vector3 translation, out Matrix4x4 result)

Parameters

scaling float

Scaling factor.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created affine transformation matrix.

AffineTransformation(float, Vector3, Quaternion, Vector3)

Creates a 3D affine transformation matrix.

public static Matrix4x4 AffineTransformation(float scaling, Vector3 rotationCenter, Quaternion rotation, Vector3 translation)

Parameters

scaling float

Scaling factor.

rotationCenter Vector3

The center of the rotation.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

Returns

Matrix4x4

The created affine transformation matrix.

AffineTransformation(float, ref Vector3, ref Quaternion, ref Vector3, out Matrix4x4)

Creates a 3D affine transformation matrix.

public static void AffineTransformation(float scaling, ref Vector3 rotationCenter, ref Quaternion rotation, ref Vector3 translation, out Matrix4x4 result)

Parameters

scaling float

Scaling factor.

rotationCenter Vector3

The center of the rotation.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created affine transformation matrix.

AffineTransformation2D(float, Vector2, float, Vector2)

Creates a 2D affine transformation matrix.

public static Matrix4x4 AffineTransformation2D(float scaling, Vector2 rotationCenter, float rotation, Vector2 translation)

Parameters

scaling float

Scaling factor.

rotationCenter Vector2

The center of the rotation.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

Returns

Matrix4x4

The created affine transformation matrix.

AffineTransformation2D(float, ref Vector2, float, ref Vector2, out Matrix4x4)

Creates a 2D affine transformation matrix.

public static void AffineTransformation2D(float scaling, ref Vector2 rotationCenter, float rotation, ref Vector2 translation, out Matrix4x4 result)

Parameters

scaling float

Scaling factor.

rotationCenter Vector2

The center of the rotation.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created affine transformation matrix.

AffineTransformation2D(float, float, Vector2)

Creates a 2D affine transformation matrix.

public static Matrix4x4 AffineTransformation2D(float scaling, float rotation, Vector2 translation)

Parameters

scaling float

Scaling factor.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

Returns

Matrix4x4

The created affine transformation matrix.

AffineTransformation2D(float, float, ref Vector2, out Matrix4x4)

Creates a 2D affine transformation matrix.

public static void AffineTransformation2D(float scaling, float rotation, ref Vector2 translation, out Matrix4x4 result)

Parameters

scaling float

Scaling factor.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created affine transformation matrix.

Backward(Matrix4x4)

Gets or sets the backward Vector3 of the matrix; that is M31, M32, and M33.

public static Vector3 Backward(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

BillboardLH(Vector3, Vector3, Vector3, Vector3)

Creates a left-handed spherical billboard that rotates around a specified object position.

public static Matrix4x4 BillboardLH(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)

Parameters

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

Returns

Matrix4x4

The created billboard matrix.

BillboardLH(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Matrix4x4)

Creates a left-handed spherical billboard that rotates around a specified object position.

public static void BillboardLH(ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, ref Vector3 cameraForwardVector, out Matrix4x4 result)

Parameters

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

result Matrix4x4

When the method completes, contains the created billboard matrix.

BillboardRH(Vector3, Vector3, Vector3, Vector3)

Creates a right-handed spherical billboard that rotates around a specified object position.

public static Matrix4x4 BillboardRH(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)

Parameters

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

Returns

Matrix4x4

The created billboard matrix.

BillboardRH(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Matrix4x4)

Creates a right-handed spherical billboard that rotates around a specified object position.

public static void BillboardRH(ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, ref Vector3 cameraForwardVector, out Matrix4x4 result)

Parameters

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

result Matrix4x4

When the method completes, contains the created billboard matrix.

Column1(Matrix4x4)

Gets or sets the first column in the matrix; that is M11, M21, M31, and M41.

public static Vector4 Column1(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Column2(Matrix4x4)

Gets or sets the second column in the matrix; that is M12, M22, M32, and M42.

public static Vector4 Column2(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Column3(Matrix4x4)

Gets or sets the third column in the matrix; that is M13, M23, M33, and M43.

public static Vector4 Column3(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Column4(Matrix4x4)

Gets or sets the fourth column in the matrix; that is M14, M24, M34, and M44.

public static Vector4 Column4(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

DecomposeLQ(Matrix4x4, out Matrix4x4, out Matrix4x4)

Decomposes a matrix into a lower triangular matrix L and an orthonormalized matrix Q.

public static void DecomposeLQ(this Matrix4x4 m, out Matrix4x4 L, out Matrix4x4 Q)

Parameters

m Matrix4x4
L Matrix4x4

When the method completes, contains the lower triangular matrix of the decomposition.

Q Matrix4x4

When the method completes, contains the orthonormalized matrix of the decomposition.

DecomposeQR(Matrix4x4, out Matrix4x4, out Matrix4x4)

Decomposes a matrix into an orthonormalized matrix Q and a right triangular matrix R.

public static void DecomposeQR(this Matrix4x4 m, out Matrix4x4 Q, out Matrix4x4 R)

Parameters

m Matrix4x4
Q Matrix4x4

When the method completes, contains the orthonormalized matrix of the decomposition.

R Matrix4x4

When the method completes, contains the right triangular matrix of the decomposition.

DecomposeUniformScale(Matrix4x4, out float, out Quaternion, out Vector3)

Decomposes a uniform scale matrix into a scale, rotation, and translation. A uniform scale matrix has the same scale in every axis.

public static bool DecomposeUniformScale(this Matrix4x4 m, out float scale, out Quaternion rotation, out Vector3 translation)

Parameters

m Matrix4x4
scale float

When the method completes, contains the scaling component of the decomposed matrix.

rotation Quaternion

When the method completes, contains the rotation component of the decomposed matrix.

translation Vector3

When the method completes, contains the translation component of the decomposed matrix.

Returns

bool

Remarks

This method is designed to decompose only an SRT transformation matrix that has the same scale in every axis.

Down(Matrix4x4)

Gets or sets the down Vector3 of the matrix; that is -M21, -M22, and -M23.

public static Vector3 Down(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

ExchangeColumns(ref Matrix4x4, int, int)

Exchanges two columns in the matrix.

public static void ExchangeColumns(ref Matrix4x4 m, int firstColumn, int secondColumn)

Parameters

m Matrix4x4
firstColumn int

The first column to exchange. This is an index of the column starting at zero.

secondColumn int

The second column to exchange. This is an index of the column starting at zero.

ExchangeRows(ref Matrix4x4, int, int)

Exchanges two rows in the matrix.

public static void ExchangeRows(ref Matrix4x4 m, int firstRow, int secondRow)

Parameters

m Matrix4x4
firstRow int

The first row to exchange. This is an index of the row starting at zero.

secondRow int

The second row to exchange. This is an index of the row starting at zero.

Exponent(Matrix4x4, int)

Performs the exponential operation on a matrix.

public static Matrix4x4 Exponent(Matrix4x4 value, int exponent)

Parameters

value Matrix4x4

The matrix to perform the operation on.

exponent int

The exponent to raise the matrix to.

Returns

Matrix4x4

The exponential matrix.

Exceptions

ArgumentOutOfRangeException

Thrown when the exponent is negative.

Exponent(ref Matrix4x4, int, out Matrix4x4)

Performs the exponential operation on a matrix.

public static void Exponent(ref Matrix4x4 value, int exponent, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to perform the operation on.

exponent int

The exponent to raise the matrix to.

result Matrix4x4

When the method completes, contains the exponential matrix.

Exceptions

ArgumentOutOfRangeException

Thrown when the exponent is negative.

Forward(Matrix4x4)

Gets or sets the forward Vector3 of the matrix; that is -M31, -M32, and -M33.

public static Vector3 Forward(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

Get(Matrix4x4, int)

Gets or sets the component at the specified index.

public static float Get(this Matrix4x4 m, int index)

Parameters

m Matrix4x4
index int

The zero-based index of the component to access.

Returns

float

The value of the matrix component, depending on the index.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is out of the range [0, 15].

Get(Matrix4x4, int, int)

Gets or sets the component at the specified index.

public static float Get(this Matrix4x4 m, int row, int column)

Parameters

m Matrix4x4
row int

The row of the matrix to access.

column int

The column of the matrix to access.

Returns

float

The value of the matrix component, depending on the index.

Exceptions

ArgumentOutOfRangeException

Thrown when the row or columnis out of the range [0, 3].

GetColumn(Matrix4x4, int)

Gets the column. Zero based index. column Index = 0 will get column 1.

public static Vector4 GetColumn(this Matrix4x4 m, int columnIdx)

Parameters

m Matrix4x4

The m.

columnIdx int

Index of the row.

Returns

Vector4

Exceptions

ArgumentException

Column Index out of bound.

GetRow(Matrix4x4, int)

Gets the row. Zero based index. Row Index = 0 will get row 1.

public static Vector4 GetRow(this Matrix4x4 m, int rowIdx)

Parameters

m Matrix4x4

The m.

rowIdx int

Index of the row.

Returns

Vector4

Exceptions

ArgumentException

Row Index out of bound.

Inverted(Matrix4x4)

Return inverted matrix if the operation succeeded. Otherwise, return Identity

public static Matrix4x4 Inverted(this Matrix4x4 matrix)

Parameters

matrix Matrix4x4

Returns

Matrix4x4

Left(Matrix4x4)

Gets or sets the left Vector3 of the matrix; that is -M11, -M12, and -M13.

public static Vector3 Left(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

LookAtLH(Vector3, Vector3, Vector3)

Creates a left-handed, look-at matrix.

public static Matrix4x4 LookAtLH(Vector3 eye, Vector3 target, Vector3 up)

Parameters

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

Returns

Matrix4x4

The created look-at matrix.

LookAtLH(ref Vector3, ref Vector3, ref Vector3, out Matrix4x4)

Creates a left-handed, look-at matrix.

public static void LookAtLH(ref Vector3 eye, ref Vector3 target, ref Vector3 up, out Matrix4x4 result)

Parameters

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

result Matrix4x4

When the method completes, contains the created look-at matrix.

LookAtRH(Vector3, Vector3, Vector3)

Creates a right-handed, look-at matrix.

public static Matrix4x4 LookAtRH(Vector3 eye, Vector3 target, Vector3 up)

Parameters

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

Returns

Matrix4x4

The created look-at matrix.

LookAtRH(ref Vector3, ref Vector3, ref Vector3, out Matrix4x4)

Creates a right-handed, look-at matrix.

public static void LookAtRH(ref Vector3 eye, ref Vector3 target, ref Vector3 up, out Matrix4x4 result)

Parameters

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

result Matrix4x4

When the method completes, contains the created look-at matrix.

LowerTriangularForm(Matrix4x4)

Brings the matrix into lower triangular form using elementary row operations.

public static Matrix4x4 LowerTriangularForm(Matrix4x4 value)

Parameters

value Matrix4x4

The matrix to put into lower triangular form.

Returns

Matrix4x4

The lower triangular matrix.

Remarks

If the matrix is not invertible (i.e. its determinant is zero) than the result of this method may produce Single.Nan and Single.Inf values. When the matrix represents a system of linear equations, than this often means that either no solution exists or an infinite number of solutions exist.

LowerTriangularForm(ref Matrix4x4, out Matrix4x4)

Brings the matrix into lower triangular form using elementary row operations.

public static void LowerTriangularForm(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to put into lower triangular form.

result Matrix4x4

When the method completes, contains the lower triangular matrix.

Remarks

If the matrix is not invertible (i.e. its determinant is zero) than the result of this method may produce Single.Nan and Single.Inf values. When the matrix represents a system of linear equations, than this often means that either no solution exists or an infinite number of solutions exist.

Negate(ref Matrix4x4, out Matrix4x4)

Negates a matrix.

public static void Negate(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to be negated.

result Matrix4x4

When the method completes, contains the negated matrix.

OrthoLH(float, float, float, float)

Creates a left-handed, orthographic projection matrix.

public static Matrix4x4 OrthoLH(float width, float height, float znear, float zfar)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

OrthoLH(float, float, float, float, out Matrix4x4)

Creates a left-handed, orthographic projection matrix.

public static void OrthoLH(float width, float height, float znear, float zfar, out Matrix4x4 result)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

OrthoOffCenterLH(float, float, float, float, float, float)

Creates a left-handed, customized orthographic projection matrix.

public static Matrix4x4 OrthoOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

OrthoOffCenterLH(float, float, float, float, float, float, out Matrix4x4)

Creates a left-handed, customized orthographic projection matrix.

public static void OrthoOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix4x4 result)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

OrthoOffCenterRH(float, float, float, float, float, float)

Creates a right-handed, customized orthographic projection matrix.

public static Matrix4x4 OrthoOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

OrthoOffCenterRH(float, float, float, float, float, float, out Matrix4x4)

Creates a right-handed, customized orthographic projection matrix.

public static void OrthoOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix4x4 result)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

OrthoRH(float, float, float, float)

Creates a right-handed, orthographic projection matrix.

public static Matrix4x4 OrthoRH(float width, float height, float znear, float zfar)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

OrthoRH(float, float, float, float, out Matrix4x4)

Creates a right-handed, orthographic projection matrix.

public static void OrthoRH(float width, float height, float znear, float zfar, out Matrix4x4 result)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

Orthogonalize(Matrix4x4)

Orthogonalizes the specified matrix.

public static Matrix4x4 Orthogonalize(Matrix4x4 value)

Parameters

value Matrix4x4

The matrix to orthogonalize.

Returns

Matrix4x4

The orthogonalized matrix.

Remarks

Orthogonalization is the process of making all rows orthogonal to each other. This means that any given row in the matrix will be orthogonal to any other given row in the matrix.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

Orthogonalize(ref Matrix4x4)

Orthogonalizes the specified matrix.

public static void Orthogonalize(ref Matrix4x4 m)

Parameters

m Matrix4x4

Remarks

Orthogonalization is the process of making all rows orthogonal to each other. This means that any given row in the matrix will be orthogonal to any other given row in the matrix.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

Orthogonalize(ref Matrix4x4, out Matrix4x4)

Orthogonalizes the specified matrix.

public static void Orthogonalize(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to orthogonalize.

result Matrix4x4

When the method completes, contains the orthogonalized matrix.

Remarks

Orthogonalization is the process of making all rows orthogonal to each other. This means that any given row in the matrix will be orthogonal to any other given row in the matrix.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

Orthonormalize(Matrix4x4)

Orthonormalizes the specified matrix.

public static Matrix4x4 Orthonormalize(Matrix4x4 value)

Parameters

value Matrix4x4

The matrix to orthonormalize.

Returns

Matrix4x4

The orthonormalized matrix.

Remarks

Orthonormalization is the process of making all rows and columns orthogonal to each other and making all rows and columns of unit length. This means that any given row will be orthogonal to any other given row and any given column will be orthogonal to any other given column. Any given row will not be orthogonal to any given column. Every row and every column will be of unit length.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

Orthonormalize(ref Matrix4x4)

Orthonormalizes the specified matrix.

public static void Orthonormalize(ref Matrix4x4 m)

Parameters

m Matrix4x4

Remarks

Orthonormalization is the process of making all rows and columns orthogonal to each other and making all rows and columns of unit length. This means that any given row will be orthogonal to any other given row and any given column will be orthogonal to any other given column. Any given row will not be orthogonal to any given column. Every row and every column will be of unit length.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

Orthonormalize(ref Matrix4x4, out Matrix4x4)

Orthonormalizes the specified matrix.

public static void Orthonormalize(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to orthonormalize.

result Matrix4x4

When the method completes, contains the orthonormalized matrix.

Remarks

Orthonormalization is the process of making all rows and columns orthogonal to each other and making all rows and columns of unit length. This means that any given row will be orthogonal to any other given row and any given column will be orthogonal to any other given column. Any given row will not be orthogonal to any given column. Every row and every column will be of unit length.

Because this method uses the modified Gram-Schmidt process, the resulting matrix tends to be numerically unstable. The numeric stability decreases according to the rows so that the first row is the most stable and the last row is the least stable.

This operation is performed on the rows of the matrix rather than the columns. If you wish for this operation to be performed on the columns, first transpose the input and than transpose the output.

PerspectiveFovLH(float, float, float, float)

Creates a left-handed, perspective projection matrix based on a field of view.

public static Matrix4x4 PerspectiveFovLH(float fov, float aspect, float znear, float zfar)

Parameters

fov float

Field of view in the y direction, in radians.

aspect float

Aspect ratio, defined as view space width divided by height.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveFovLH(float, float, float, float, out Matrix4x4)

Creates a left-handed, perspective projection matrix based on a field of view.

public static void PerspectiveFovLH(float fov, float aspect, float znear, float zfar, out Matrix4x4 result)

Parameters

fov float

Field of view in the y direction, in radians.

aspect float

Aspect ratio, defined as view space width divided by height.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PerspectiveFovRH(float, float, float, float)

Creates a right-handed, perspective projection matrix based on a field of view.

public static Matrix4x4 PerspectiveFovRH(float fov, float aspect, float znear, float zfar)

Parameters

fov float

Field of view in the y direction, in radians.

aspect float

Aspect ratio, defined as view space width divided by height.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveFovRH(float, float, float, float, out Matrix4x4)

Creates a right-handed, perspective projection matrix based on a field of view.

public static void PerspectiveFovRH(float fov, float aspect, float znear, float zfar, out Matrix4x4 result)

Parameters

fov float

Field of view in the y direction, in radians.

aspect float

Aspect ratio, defined as view space width divided by height.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PerspectiveLH(float, float, float, float)

Creates a left-handed, perspective projection matrix.

public static Matrix4x4 PerspectiveLH(float width, float height, float znear, float zfar)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveLH(float, float, float, float, out Matrix4x4)

Creates a left-handed, perspective projection matrix.

public static void PerspectiveLH(float width, float height, float znear, float zfar, out Matrix4x4 result)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PerspectiveOffCenterLH(float, float, float, float, float, float)

Creates a left-handed, customized perspective projection matrix.

public static Matrix4x4 PerspectiveOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveOffCenterLH(float, float, float, float, float, float, out Matrix4x4)

Creates a left-handed, customized perspective projection matrix.

public static void PerspectiveOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix4x4 result)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PerspectiveOffCenterRH(float, float, float, float, float, float)

Creates a right-handed, customized perspective projection matrix.

public static Matrix4x4 PerspectiveOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveOffCenterRH(float, float, float, float, float, float, out Matrix4x4)

Creates a right-handed, customized perspective projection matrix.

public static void PerspectiveOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix4x4 result)

Parameters

left float

Minimum x-value of the viewing volume.

right float

Maximum x-value of the viewing volume.

bottom float

Minimum y-value of the viewing volume.

top float

Maximum y-value of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PerspectiveRH(float, float, float, float)

Creates a right-handed, perspective projection matrix.

public static Matrix4x4 PerspectiveRH(float width, float height, float znear, float zfar)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

Returns

Matrix4x4

The created projection matrix.

PerspectiveRH(float, float, float, float, out Matrix4x4)

Creates a right-handed, perspective projection matrix.

public static void PerspectiveRH(float width, float height, float znear, float zfar, out Matrix4x4 result)

Parameters

width float

Width of the viewing volume.

height float

Height of the viewing volume.

znear float

Minimum z-value of the viewing volume.

zfar float

Maximum z-value of the viewing volume.

result Matrix4x4

When the method completes, contains the created projection matrix.

PsudoInvert(Matrix4x4)

Pseudo inversion. Usually use to perform fast view matrix inversion.

public static Matrix4x4 PsudoInvert(this Matrix4x4 viewMatrix)

Parameters

viewMatrix Matrix4x4

Returns

Matrix4x4

PsudoInvert(ref Matrix4x4)

Pseudo inversion. Usually use to perform fast view matrix inversion.

public static Matrix4x4 PsudoInvert(ref Matrix4x4 viewMatrix)

Parameters

viewMatrix Matrix4x4

Returns

Matrix4x4

ReducedRowEchelonForm(ref Matrix4x4, ref Vector4, out Matrix4x4, out Vector4)

Brings the matrix into reduced row echelon form using elementary row operations.

public static void ReducedRowEchelonForm(ref Matrix4x4 value, ref Vector4 augment, out Matrix4x4 result, out Vector4 augmentResult)

Parameters

value Matrix4x4

The matrix to put into reduced row echelon form.

augment Vector4

The fifth column of the matrix.

result Matrix4x4

When the method completes, contains the resultant matrix after the operation.

augmentResult Vector4

When the method completes, contains the resultant fifth column of the matrix.

Remarks

The fifth column is often called the augmented part of the matrix. This is because the fifth column is really just an extension of the matrix so that there is a place to put all of the non-zero components after the operation is complete.

Often times the resultant matrix will the identity matrix or a matrix similar to the identity matrix. Sometimes, however, that is not possible and numbers other than zero and one may appear.

This method can be used to solve systems of linear equations. Upon completion of this method, the augmentResult will contain the solution for the system. It is up to the user to analyze both the input and the result to determine if a solution really exists.

Right(Matrix4x4)

Gets or sets the right Vector3 of the matrix; that is M11, M12, and M13.

public static Vector3 Right(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

RotationAxis(Vector3, float)

Rotations the axis. Angle is radian.

public static Matrix4x4 RotationAxis(Vector3 axis, float angle)

Parameters

axis Vector3

The axis.

angle float

The angle.

Returns

Matrix4x4

RotationX(float)

Rotations the x.Angle is radian.

public static Matrix4x4 RotationX(float angle)

Parameters

angle float

The radian.

Returns

Matrix4x4

RotationY(float)

Rotations the y.Angle is radian.

public static Matrix4x4 RotationY(float angle)

Parameters

angle float

The radian.

Returns

Matrix4x4

RotationZ(float)

Rotations the z.Angle is radian.

public static Matrix4x4 RotationZ(float angle)

Parameters

angle float

The radian.

Returns

Matrix4x4

Row1(Matrix4x4)

Gets or sets the first row in the matrix; that is M11, M12, M13, and M14.

public static Vector4 Row1(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Row2(Matrix4x4)

Gets or sets the second row in the matrix; that is M21, M22, M23, and M24.

public static Vector4 Row2(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Row3(Matrix4x4)

Gets or sets the third row in the matrix; that is M31, M32, M33, and M34.

public static Vector4 Row3(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

Row4(Matrix4x4)

Gets or sets the fourth row in the matrix; that is M41, M42, M43, and M44.

public static Vector4 Row4(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector4

RowEchelonForm(Matrix4x4)

Brings the matrix into row echelon form using elementary row operations;

public static Matrix4x4 RowEchelonForm(Matrix4x4 value)

Parameters

value Matrix4x4

The matrix to put into row echelon form.

Returns

Matrix4x4

When the method completes, contains the row echelon form of the matrix.

RowEchelonForm(ref Matrix4x4, out Matrix4x4)

Brings the matrix into row echelon form using elementary row operations;

public static void RowEchelonForm(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to put into row echelon form.

result Matrix4x4

When the method completes, contains the row echelon form of the matrix.

ScaleVector(Matrix4x4)

Gets or sets the scale of the matrix; that is M11, M22, and M33.

public static Vector3 ScaleVector(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

Scaling(Vector3)

Scalings the specified v.

public static Matrix4x4 Scaling(Vector3 v)

Parameters

v Vector3

The v.

Returns

Matrix4x4

Scaling(Vector3, Vector3)

Scalings the specified v.

public static Matrix4x4 Scaling(Vector3 v, Vector3 center)

Parameters

v Vector3

The v.

center Vector3

The center.

Returns

Matrix4x4

Scaling(float)

Scalings the specified scaling.

public static Matrix4x4 Scaling(float scaling)

Parameters

scaling float

The scaling.

Returns

Matrix4x4

Scaling(float, float, float)

Scalings the specified x.

public static Matrix4x4 Scaling(float x, float y, float z)

Parameters

x float

The x.

y float

The y.

z float

The z.

Returns

Matrix4x4

Set(ref Matrix4x4, int, int, float)

public static void Set(ref Matrix4x4 m, int row, int column, float value)

Parameters

m Matrix4x4
row int
column int
value float

Set(ref Matrix4x4, int, float)

public static void Set(ref Matrix4x4 m, int index, float value)

Parameters

m Matrix4x4
index int
value float

SetBackward(ref Matrix4x4, ref Vector3)

public static void SetBackward(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetColumn(ref Matrix4x4, int, Vector4)

Sets the column by index. Index 0 sets column 1;

public static void SetColumn(ref Matrix4x4 m, int columnIdx, Vector4 value)

Parameters

m Matrix4x4

The m.

columnIdx int

Index of the column.

value Vector4

The value.

Exceptions

ArgumentException

Column Index out of bound.

SetColumn1(ref Matrix4x4, Vector4)

public static void SetColumn1(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn1(ref Matrix4x4, ref Vector4)

public static void SetColumn1(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn2(ref Matrix4x4, Vector4)

public static void SetColumn2(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn2(ref Matrix4x4, ref Vector4)

public static void SetColumn2(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn3(ref Matrix4x4, Vector4)

public static void SetColumn3(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn3(ref Matrix4x4, ref Vector4)

public static void SetColumn3(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn4(ref Matrix4x4, Vector4)

public static void SetColumn4(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetColumn4(ref Matrix4x4, ref Vector4)

public static void SetColumn4(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetDown(ref Matrix4x4, ref Vector3)

public static void SetDown(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetForward(ref Matrix4x4, ref Vector3)

public static void SetForward(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetLeft(ref Matrix4x4, ref Vector3)

public static void SetLeft(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetRight(ref Matrix4x4, ref Vector3)

public static void SetRight(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetRow(ref Matrix4x4, int, Vector4)

Sets the row by index. Index 0 sets row 1.

public static void SetRow(ref Matrix4x4 m, int rowIdx, Vector4 value)

Parameters

m Matrix4x4

The m.

rowIdx int

Index of the row.

value Vector4

The value.

Exceptions

ArgumentException

Row Index out of bound.

SetRow1(ref Matrix4x4, Vector4)

public static void SetRow1(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow1(ref Matrix4x4, ref Vector4)

public static void SetRow1(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow2(ref Matrix4x4, Vector4)

public static void SetRow2(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow2(ref Matrix4x4, ref Vector4)

public static void SetRow2(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow3(ref Matrix4x4, Vector4)

public static void SetRow3(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow3(ref Matrix4x4, ref Vector4)

public static void SetRow3(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow4(ref Matrix4x4, Vector4)

public static void SetRow4(ref Matrix4x4 m, Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetRow4(ref Matrix4x4, ref Vector4)

public static void SetRow4(ref Matrix4x4 m, ref Vector4 value)

Parameters

m Matrix4x4
value Vector4

SetScaleVector(ref Matrix4x4, ref Vector3)

public static void SetScaleVector(ref Matrix4x4 m, ref Vector3 value)

Parameters

m Matrix4x4
value Vector3

SetUp(ref Matrix4x4, ref Vector3)

public static void SetUp(ref Matrix4x4 m, ref Vector3 up)

Parameters

m Matrix4x4
up Vector3

Skew(float, ref Vector3, ref Vector3, out Matrix4x4)

Creates a skew/shear matrix by means of a translation vector, a rotation vector, and a rotation angle. shearing is performed in the direction of translation vector, where translation vector and rotation vector define the shearing plane. The effect is such that the skewed rotation vector has the specified angle with rotation itself.

public static void Skew(float angle, ref Vector3 rotationVec, ref Vector3 transVec, out Matrix4x4 matrix)

Parameters

angle float

The rotation angle.

rotationVec Vector3

The rotation vector

transVec Vector3

The translation vector

matrix Matrix4x4

Contains the created skew/shear matrix.

SmoothStep(Matrix4x4, Matrix4x4, float)

Performs a cubic interpolation between two matrices.

public static Matrix4x4 SmoothStep(Matrix4x4 start, Matrix4x4 end, float amount)

Parameters

start Matrix4x4

Start matrix.

end Matrix4x4

End matrix.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Matrix4x4

The cubic interpolation of the two matrices.

SmoothStep(ref Matrix4x4, ref Matrix4x4, float, out Matrix4x4)

Performs a cubic interpolation between two matrices.

public static void SmoothStep(ref Matrix4x4 start, ref Matrix4x4 end, float amount, out Matrix4x4 result)

Parameters

start Matrix4x4

Start matrix.

end Matrix4x4

End matrix.

amount float

Value between 0 and 1 indicating the weight of end.

result Matrix4x4

When the method completes, contains the cubic interpolation of the two matrices.

ToArray(Matrix4x4)

Creates an array containing the elements of the matrix.

public static float[] ToArray(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

float[]

A sixteen-element array containing the components of the matrix.

Transformation(Vector3, Quaternion, Vector3, Vector3, Quaternion, Vector3)

Creates a transformation matrix.

public static Matrix4x4 Transformation(Vector3 scalingCenter, Quaternion scalingRotation, Vector3 scaling, Vector3 rotationCenter, Quaternion rotation, Vector3 translation)

Parameters

scalingCenter Vector3

Center point of the scaling operation.

scalingRotation Quaternion

Scaling rotation amount.

scaling Vector3

Scaling factor.

rotationCenter Vector3

The center of the rotation.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

Returns

Matrix4x4

The created transformation matrix.

Transformation(ref Vector3, ref Quaternion, ref Vector3, ref Vector3, ref Quaternion, ref Vector3, out Matrix4x4)

Creates a transformation matrix.

public static void Transformation(ref Vector3 scalingCenter, ref Quaternion scalingRotation, ref Vector3 scaling, ref Vector3 rotationCenter, ref Quaternion rotation, ref Vector3 translation, out Matrix4x4 result)

Parameters

scalingCenter Vector3

Center point of the scaling operation.

scalingRotation Quaternion

Scaling rotation amount.

scaling Vector3

Scaling factor.

rotationCenter Vector3

The center of the rotation.

rotation Quaternion

The rotation of the transformation.

translation Vector3

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created transformation matrix.

Transformation2D(Vector2, float, Vector2, Vector2, float, Vector2)

Creates a 2D transformation matrix.

public static Matrix4x4 Transformation2D(Vector2 scalingCenter, float scalingRotation, Vector2 scaling, Vector2 rotationCenter, float rotation, Vector2 translation)

Parameters

scalingCenter Vector2

Center point of the scaling operation.

scalingRotation float

Scaling rotation amount.

scaling Vector2

Scaling factor.

rotationCenter Vector2

The center of the rotation.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

Returns

Matrix4x4

The created transformation matrix.

Transformation2D(ref Vector2, float, ref Vector2, ref Vector2, float, ref Vector2, out Matrix4x4)

Creates a 2D transformation matrix.

public static void Transformation2D(ref Vector2 scalingCenter, float scalingRotation, ref Vector2 scaling, ref Vector2 rotationCenter, float rotation, ref Vector2 translation, out Matrix4x4 result)

Parameters

scalingCenter Vector2

Center point of the scaling operation.

scalingRotation float

Scaling rotation amount.

scaling Vector2

Scaling factor.

rotationCenter Vector2

The center of the rotation.

rotation float

The rotation of the transformation.

translation Vector2

The translation factor of the transformation.

result Matrix4x4

When the method completes, contains the created transformation matrix.

Translation(Vector3)

Translations the specified v.

public static Matrix4x4 Translation(Vector3 v)

Parameters

v Vector3

The v.

Returns

Matrix4x4

Translation(float, float, float)

Translations the specified x.

public static Matrix4x4 Translation(float x, float y, float z)

Parameters

x float

The x.

y float

The y.

z float

The z.

Returns

Matrix4x4

Up(Matrix4x4)

Gets or sets the up Vector3 of the matrix; that is M21, M22, and M23.

public static Vector3 Up(this Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Vector3

UpperTriangularForm(Matrix4x4)

Brings the matrix into upper triangular form using elementary row operations.

public static Matrix4x4 UpperTriangularForm(Matrix4x4 value)

Parameters

value Matrix4x4

The matrix to put into upper triangular form.

Returns

Matrix4x4

The upper triangular matrix.

Remarks

If the matrix is not invertible (i.e. its determinant is zero) than the result of this method may produce Single.Nan and Single.Inf values. When the matrix represents a system of linear equations, than this often means that either no solution exists or an infinite number of solutions exist.

UpperTriangularForm(ref Matrix4x4, out Matrix4x4)

Brings the matrix into upper triangular form using elementary row operations.

public static void UpperTriangularForm(ref Matrix4x4 value, out Matrix4x4 result)

Parameters

value Matrix4x4

The matrix to put into upper triangular form.

result Matrix4x4

When the method completes, contains the upper triangular matrix.

Remarks

If the matrix is not invertible (i.e. its determinant is zero) than the result of this method may produce Single.Nan and Single.Inf values. When the matrix represents a system of linear equations, than this often means that either no solution exists or an infinite number of solutions exist.