Struct Matrix3d
Represents a 3x3 matrix containing 3D rotation and scale with double-precision components.
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Matrix3d : IEquatable<Matrix3d>, IFormattable
Constructors
Matrix3d(Matrix4d)
Initializes a new instance of the Matrix3d struct.
Declaration
public Matrix3d(Matrix4d matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix4d | matrix | A Matrix4d to take the upper-left 3x3 from. |
Matrix3d(Vector3d, Vector3d, Vector3d)
Initializes a new instance of the Matrix3d struct.
Declaration
public Matrix3d(Vector3d row0, Vector3d row1, Vector3d row2)
Parameters
Type | Name | Description |
---|---|---|
Vector3d | row0 | Top row of the matrix. |
Vector3d | row1 | Second row of the matrix. |
Vector3d | row2 | Bottom row of the matrix. |
Matrix3d(double, double, double, double, double, double, double, double, double)
Initializes a new instance of the Matrix3d struct.
Declaration
public Matrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Parameters
Type | Name | Description |
---|---|---|
double | m00 | First item of the first row of the matrix. |
double | m01 | Second item of the first row of the matrix. |
double | m02 | Third item of the first row of the matrix. |
double | m10 | First item of the second row of the matrix. |
double | m11 | Second item of the second row of the matrix. |
double | m12 | Third item of the second row of the matrix. |
double | m20 | First item of the third row of the matrix. |
double | m21 | Second item of the third row of the matrix. |
double | m22 | Third item of the third row of the matrix. |
Fields
Identity
The identity matrix.
Declaration
public static readonly Matrix3d Identity
Field Value
Type | Description |
---|---|
Matrix3d |
Row0
First row of the matrix.
Declaration
public Vector3d Row0
Field Value
Type | Description |
---|---|
Vector3d |
Row1
Second row of the matrix.
Declaration
public Vector3d Row1
Field Value
Type | Description |
---|---|
Vector3d |
Row2
Third row of the matrix.
Declaration
public Vector3d Row2
Field Value
Type | Description |
---|---|
Vector3d |
Zero
The zero matrix.
Declaration
public static readonly Matrix3d Zero
Field Value
Type | Description |
---|---|
Matrix3d |
Properties
Column0
Gets the first column of this matrix.
Declaration
public Vector3d Column0 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3d |
Column1
Gets the second column of this matrix.
Declaration
public Vector3d Column1 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3d |
Column2
Gets the third column of this matrix.
Declaration
public Vector3d Column2 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3d |
Determinant
Gets the determinant of this matrix.
Declaration
public readonly double Determinant { get; }
Property Value
Type | Description |
---|---|
double |
Diagonal
Gets or sets the values along the main diagonal of the matrix.
Declaration
public Vector3d Diagonal { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3d |
this[int, int]
Gets or sets the value at a specified row and column.
Declaration
public double 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 |
---|---|
double |
M11
Gets or sets the value at row 1, column 1 of this instance.
Declaration
public double M11 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M12
Gets or sets the value at row 1, column 2 of this instance.
Declaration
public double M12 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M13
Gets or sets the value at row 1, column 3 of this instance.
Declaration
public double M13 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M21
Gets or sets the value at row 2, column 1 of this instance.
Declaration
public double M21 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M22
Gets or sets the value at row 2, column 2 of this instance.
Declaration
public double M22 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M23
Gets or sets the value at row 2, column 3 of this instance.
Declaration
public double M23 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M31
Gets or sets the value at row 3, column 1 of this instance.
Declaration
public double M31 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M32
Gets or sets the value at row 3, column 2 of this instance.
Declaration
public double M32 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
M33
Gets or sets the value at row 3, column 3 of this instance.
Declaration
public double M33 { readonly get; set; }
Property Value
Type | Description |
---|---|
double |
Trace
Gets the trace of the matrix, the sum of the values along the diagonal.
Declaration
public readonly double Trace { get; }
Property Value
Type | Description |
---|---|
double |
Methods
Add(Matrix3d, Matrix3d)
Adds two instances.
Declaration
[Pure]
public static Matrix3d Add(Matrix3d left, Matrix3d right)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The left operand of the addition. |
Matrix3d | right | The right operand of the addition. |
Returns
Type | Description |
---|---|
Matrix3d | A new instance that is the result of the addition. |
Add(in Matrix3d, in Matrix3d, out Matrix3d)
Adds two instances.
Declaration
public static void Add(in Matrix3d left, in Matrix3d right, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The left operand of the addition. |
Matrix3d | right | The right operand of the addition. |
Matrix3d | result | A new instance that is the result of the addition. |
ClearRotation()
Returns a copy of this Matrix3 without rotation.
Declaration
public readonly Matrix3d ClearRotation()
Returns
Type | Description |
---|---|
Matrix3d | The matrix without rotation. |
ClearScale()
Returns a copy of this Matrix3 without scale.
Declaration
public readonly Matrix3d ClearScale()
Returns
Type | Description |
---|---|
Matrix3d | The matrix without scaling. |
CreateFromAxisAngle(Vector3d, double)
Build a rotation matrix from the specified axis/angle rotation.
Declaration
[Pure]
public static Matrix3d CreateFromAxisAngle(Vector3d axis, double angle)
Parameters
Type | Name | Description |
---|---|---|
Vector3d | axis | The axis to rotate about. |
double | angle | Angle in radians to rotate counter-clockwise (looking in the direction of the given axis). |
Returns
Type | Description |
---|---|
Matrix3d | A matrix instance. |
CreateFromAxisAngle(Vector3d, double, out Matrix3d)
Build a rotation matrix from the specified axis/angle rotation.
Declaration
public static void CreateFromAxisAngle(Vector3d axis, double angle, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Vector3d | axis | The axis to rotate about. |
double | angle | Angle in radians to rotate counter-clockwise (looking in the direction of the given axis). |
Matrix3d | result | A matrix instance. |
CreateFromQuaternion(Quaterniond)
Build a rotation matrix from the specified quaternion.
Declaration
[Pure]
public static Matrix3d CreateFromQuaternion(Quaterniond q)
Parameters
Type | Name | Description |
---|---|---|
Quaterniond | q | Quaternion to translate. |
Returns
Type | Description |
---|---|
Matrix3d | A matrix instance. |
CreateFromQuaternion(in Quaterniond, out Matrix3d)
Build a rotation matrix from the specified quaternion.
Declaration
public static void CreateFromQuaternion(in Quaterniond q, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Quaterniond | q | Quaternion to translate. |
Matrix3d | result | Matrix result. |
CreateRotationX(double)
Builds a rotation matrix for a rotation around the x-axis.
Declaration
[Pure]
public static Matrix3d CreateRotationX(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
Matrix3d | The resulting Matrix3d instance. |
CreateRotationX(double, out Matrix3d)
Builds a rotation matrix for a rotation around the x-axis.
Declaration
public static void CreateRotationX(double angle, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Matrix3d | result | The resulting Matrix3d instance. |
CreateRotationY(double)
Builds a rotation matrix for a rotation around the y-axis.
Declaration
[Pure]
public static Matrix3d CreateRotationY(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
Matrix3d | The resulting Matrix3d instance. |
CreateRotationY(double, out Matrix3d)
Builds a rotation matrix for a rotation around the y-axis.
Declaration
public static void CreateRotationY(double angle, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Matrix3d | result | The resulting Matrix3d instance. |
CreateRotationZ(double)
Builds a rotation matrix for a rotation around the z-axis.
Declaration
[Pure]
public static Matrix3d CreateRotationZ(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
Matrix3d | The resulting Matrix3d instance. |
CreateRotationZ(double, out Matrix3d)
Builds a rotation matrix for a rotation around the z-axis.
Declaration
public static void CreateRotationZ(double angle, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The counter-clockwise angle in radians. |
Matrix3d | result | The resulting Matrix3d instance. |
CreateScale(Vector3d)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix3d CreateScale(Vector3d scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3d | scale | Scale factors for the x, y, and z axes. |
Returns
Type | Description |
---|---|
Matrix3d | A scale matrix. |
CreateScale(in Vector3d, out Matrix3d)
Creates a scale matrix.
Declaration
public static void CreateScale(in Vector3d scale, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Vector3d | scale | Scale factors for the x, y, and z axes. |
Matrix3d | result | A scale matrix. |
CreateScale(double)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix3d CreateScale(double scale)
Parameters
Type | Name | Description |
---|---|---|
double | scale | Single scale factor for the x, y, and z axes. |
Returns
Type | Description |
---|---|
Matrix3d | A scale matrix. |
CreateScale(double, out Matrix3d)
Creates a scale matrix.
Declaration
public static void CreateScale(double scale, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
double | scale | Single scale factor for the x, y, and z axes. |
Matrix3d | result | A scale matrix. |
CreateScale(double, double, double)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix3d CreateScale(double x, double y, double z)
Parameters
Type | Name | Description |
---|---|---|
double | x | Scale factor for the x axis. |
double | y | Scale factor for the y axis. |
double | z | Scale factor for the z axis. |
Returns
Type | Description |
---|---|
Matrix3d | A scale matrix. |
CreateScale(double, double, double, out Matrix3d)
Creates a scale matrix.
Declaration
public static void CreateScale(double x, double y, double z, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
double | x | Scale factor for the x axis. |
double | y | Scale factor for the y axis. |
double | z | Scale factor for the z axis. |
Matrix3d | 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 Matrix3d 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 |
---|---|
Matrix3d | 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 Matrix3d)
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 Matrix3d 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. |
Matrix3d | 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(Matrix3d)
Indicates whether the current matrix is equal to another matrix.
Declaration
[Pure]
public readonly bool Equals(Matrix3d other)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | 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
ExtractRotation(bool)
Returns the rotation component of this instance. Quite slow.
Declaration
[Pure]
public readonly Quaterniond 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 |
---|---|
Quaterniond | The rotation. |
ExtractScale()
Returns the scale component of this instance.
Declaration
public readonly Vector3d ExtractScale()
Returns
Type | Description |
---|---|
Vector3d | 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
Invert()
Converts this instance into its inverse.
Declaration
public void Invert()
Invert(Matrix3d)
Calculate the inverse of the given matrix.
Declaration
[Pure]
public static Matrix3d Invert(Matrix3d mat)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | mat | The matrix to invert. |
Returns
Type | Description |
---|---|
Matrix3d | The inverse of the given matrix. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the Matrix4 is singular. |
Invert(in Matrix3d, out Matrix3d)
Calculate the inverse of the given matrix.
Declaration
public static void Invert(in Matrix3d matrix, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | matrix | The matrix to invert. |
Matrix3d | 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 Matrix3d is singular. |
Inverted()
Returns an inverted copy of this instance.
Declaration
public readonly Matrix3d Inverted()
Returns
Type | Description |
---|---|
Matrix3d | 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(Matrix3d, Matrix3d)
Multiplies two instances.
Declaration
[Pure]
public static Matrix3d Mult(Matrix3d left, Matrix3d right)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The left operand of the multiplication. |
Matrix3d | right | The right operand of the multiplication. |
Returns
Type | Description |
---|---|
Matrix3d | A new instance that is the result of the multiplication. |
Mult(in Matrix3d, in Matrix3d, out Matrix3d)
Multiplies two instances.
Declaration
public static void Mult(in Matrix3d left, in Matrix3d right, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The left operand of the multiplication. |
Matrix3d | right | The right operand of the multiplication. |
Matrix3d | 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 Matrix3d Normalized()
Returns
Type | Description |
---|---|
Matrix3d | The normalized copy. |
Swizzle(Matrix3d, int, int, int)
Swizzles a matrix, i.e. switches rows of the matrix.
Declaration
public static Matrix3d Swizzle(Matrix3d mat, int rowForRow0, int rowForRow1, int rowForRow2)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | 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 |
---|---|
Matrix3d | The swizzled matrix. |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | If any of the rows are outside of the range [0, 2]. |
Swizzle(in Matrix3d, int, int, int, out Matrix3d)
Swizzles a matrix, i.e. switches rows of the matrix.
Declaration
public static void Swizzle(in Matrix3d mat, int rowForRow0, int rowForRow1, int rowForRow2, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | 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. |
Matrix3d | 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 Matrix3d 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 |
---|---|
Matrix3d | 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
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 ( |
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 ( |
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 ( |
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
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(Matrix3d)
Calculate the transpose of the given matrix.
Declaration
[Pure]
public static Matrix3d Transpose(Matrix3d mat)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | mat | The matrix to transpose. |
Returns
Type | Description |
---|---|
Matrix3d | The transpose of the given matrix. |
Transpose(in Matrix3d, out Matrix3d)
Calculate the transpose of the given matrix.
Declaration
public static void Transpose(in Matrix3d mat, out Matrix3d result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | mat | The matrix to transpose. |
Matrix3d | result | The result of the calculation. |
Transposed()
Returns a transposed copy of this instance.
Declaration
public readonly Matrix3d Transposed()
Returns
Type | Description |
---|---|
Matrix3d | The transposed copy. |
Operators
operator ==(Matrix3d, Matrix3d)
Compares two instances for equality.
Declaration
[Pure]
public static bool operator ==(Matrix3d left, Matrix3d right)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The first instance. |
Matrix3d | right | The second instance. |
Returns
Type | Description |
---|---|
bool | True, if left equals right; false otherwise. |
operator !=(Matrix3d, Matrix3d)
Compares two instances for inequality.
Declaration
[Pure]
public static bool operator !=(Matrix3d left, Matrix3d right)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | The first instance. |
Matrix3d | right | The second instance. |
Returns
Type | Description |
---|---|
bool | True, if left does not equal right; false otherwise. |
operator *(Matrix3d, Matrix3d)
Matrix multiplication.
Declaration
[Pure]
public static Matrix3d operator *(Matrix3d left, Matrix3d right)
Parameters
Type | Name | Description |
---|---|---|
Matrix3d | left | left-hand operand. |
Matrix3d | right | right-hand operand. |
Returns
Type | Description |
---|---|
Matrix3d | A new Matrix3d which holds the result of the multiplication. |