Struct Matrix2d
Represents a 2x2 matrix.
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Matrix2d : IEquatable<Matrix2d>, IFormattable
Constructors
Matrix2d(Vector2d, Vector2d)
Initializes a new instance of the Matrix2d struct.
Declaration
public Matrix2d(Vector2d row0, Vector2d row1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2d | row0 | Top row of the matrix. |
| Vector2d | row1 | Bottom row of the matrix. |
Matrix2d(double, double, double, double)
Initializes a new instance of the Matrix2d struct.
Declaration
public Matrix2d(double m00, double m01, double m10, double m11)
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 | m10 | First item of the second row of the matrix. |
| double | m11 | Second item of the second row of the matrix. |
Fields
Identity
The identity matrix.
Declaration
public static readonly Matrix2d Identity
Field Value
| Type | Description |
|---|---|
| Matrix2d |
Row0
Top row of the matrix.
Declaration
public Vector2d Row0
Field Value
| Type | Description |
|---|---|
| Vector2d |
Row1
Bottom row of the matrix.
Declaration
public Vector2d Row1
Field Value
| Type | Description |
|---|---|
| Vector2d |
Zero
The zero matrix.
Declaration
public static readonly Matrix2d Zero
Field Value
| Type | Description |
|---|---|
| Matrix2d |
Properties
Column0
Gets or sets the first column of this matrix.
Declaration
public Vector2d Column0 { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2d |
Column1
Gets or sets the second column of this matrix.
Declaration
public Vector2d Column1 { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2d |
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 Vector2d Diagonal { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2d |
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 | 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 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 |
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 |
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(Matrix2d, Matrix2d)
Adds two instances.
Declaration
[Pure]
public static Matrix2d Add(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the addition. |
| Matrix2d | right | The right operand of the addition. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new instance that is the result of the addition. |
Add(in Matrix2d, in Matrix2d, out Matrix2d)
Adds two instances.
Declaration
public static void Add(in Matrix2d left, in Matrix2d right, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the addition. |
| Matrix2d | right | The right operand of the addition. |
| Matrix2d | result | A new instance that is the result of the addition. |
CreateRotation(double, out Matrix2d)
Builds a rotation matrix.
Declaration
public static void CreateRotation(double angle, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| double | angle | The counter-clockwise angle in radians. |
| Matrix2d | result | The resulting Matrix2d instance. |
CreateRotation(double)
Builds a rotation matrix.
Declaration
[Pure]
public static Matrix2d CreateRotation(double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| double | angle | The counter-clockwise angle in radians. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The resulting Matrix2d instance. |
CreateScale(Vector2d, out Matrix2d)
Creates a scale matrix.
Declaration
public static void CreateScale(Vector2d scale, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2d | scale | Scale factors for the x and y axes. |
| Matrix2d | result | A scale matrix. |
CreateScale(Vector2d)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix2d CreateScale(Vector2d scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2d | scale | Scale factors for the x and y axes. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A scale matrix. |
CreateScale(double, out Matrix2d)
Creates a scale matrix.
Declaration
public static void CreateScale(double scale, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| double | scale | Single scale factor for the x, y, and z axes. |
| Matrix2d | result | A scale matrix. |
CreateScale(double, double, out Matrix2d)
Creates a scale matrix.
Declaration
public static void CreateScale(double x, double y, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | Scale factor for the x axis. |
| double | y | Scale factor for the y axis. |
| Matrix2d | result | A scale matrix. |
CreateScale(double, double)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix2d CreateScale(double x, double y)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | Scale factor for the x axis. |
| double | y | Scale factor for the y axis. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A scale matrix. |
CreateScale(double)
Creates a scale matrix.
Declaration
[Pure]
public static Matrix2d CreateScale(double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| double | scale | Single scale factor for the x and y axes. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A scale matrix. |
CreateSwizzle(int, int, out Matrix2d)
Create a swizzle matrix that can be used to change the row order of matrices.
Declaration
public static void CreateSwizzle(int rowForRow0, int rowForRow1, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
| Matrix2d | result | The resulting swizzle matrix. |
Remarks
If you are looking to swizzle vectors there are properties like Yx that can do this more effectively.
CreateSwizzle(int, int)
Create a swizzle matrix that can be used to change the row order of matrices.
Declaration
public static Matrix2d CreateSwizzle(int rowForRow0, int rowForRow1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The resulting swizzle matrix. |
Remarks
If you are looking to swizzle vectors there are properties like Yx that can do this more effectively.
Equals(Matrix2d)
Indicates whether the current matrix is equal to another matrix.
Declaration
[Pure]
public readonly bool Equals(Matrix2d other)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | other | An 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
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(Matrix2d)
Calculate the inverse of the given matrix.
Declaration
[Pure]
public static Matrix2d Invert(Matrix2d mat)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to invert. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The inverse of the given matrix. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if the Matrix2d is singular. |
Invert(in Matrix2d, out Matrix2d)
Calculate the inverse of the given matrix.
Declaration
public static void Invert(in Matrix2d mat, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to invert. |
| Matrix2d | 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 Matrix2d is singular. |
Inverted()
Returns an inverted copy of this instance.
Declaration
public readonly Matrix2d Inverted()
Returns
| Type | Description |
|---|---|
| Matrix2d | The inverted copy. |
Mult(Matrix2d, Matrix2d)
Multiplies two instances.
Declaration
[Pure]
public static Matrix2d Mult(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2d | right | The right operand of the multiplication. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new instance that is the result of the multiplication. |
Mult(Matrix2d, Matrix2x3d)
Multiplies two instances.
Declaration
[Pure]
public static Matrix2x3d Mult(Matrix2d left, Matrix2x3d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2x3d | right | The right operand of the multiplication. |
Returns
| Type | Description |
|---|---|
| Matrix2x3d | A new instance that is the result of the multiplication. |
Mult(Matrix2d, Matrix2x4d)
Multiplies two instances.
Declaration
[Pure]
public static Matrix2x4d Mult(Matrix2d left, Matrix2x4d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2x4d | right | The right operand of the multiplication. |
Returns
| Type | Description |
|---|---|
| Matrix2x4d | A new instance that is the result of the multiplication. |
Mult(Matrix2d, double)
Multiplies and instance by a scalar.
Declaration
[Pure]
public static Matrix2d Mult(Matrix2d left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| double | right | The right operand of the multiplication. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new instance that is the result of the multiplication. |
Mult(in Matrix2d, in Matrix2d, out Matrix2d)
Multiplies two instances.
Declaration
public static void Mult(in Matrix2d left, in Matrix2d right, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2d | right | The right operand of the multiplication. |
| Matrix2d | result | A new instance that is the result of the multiplication. |
Mult(in Matrix2d, in Matrix2x3d, out Matrix2x3d)
Multiplies two instances.
Declaration
public static void Mult(in Matrix2d left, in Matrix2x3d right, out Matrix2x3d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2x3d | right | The right operand of the multiplication. |
| Matrix2x3d | result | A new instance that is the result of the multiplication. |
Mult(in Matrix2d, in Matrix2x4d, out Matrix2x4d)
Multiplies two instances.
Declaration
public static void Mult(in Matrix2d left, in Matrix2x4d right, out Matrix2x4d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| Matrix2x4d | right | The right operand of the multiplication. |
| Matrix2x4d | result | A new instance that is the result of the multiplication. |
Mult(in Matrix2d, double, out Matrix2d)
Multiplies and instance by a scalar.
Declaration
public static void Mult(in Matrix2d left, double right, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the multiplication. |
| double | right | The right operand of the multiplication. |
| Matrix2d | result | A new instance that is the result of the multiplication. |
Subtract(Matrix2d, Matrix2d)
Subtracts two instances.
Declaration
[Pure]
public static Matrix2d Subtract(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the subtraction. |
| Matrix2d | right | The right operand of the subtraction. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new instance that is the result of the subtraction. |
Subtract(in Matrix2d, in Matrix2d, out Matrix2d)
Subtracts two instances.
Declaration
public static void Subtract(in Matrix2d left, in Matrix2d right, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The left operand of the subtraction. |
| Matrix2d | right | The right operand of the subtraction. |
| Matrix2d | result | A new instance that is the result of the subtraction. |
Swizzle(Matrix2d, int, int)
Swizzles a matrix, i.e. switches rows of the matrix.
Declaration
public static Matrix2d Swizzle(Matrix2d mat, int rowForRow0, int rowForRow1)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to swizzle. |
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The swizzled matrix. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If any of the rows are outside of the range [0, 1]. |
Swizzle(in Matrix2d, int, int, out Matrix2d)
Swizzles a matrix, i.e. switches rows of the matrix.
Declaration
public static void Swizzle(in Matrix2d mat, int rowForRow0, int rowForRow1, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to swizzle. |
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
| Matrix2d | result | The swizzled matrix. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If any of the rows are outside of the range [0, 1]. |
Swizzle(int, int)
Swizzles this instance. Swiches places of the rows of the matrix.
Declaration
public void Swizzle(int rowForRow0, int rowForRow1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
Swizzled(int, int)
Returns a swizzled copy of this instance.
Declaration
public readonly Matrix2d Swizzled(int rowForRow0, int rowForRow1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowForRow0 | Which row to place in Row0. |
| int | rowForRow1 | Which row to place in Row1. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The swizzled copy. |
ToString()
Returns a System.String that represents the current Matrix4.
Declaration
public override readonly string ToString()
Returns
| Type | Description |
|---|---|
| string | The string representation of the matrix. |
Overrides
ToString(IFormatProvider)
Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | formatProvider |
Returns
| Type | Description |
|---|---|
| string |
ToString(string, IFormatProvider)
Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| string | format | |
| IFormatProvider | formatProvider |
Returns
| Type | Description |
|---|---|
| string |
ToString(string)
Declaration
public readonly string ToString(string format)
Parameters
| Type | Name | Description |
|---|---|---|
| string | format |
Returns
| Type | Description |
|---|---|
| string |
Transpose()
Converts this instance to its transpose.
Declaration
public void Transpose()
Transpose(Matrix2d)
Calculate the transpose of the given matrix.
Declaration
[Pure]
public static Matrix2d Transpose(Matrix2d mat)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to transpose. |
Returns
| Type | Description |
|---|---|
| Matrix2d | The transpose of the given matrix. |
Transpose(in Matrix2d, out Matrix2d)
Calculate the transpose of the given matrix.
Declaration
public static void Transpose(in Matrix2d mat, out Matrix2d result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | mat | The matrix to transpose. |
| Matrix2d | result | The transpose of the given matrix. |
Transposed()
Returns a transposed copy of this instance.
Declaration
public readonly Matrix2d Transposed()
Returns
| Type | Description |
|---|---|
| Matrix2d | The transposed copy. |
Operators
operator +(Matrix2d, Matrix2d)
Matrix addition.
Declaration
[Pure]
public static Matrix2d operator +(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| Matrix2d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new Matrix2d which holds the result of the addition. |
operator ==(Matrix2d, Matrix2d)
Compares two instances for equality.
Declaration
[Pure]
public static bool operator ==(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The first instance. |
| Matrix2d | right | The second instance. |
Returns
| Type | Description |
|---|---|
| bool | True, if left equals right; false otherwise. |
operator !=(Matrix2d, Matrix2d)
Compares two instances for inequality.
Declaration
[Pure]
public static bool operator !=(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | The first instance. |
| Matrix2d | right | The second instance. |
Returns
| Type | Description |
|---|---|
| bool | True, if left does not equal right; false otherwise. |
operator *(Matrix2d, Matrix2d)
Matrix multiplication.
Declaration
[Pure]
public static Matrix2d operator *(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| Matrix2d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new Matrix2d which holds the result of the multiplication. |
operator *(Matrix2d, Matrix2x3d)
Matrix multiplication.
Declaration
[Pure]
public static Matrix2x3d operator *(Matrix2d left, Matrix2x3d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| Matrix2x3d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2x3d | A new Matrix2x3d which holds the result of the multiplication. |
operator *(Matrix2d, Matrix2x4d)
Matrix multiplication.
Declaration
[Pure]
public static Matrix2x4d operator *(Matrix2d left, Matrix2x4d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| Matrix2x4d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2x4d | A new Matrix2x4d which holds the result of the multiplication. |
operator *(Matrix2d, double)
Scalar multiplication.
Declaration
[Pure]
public static Matrix2d operator *(Matrix2d left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| double | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new Matrix2d which holds the result of the multiplication. |
operator *(double, Matrix2d)
Scalar multiplication.
Declaration
[Pure]
public static Matrix2d operator *(double left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| double | left | left-hand operand. |
| Matrix2d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new Matrix2d which holds the result of the multiplication. |
operator -(Matrix2d, Matrix2d)
Matrix subtraction.
Declaration
[Pure]
public static Matrix2d operator -(Matrix2d left, Matrix2d right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix2d | left | left-hand operand. |
| Matrix2d | right | right-hand operand. |
Returns
| Type | Description |
|---|---|
| Matrix2d | A new Matrix2d which holds the result of the subtraction. |