Struct Matrix3x3
A structure representing 3x3 matrix.
Namespace: ISynergy.Framework.Mathematics
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public struct Matrix3x3
Remarks
The structure incapsulates elements of a 3x3 matrix and provides some operations with it.
Fields
View SourceV00
Row 0 column 0 element of the matrix.
Declaration
public float V00
Field Value
Type | Description |
---|---|
System.Single |
V01
Row 0 column 1 element of the matrix.
Declaration
public float V01
Field Value
Type | Description |
---|---|
System.Single |
V02
Row 0 column 2 element of the matrix.
Declaration
public float V02
Field Value
Type | Description |
---|---|
System.Single |
V10
Row 1 column 0 element of the matrix.
Declaration
public float V10
Field Value
Type | Description |
---|---|
System.Single |
V11
Row 1 column 1 element of the matrix.
Declaration
public float V11
Field Value
Type | Description |
---|---|
System.Single |
V12
Row 1 column 2 element of the matrix.
Declaration
public float V12
Field Value
Type | Description |
---|---|
System.Single |
V20
Row 2 column 0 element of the matrix.
Declaration
public float V20
Field Value
Type | Description |
---|---|
System.Single |
V21
Row 2 column 1 element of the matrix.
Declaration
public float V21
Field Value
Type | Description |
---|---|
System.Single |
V22
Row 2 column 2 element of the matrix.
Declaration
public float V22
Field Value
Type | Description |
---|---|
System.Single |
Properties
View SourceDeterminant
Calculates determinant of the matrix.
Declaration
public readonly float Determinant { get; }
Property Value
Type | Description |
---|---|
System.Single |
Identity
Provides an identity matrix with all diagonal elements set to 1.
Declaration
public static readonly Matrix3x3 Identity { get; }
Property Value
Type | Description |
---|---|
Matrix3x3 |
Methods
View SourceAdd(Matrix3x3, Matrix3x3)
Adds corresponding components of two matrices.
Declaration
public static Matrix3x3 Add(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The matrix to add to. |
Matrix3x3 | matrix2 | The matrix to add to the first matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which components are equal to sum of corresponding components of the two specified matrices. |
Add(Matrix3x3, Single)
Adds specified value to all components of the specified matrix.
Declaration
public static Matrix3x3 Add(Matrix3x3 matrix, float value)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to add value to. |
System.Single | value | Value to add to all components of the specified matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns new matrix with all components equal to corresponding components of the specified matrix increased by the specified value. |
Adjugate()
Calculate adjugate of the matrix, adj(A).
Declaration
public Matrix3x3 Adjugate()
Returns
Type | Description |
---|---|
Matrix3x3 | Returns adjugate of the matrix. |
CreateDiagonal(Vector3)
Creates a diagonal matrix using the specified vector as diagonal elements.
Declaration
public static Matrix3x3 CreateDiagonal(Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Vector to use for diagonal elements of the matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a diagonal matrix. |
CreateFromColumns(Vector3, Vector3, Vector3)
Creates a matrix from 3 columns specified as vectors.
Declaration
public static Matrix3x3 CreateFromColumns(Vector3 column0, Vector3 column1, Vector3 column2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | column0 | First column of the matrix to create. |
Vector3 | column1 | Second column of the matrix to create. |
Vector3 | column2 | Third column of the matrix to create. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix from specified columns. |
CreateFromRows(Vector3, Vector3, Vector3)
Creates a matrix from 3 rows specified as vectors.
Declaration
public static Matrix3x3 CreateFromRows(Vector3 row0, Vector3 row1, Vector3 row2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | row0 | First row of the matrix to create. |
Vector3 | row1 | Second row of the matrix to create. |
Vector3 | row2 | Third row of the matrix to create. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix from specified rows. |
CreateFromYawPitchRoll(Single, Single, Single)
Creates rotation matrix to rotate an object around X, Y and Z axes.
Declaration
public static Matrix3x3 CreateFromYawPitchRoll(float yaw, float pitch, float roll)
Parameters
Type | Name | Description |
---|---|---|
System.Single | yaw | Rotation angle around Y axis in radians. |
System.Single | pitch | Rotation angle around X axis in radians. |
System.Single | roll | Rotation angle around Z axis in radians. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns rotation matrix to rotate an object around all 3 axes. |
Remarks
note
The routine assumes roll-pitch-yaw rotation order, when creating rotation matrix, i.e. an object is first rotated around Z axis, then around X axis and finally around Y axis.
CreateRotationX(Single)
Creates rotation matrix around X axis.
Declaration
public static Matrix3x3 CreateRotationX(float radians)
Parameters
Type | Name | Description |
---|---|---|
System.Single | radians | Rotation angle around X axis in radians. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns rotation matrix to rotate an object around X axis. |
CreateRotationY(Single)
Creates rotation matrix around Y axis.
Declaration
public static Matrix3x3 CreateRotationY(float radians)
Parameters
Type | Name | Description |
---|---|---|
System.Single | radians | Rotation angle around Y axis in radians. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns rotation matrix to rotate an object around Y axis. |
CreateRotationZ(Single)
Creates rotation matrix around Z axis.
Declaration
public static Matrix3x3 CreateRotationZ(float radians)
Parameters
Type | Name | Description |
---|---|---|
System.Single | radians | Rotation angle around Z axis in radians. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns rotation matrix to rotate an object around Z axis. |
Equals(Matrix3x3)
Tests whether the matrix equals to the specified one.
Declaration
public bool Equals(Matrix3x3 matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | The matrix to test equality with. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two matrices are equal or false otherwise. |
Equals(Object)
Tests whether the matrix equals to the specified object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to test equality with. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the matrix equals to the specified object or false otherwise. |
ExtractYawPitchRoll(out Single, out Single, out Single)
Extract rotation angles from the rotation matrix.
Declaration
public void ExtractYawPitchRoll(out float yaw, out float pitch, out float roll)
Parameters
Type | Name | Description |
---|---|---|
System.Single | yaw | Extracted rotation angle around Y axis in radians. |
System.Single | pitch | Extracted rotation angle around X axis in radians. |
System.Single | roll | Extracted rotation angle around Z axis in radians. |
Remarks
note
The routine assumes roll-pitch-yaw rotation order when extracting rotation angle. Using extracted angles with the CreateFromYawPitchRoll(Single, Single, Single) should provide same rotation matrix.
note
The method assumes the provided matrix represent valid rotation matrix.
Sample usage:
// assume we have a rotation matrix created like this
float yaw = 10.0f / 180 * Math.PI;
float pitch = 30.0f / 180 * Math.PI;
float roll = 45.0f / 180 * Math.PI;
Matrix3x3 rotationMatrix = Matrix3x3.CreateFromYawPitchRoll( yaw, pitch, roll );
// ...
// now somewhere in the code you may want to get rotation
// angles back from a matrix assuming same rotation order
float extractedYaw;
float extractedPitch;
float extractedRoll;
rotation.ExtractYawPitchRoll( out extractedYaw, out extractedPitch, out extractedRoll );
GetColumn(Int32)
Get column of the matrix.
Declaration
public Vector3 GetColumn(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Column index to get, [0, 2]. |
Returns
Type | Description |
---|---|
Vector3 | Returns specified column of the matrix as a vector. |
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer hash code. |
GetRow(Int32)
Get row of the matrix.
Declaration
public Vector3 GetRow(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Row index to get, [0, 2]. |
Returns
Type | Description |
---|---|
Vector3 | Returns specified row of the matrix as a vector. |
Inverse()
Calculate inverse of the matrix, A-1.
Declaration
public Matrix3x3 Inverse()
Returns
Type | Description |
---|---|
Matrix3x3 | Returns inverse of the matrix. |
Multiply(Matrix3x3, Matrix3x3)
Multiplies two specified matrices.
Declaration
public static Matrix3x3 Multiply(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | Matrix to multiply. |
Matrix3x3 | matrix2 | Matrix to multiply by. |
Returns
Type | Description |
---|---|
Matrix3x3 | Return new matrix, which the result of multiplication of the two specified matrices. |
Multiply(Matrix3x3, Vector3)
Multiplies specified matrix by the specified vector.
Declaration
public static Vector3 Multiply(Matrix3x3 matrix, Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to multiply by vector. |
Vector3 | vector | Vector to multiply matrix by. |
Returns
Type | Description |
---|---|
Vector3 | Returns new vector which is the result of multiplication of the specified matrix by the specified vector. |
Multiply(Matrix3x3, Single)
Multiplies matrix by the specified factor.
Declaration
public static Matrix3x3 Multiply(Matrix3x3 matrix, float factor)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to multiply. |
System.Single | factor | Factor to multiple the specified matrix by. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns new matrix with all components equal to corresponding components of the specified matrix multiples by the specified factor. |
MultiplySelfByTranspose()
Multiply the matrix by its transposition, A*AT.
Declaration
public Matrix3x3 MultiplySelfByTranspose()
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which is the result of multiplying this matrix by its transposition. |
MultiplyTransposeBySelf()
Multiply transposition of this matrix by itself, AT*A.
Declaration
public Matrix3x3 MultiplyTransposeBySelf()
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which is the result of multiplying this matrix's transposition by itself. |
PseudoInverse()
Calculate pseudo inverse of the matrix, A+.
Declaration
public Matrix3x3 PseudoInverse()
Returns
Type | Description |
---|---|
Matrix3x3 | Returns pseudo inverse of the matrix. |
Remarks
The pseudo inverse of the matrix is calculate through its SVD(out Matrix3x3, out Vector3, out Matrix3x3) as V*E+*UT.
Subtract(Matrix3x3, Matrix3x3)
Subtracts corresponding components of two matrices.
Declaration
public static Matrix3x3 Subtract(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The matrix to subtract from. |
Matrix3x3 | matrix2 | The matrix to subtract from the first matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which components are equal to difference of corresponding components of the two specified matrices. |
SVD(out Matrix3x3, out Vector3, out Matrix3x3)
Calculate Singular Value Decomposition (SVD) of the matrix, such as A=UEVT.
Declaration
public void SVD(out Matrix3x3 u, out Vector3 e, out Matrix3x3 v)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | u | Output parameter which gets 3x3 U matrix. |
Vector3 | e | Output parameter which gets diagonal elements of the E matrix. |
Matrix3x3 | v | Output parameter which gets 3x3 V matrix. |
Remarks
Having components U, E and V the source matrix can be reproduced using below code:
Matrix3x3 source = u * Matrix3x3.Diagonal( e ) * v.Transpose( );
ToArray()
Returns array representation of the matrix.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
System.Single[] | Returns array which contains all elements of the matrix in the row-major order. |
Transpose()
Transpose the matrix, AT.
Declaration
public Matrix3x3 Transpose()
Returns
Type | Description |
---|---|
Matrix3x3 | Return a matrix which equals to transposition of this matrix. |
Operators
View SourceAddition(Matrix3x3, Matrix3x3)
Adds corresponding components of two matrices.
Declaration
public static Matrix3x3 operator +(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The matrix to add to. |
Matrix3x3 | matrix2 | The matrix to add to the first matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which components are equal to sum of corresponding components of the two specified matrices. |
Addition(Matrix3x3, Single)
Adds specified value to all components of the specified matrix.
Declaration
public static Matrix3x3 operator +(Matrix3x3 matrix, float value)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to add value to. |
System.Single | value | Value to add to all components of the specified matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns new matrix with all components equal to corresponding components of the specified matrix increased by the specified value. |
Equality(Matrix3x3, Matrix3x3)
Tests whether two specified matrices are equal.
Declaration
public static bool operator ==(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The left-hand matrix. |
Matrix3x3 | matrix2 | The right-hand matrix. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two matrices are equal or false otherwise. |
Inequality(Matrix3x3, Matrix3x3)
Tests whether two specified matrices are not equal.
Declaration
public static bool operator !=(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The left-hand matrix. |
Matrix3x3 | matrix2 | The right-hand matrix. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two matrices are not equal or false otherwise. |
Multiply(Matrix3x3, Matrix3x3)
Multiplies two specified matrices.
Declaration
public static Matrix3x3 operator *(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | Matrix to multiply. |
Matrix3x3 | matrix2 | Matrix to multiply by. |
Returns
Type | Description |
---|---|
Matrix3x3 | Return new matrix, which the result of multiplication of the two specified matrices. |
Multiply(Matrix3x3, Vector3)
Multiplies specified matrix by the specified vector.
Declaration
public static Vector3 operator *(Matrix3x3 matrix, Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to multiply by vector. |
Vector3 | vector | Vector to multiply matrix by. |
Returns
Type | Description |
---|---|
Vector3 | Returns new vector which is the result of multiplication of the specified matrix by the specified vector. |
Multiply(Matrix3x3, Single)
Multiplies matrix by the specified factor.
Declaration
public static Matrix3x3 operator *(Matrix3x3 matrix, float factor)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix | Matrix to multiply. |
System.Single | factor | Factor to multiple the specified matrix by. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns new matrix with all components equal to corresponding components of the specified matrix multiples by the specified factor. |
Subtraction(Matrix3x3, Matrix3x3)
Subtracts corresponding components of two matrices.
Declaration
public static Matrix3x3 operator -(Matrix3x3 matrix1, Matrix3x3 matrix2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3x3 | matrix1 | The matrix to subtract from. |
Matrix3x3 | matrix2 | The matrix to subtract from the first matrix. |
Returns
Type | Description |
---|---|
Matrix3x3 | Returns a matrix which components are equal to difference of corresponding components of the two specified matrices. |