Show / Hide Table of Contents

Struct Matrix3

Represents a 3x3 matrix containing 3D rotation and scale.

Implements
IEquatable<Matrix3>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Matrix3 : IEquatable<Matrix3>, IFormattable

Constructors

Matrix3(Matrix4)

Initializes a new instance of the Matrix3 struct.

Declaration
public Matrix3(Matrix4 matrix)
Parameters
Type Name Description
Matrix4 matrix

A Matrix4 to take the upper-left 3x3 from.

Matrix3(Vector3, Vector3, Vector3)

Initializes a new instance of the Matrix3 struct.

Declaration
public Matrix3(Vector3 row0, Vector3 row1, Vector3 row2)
Parameters
Type Name Description
Vector3 row0

Top row of the matrix.

Vector3 row1

Second row of the matrix.

Vector3 row2

Bottom row of the matrix.

Matrix3(float, float, float, float, float, float, float, float, float)

Initializes a new instance of the Matrix3 struct.

Declaration
public Matrix3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Parameters
Type Name Description
float m00

First item of the first row of the matrix.

float m01

Second item of the first row of the matrix.

float m02

Third item of the first row of the matrix.

float m10

First item of the second row of the matrix.

float m11

Second item of the second row of the matrix.

float m12

Third item of the second row of the matrix.

float m20

First item of the third row of the matrix.

float m21

Second item of the third row of the matrix.

float m22

Third item of the third row of the matrix.

Fields

Identity

The identity matrix.

Declaration
public static readonly Matrix3 Identity
Field Value
Type Description
Matrix3

Row0

First row of the matrix.

Declaration
public Vector3 Row0
Field Value
Type Description
Vector3

Row1

Second row of the matrix.

Declaration
public Vector3 Row1
Field Value
Type Description
Vector3

Row2

Third row of the matrix.

Declaration
public Vector3 Row2
Field Value
Type Description
Vector3

Zero

The zero matrix.

Declaration
public static readonly Matrix3 Zero
Field Value
Type Description
Matrix3

Properties

Column0

Gets the first column of this matrix.

Declaration
public Vector3 Column0 { readonly get; set; }
Property Value
Type Description
Vector3

Column1

Gets the second column of this matrix.

Declaration
public Vector3 Column1 { readonly get; set; }
Property Value
Type Description
Vector3

Column2

Gets the third column of this matrix.

Declaration
public Vector3 Column2 { readonly get; set; }
Property Value
Type Description
Vector3

Determinant

Gets the determinant of this matrix.

Declaration
public readonly float Determinant { get; }
Property Value
Type Description
float

Diagonal

Gets or sets the values along the main diagonal of the matrix.

Declaration
public Vector3 Diagonal { readonly get; set; }
Property Value
Type Description
Vector3

this[int, int]

Gets or sets the value at a specified row and column.

Declaration
public float this[int rowIndex, int columnIndex] { readonly get; set; }
Parameters
Type Name Description
int rowIndex

The index of the row.

int columnIndex

The index of the column.

Property Value
Type Description
float

The element at the given row and column index.

M11

Gets or sets the value at row 1, column 1 of this instance.

Declaration
public float M11 { readonly get; set; }
Property Value
Type Description
float

M12

Gets or sets the value at row 1, column 2 of this instance.

Declaration
public float M12 { readonly get; set; }
Property Value
Type Description
float

M13

Gets or sets the value at row 1, column 3 of this instance.

Declaration
public float M13 { readonly get; set; }
Property Value
Type Description
float

M21

Gets or sets the value at row 2, column 1 of this instance.

Declaration
public float M21 { readonly get; set; }
Property Value
Type Description
float

M22

Gets or sets the value at row 2, column 2 of this instance.

Declaration
public float M22 { readonly get; set; }
Property Value
Type Description
float

M23

Gets or sets the value at row 2, column 3 of this instance.

Declaration
public float M23 { readonly get; set; }
Property Value
Type Description
float

M31

Gets or sets the value at row 3, column 1 of this instance.

Declaration
public float M31 { readonly get; set; }
Property Value
Type Description
float

M32

Gets or sets the value at row 3, column 2 of this instance.

Declaration
public float M32 { readonly get; set; }
Property Value
Type Description
float

M33

Gets or sets the value at row 3, column 3 of this instance.

Declaration
public float M33 { readonly get; set; }
Property Value
Type Description
float

Trace

Gets the trace of the matrix, the sum of the values along the diagonal.

Declaration
public readonly float Trace { get; }
Property Value
Type Description
float

Methods

Add(Matrix3, Matrix3)

Adds two instances.

Declaration
[Pure]
public static Matrix3 Add(Matrix3 left, Matrix3 right)
Parameters
Type Name Description
Matrix3 left

The left operand of the addition.

Matrix3 right

The right operand of the addition.

Returns
Type Description
Matrix3

A new instance that is the result of the addition.

Add(in Matrix3, in Matrix3, out Matrix3)

Adds two instances.

Declaration
public static void Add(in Matrix3 left, in Matrix3 right, out Matrix3 result)
Parameters
Type Name Description
Matrix3 left

The left operand of the addition.

Matrix3 right

The right operand of the addition.

Matrix3 result

A new instance that is the result of the addition.

ClearRotation()

Returns a copy of this Matrix3 without rotation.

Declaration
public readonly Matrix3 ClearRotation()
Returns
Type Description
Matrix3

The matrix without rotation.

ClearScale()

Returns a copy of this Matrix3 without scale.

Declaration
public readonly Matrix3 ClearScale()
Returns
Type Description
Matrix3

The matrix without scaling.

CreateFromAxisAngle(Vector3, float)

Build a rotation matrix from the specified axis/angle rotation.

Declaration
[Pure]
public static Matrix3 CreateFromAxisAngle(Vector3 axis, float angle)
Parameters
Type Name Description
Vector3 axis

The axis to rotate about.

float angle

Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).

Returns
Type Description
Matrix3

A matrix instance.

CreateFromAxisAngle(Vector3, float, out Matrix3)

Build a rotation matrix from the specified axis/angle rotation.

Declaration
public static void CreateFromAxisAngle(Vector3 axis, float angle, out Matrix3 result)
Parameters
Type Name Description
Vector3 axis

The axis to rotate about.

float angle

Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).

Matrix3 result

A matrix instance.

CreateFromQuaternion(Quaternion)

Build a rotation matrix from the specified quaternion.

Declaration
[Pure]
public static Matrix3 CreateFromQuaternion(Quaternion q)
Parameters
Type Name Description
Quaternion q

Quaternion to translate.

Returns
Type Description
Matrix3

A matrix instance.

CreateFromQuaternion(in Quaternion, out Matrix3)

Build a rotation matrix from the specified quaternion.

Declaration
public static void CreateFromQuaternion(in Quaternion q, out Matrix3 result)
Parameters
Type Name Description
Quaternion q

Quaternion to translate.

Matrix3 result

Matrix result.

CreateRotationX(float)

Builds a rotation matrix for a rotation around the x-axis.

Declaration
[Pure]
public static Matrix3 CreateRotationX(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix3

The resulting Matrix3 instance.

CreateRotationX(float, out Matrix3)

Builds a rotation matrix for a rotation around the x-axis.

Declaration
public static void CreateRotationX(float angle, out Matrix3 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix3 result

The resulting Matrix3 instance.

CreateRotationY(float)

Builds a rotation matrix for a rotation around the y-axis.

Declaration
[Pure]
public static Matrix3 CreateRotationY(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix3

The resulting Matrix3 instance.

CreateRotationY(float, out Matrix3)

Builds a rotation matrix for a rotation around the y-axis.

Declaration
public static void CreateRotationY(float angle, out Matrix3 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix3 result

The resulting Matrix3 instance.

CreateRotationZ(float)

Builds a rotation matrix for a rotation around the z-axis.

Declaration
[Pure]
public static Matrix3 CreateRotationZ(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix3

The resulting Matrix3 instance.

CreateRotationZ(float, out Matrix3)

Builds a rotation matrix for a rotation around the z-axis.

Declaration
public static void CreateRotationZ(float angle, out Matrix3 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix3 result

The resulting Matrix3 instance.

CreateScale(Vector3)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix3 CreateScale(Vector3 scale)
Parameters
Type Name Description
Vector3 scale

Scale factors for the x, y, and z axes.

Returns
Type Description
Matrix3

A scale matrix.

CreateScale(in Vector3, out Matrix3)

Creates a scale matrix.

Declaration
public static void CreateScale(in Vector3 scale, out Matrix3 result)
Parameters
Type Name Description
Vector3 scale

Scale factors for the x, y, and z axes.

Matrix3 result

A scale matrix.

CreateScale(float)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix3 CreateScale(float scale)
Parameters
Type Name Description
float scale

Single scale factor for the x, y, and z axes.

Returns
Type Description
Matrix3

A scale matrix.

CreateScale(float, out Matrix3)

Creates a scale matrix.

Declaration
public static void CreateScale(float scale, out Matrix3 result)
Parameters
Type Name Description
float scale

Single scale factor for the x, y, and z axes.

Matrix3 result

A scale matrix.

CreateScale(float, float, float)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix3 CreateScale(float x, float y, float z)
Parameters
Type Name Description
float x

Scale factor for the x axis.

float y

Scale factor for the y axis.

float z

Scale factor for the z axis.

Returns
Type Description
Matrix3

A scale matrix.

CreateScale(float, float, float, out Matrix3)

Creates a scale matrix.

Declaration
public static void CreateScale(float x, float y, float z, out Matrix3 result)
Parameters
Type Name Description
float x

Scale factor for the x axis.

float y

Scale factor for the y axis.

float z

Scale factor for the z axis.

Matrix3 result

A scale matrix.

CreateSwizzle(int, int, int)

Create a swizzle matrix that can be used to change the row order of matrices.

Declaration
public static Matrix3 CreateSwizzle(int rowForRow0, int rowForRow1, int rowForRow2)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Returns
Type Description
Matrix3

The resulting swizzle matrix.

Remarks

If you are looking to swizzle vectors there are properties like Zyx that can do this more effectively.

CreateSwizzle(int, int, int, out Matrix3)

Create a swizzle matrix that can be used to change the row order of matrices.

Declaration
public static void CreateSwizzle(int rowForRow0, int rowForRow1, int rowForRow2, out Matrix3 result)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Matrix3 result

The resulting swizzle matrix.

Remarks

If you are looking to swizzle vectors there are properties like Zyx that can do this more effectively.

Equals(Matrix3)

Indicates whether the current matrix is equal to another matrix.

Declaration
[Pure]
public readonly bool Equals(Matrix3 other)
Parameters
Type Name Description
Matrix3 other

A matrix to compare with this matrix.

Returns
Type Description
bool

true if the current matrix is equal to the matrix parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

Declaration
[Pure]
public override readonly bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare to.

Returns
Type Description
bool

True if the instances are equal; false otherwise.

Overrides
ValueType.Equals(object)

ExtractRotation(bool)

Returns the rotation component of this instance. Quite slow.

Declaration
public readonly Quaternion ExtractRotation(bool rowNormalize = true)
Parameters
Type Name Description
bool rowNormalize

Whether the method should row-normalize (i.e. remove scale from) the Matrix. Pass false if you know it's already normalized.

Returns
Type Description
Quaternion

The rotation.

ExtractScale()

Returns the scale component of this instance.

Declaration
public readonly Vector3 ExtractScale()
Returns
Type Description
Vector3

The scale components.

GetHashCode()

Returns the hashcode for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int

A System.Int32 containing the unique hashcode for this instance.

Overrides
ValueType.GetHashCode()

Invert()

Converts this instance into its inverse.

Declaration
public void Invert()

Invert(Matrix3)

Calculate the inverse of the given matrix.

Declaration
[Pure]
public static Matrix3 Invert(Matrix3 mat)
Parameters
Type Name Description
Matrix3 mat

The matrix to invert.

Returns
Type Description
Matrix3

The inverse of the given matrix.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix4 is singular.

Invert(in Matrix3, out Matrix3)

Calculate the inverse of the given matrix.

Declaration
public static void Invert(in Matrix3 matrix, out Matrix3 result)
Parameters
Type Name Description
Matrix3 matrix

The matrix to invert.

Matrix3 result

The inverse of the given matrix if it has one, or the input if it is singular.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix3 is singular.

Inverted()

Returns an inverted copy of this instance.

Declaration
public readonly Matrix3 Inverted()
Returns
Type Description
Matrix3

The inverted copy.

Remarks

If the matrix is singular this function does not throw an exception, instead it returns the original un-inverted matrix.

Mult(Matrix3, Matrix3)

Multiplies two instances.

Declaration
[Pure]
public static Matrix3 Mult(Matrix3 left, Matrix3 right)
Parameters
Type Name Description
Matrix3 left

The left operand of the multiplication.

Matrix3 right

The right operand of the multiplication.

Returns
Type Description
Matrix3

A new instance that is the result of the multiplication.

Mult(in Matrix3, in Matrix3, out Matrix3)

Multiplies two instances.

Declaration
public static void Mult(in Matrix3 left, in Matrix3 right, out Matrix3 result)
Parameters
Type Name Description
Matrix3 left

The left operand of the multiplication.

Matrix3 right

The right operand of the multiplication.

Matrix3 result

A new instance that is the result of the multiplication.

Normalize()

Divides each element in the Matrix by the Determinant.

Declaration
public void Normalize()

Normalized()

Returns a normalized copy of this instance.

Declaration
public readonly Matrix3 Normalized()
Returns
Type Description
Matrix3

The normalized copy.

Swizzle(Matrix3, int, int, int)

Swizzles a matrix, i.e. switches rows of the matrix.

Declaration
public static Matrix3 Swizzle(Matrix3 mat, int rowForRow0, int rowForRow1, int rowForRow2)
Parameters
Type Name Description
Matrix3 mat

The matrix to swizzle.

int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Returns
Type Description
Matrix3

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

If any of the rows are outside of the range [0, 2].

Swizzle(in Matrix3, int, int, int, out Matrix3)

Swizzles a matrix, i.e. switches rows of the matrix.

Declaration
public static void Swizzle(in Matrix3 mat, int rowForRow0, int rowForRow1, int rowForRow2, out Matrix3 result)
Parameters
Type Name Description
Matrix3 mat

The matrix to swizzle.

int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Matrix3 result

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

If any of the rows are outside of the range [0, 2].

Swizzle(int, int, int)

Swizzles this instance. Switches places of the rows of the matrix.

Declaration
public void Swizzle(int rowForRow0, int rowForRow1, int rowForRow2)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Swizzled(int, int, int)

Returns a swizzled copy of this instance.

Declaration
public readonly Matrix3 Swizzled(int rowForRow0, int rowForRow1, int rowForRow2)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

Returns
Type Description
Matrix3

The swizzled copy.

ToString()

Returns a System.String that represents the current Matrix3d.

Declaration
public override readonly string ToString()
Returns
Type Description
string

The string representation of the matrix.

Overrides
ValueType.ToString()

ToString(IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
Type Name Description
IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string, IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

Transpose()

Converts this instance into its transpose.

Declaration
public void Transpose()

Transpose(Matrix3)

Calculate the transpose of the given matrix.

Declaration
[Pure]
public static Matrix3 Transpose(Matrix3 mat)
Parameters
Type Name Description
Matrix3 mat

The matrix to transpose.

Returns
Type Description
Matrix3

The transpose of the given matrix.

Transpose(in Matrix3, out Matrix3)

Calculate the transpose of the given matrix.

Declaration
public static void Transpose(in Matrix3 mat, out Matrix3 result)
Parameters
Type Name Description
Matrix3 mat

The matrix to transpose.

Matrix3 result

The result of the calculation.

Transposed()

Returns a transposed copy of this instance.

Declaration
public readonly Matrix3 Transposed()
Returns
Type Description
Matrix3

The transposed copy.

Operators

operator ==(Matrix3, Matrix3)

Compares two instances for equality.

Declaration
[Pure]
public static bool operator ==(Matrix3 left, Matrix3 right)
Parameters
Type Name Description
Matrix3 left

The first instance.

Matrix3 right

The second instance.

Returns
Type Description
bool

True, if left equals right; false otherwise.

operator !=(Matrix3, Matrix3)

Compares two instances for inequality.

Declaration
[Pure]
public static bool operator !=(Matrix3 left, Matrix3 right)
Parameters
Type Name Description
Matrix3 left

The first instance.

Matrix3 right

The second instance.

Returns
Type Description
bool

True, if left does not equal right; false otherwise.

operator *(Matrix3, Matrix3)

Matrix multiplication.

Declaration
[Pure]
public static Matrix3 operator *(Matrix3 left, Matrix3 right)
Parameters
Type Name Description
Matrix3 left

left-hand operand.

Matrix3 right

right-hand operand.

Returns
Type Description
Matrix3

A new Matrix3d which holds the result of the multiplication.

Implements

IEquatable<T>
IFormattable
In this article
Back to top Generated by DocFX