Struct Matrix2D
A 2x3 transformation matrix used for 2D operations.
Namespace: Unity.VectorGraphics
Syntax
public struct Matrix2D
Constructors
Matrix2D(Vector2, Vector2, Vector2)
Initializes a Matrix2D with column vectors
Declaration
public Matrix2D(Vector2 column0, Vector2 column1, Vector2 column2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | column0 | The first column |
Vector2 | column1 | The second column |
Vector2 | column2 | The third column |
Fields
m00
The matrix member at (0,0)
Declaration
public float m00
Field Value
Type | Description |
---|---|
Single |
m01
The matrix member at (0,1)
Declaration
public float m01
Field Value
Type | Description |
---|---|
Single |
m02
The matrix member at (0,2)
Declaration
public float m02
Field Value
Type | Description |
---|---|
Single |
m10
The matrix member at (1,0)
Declaration
public float m10
Field Value
Type | Description |
---|---|
Single |
m11
The matrix member at (1,1)
Declaration
public float m11
Field Value
Type | Description |
---|---|
Single |
m12
The matrix member at (1,2)
Declaration
public float m12
Field Value
Type | Description |
---|---|
Single |
Properties
identity
Returns the identity matrix (read-only).
Declaration
public static Matrix2D identity { get; }
Property Value
Type | Description |
---|---|
Matrix2D | The identity matrix |
Item[Int32]
Access element at sequential index (0..5 inclusive).
Declaration
public float this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Property Value
Type | Description |
---|---|
Single | The value at [index] |
Item[Int32, Int32]
Access element at [row, column].
Declaration
public float this[int row, int column] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | row | |
Int32 | column |
Property Value
Type | Description |
---|---|
Single | The value at [row, column] |
zero
Returns a matrix with all elements set to zero (read-only).
Declaration
public static Matrix2D zero { get; }
Property Value
Type | Description |
---|---|
Matrix2D | The zero matrix |
Methods
Equals(Object)
Checks if two matrices are equal.
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
Object | other | The other matrix to compare with |
Returns
Type | Description |
---|---|
Boolean | True when the matrix is equal to "other" |
Overrides
Remarks
Used to allow Matrix3x3s to be used as keys in hash tables.
GetColumn(Int32)
Gets a column of the matrix.
Declaration
public Vector2 GetColumn(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The column index, between 0 and 2 inclusively |
Returns
Type | Description |
---|---|
Vector2 | The column at "index" |
GetHashCode()
Gets a hashcode of the matrix.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hashcode of the matrix |
Overrides
Remarks
Used to allow Matrix3x3s to be used as keys in hash tables.
GetRow(Int32)
Gets a row of the matrix.
Declaration
public Vector3 GetRow(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The row index, between 0 and 1 inclusively |
Returns
Type | Description |
---|---|
Vector3 | The row at "index" |
Inverse()
Computes the inverse of the matrix.
Declaration
public Matrix2D Inverse()
Returns
Type | Description |
---|---|
Matrix2D | The inverse matrix |
MultiplyPoint(Vector2)
Transforms a position by this matrix (effectively by 2x3).
Declaration
public Vector2 MultiplyPoint(Vector2 point)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | point | The point to multiply with this matrix |
Returns
Type | Description |
---|---|
Vector2 | The multiplied point |
MultiplyVector(Vector2)
Transforms a direction by this matrix.
Declaration
public Vector2 MultiplyVector(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The direction to multiply with this matrix |
Returns
Type | Description |
---|---|
Vector2 | The multiplied direction |
Rotate(Single)
Creates a rotation matrix. Note: Assumes unit quaternion.
Declaration
[Obsolete("Use RotateRH or RotateLH instead")]
public static Matrix2D Rotate(float angleRadians)
Parameters
Type | Name | Description |
---|---|---|
Single | angleRadians | The rotation angle, in radians |
Returns
Type | Description |
---|---|
Matrix2D | The rotation matrix |
RotateLH(Single)
Creates a left-hand side rotation matrix.
Declaration
public static Matrix2D RotateLH(float angleRadians)
Parameters
Type | Name | Description |
---|---|---|
Single | angleRadians | The rotation angle, in radians |
Returns
Type | Description |
---|---|
Matrix2D | The rotation matrix |
RotateRH(Single)
Creates a right-hand side rotation matrix.
Declaration
public static Matrix2D RotateRH(float angleRadians)
Parameters
Type | Name | Description |
---|---|---|
Single | angleRadians | The rotation angle, in radians |
Returns
Type | Description |
---|---|
Matrix2D | The rotation matrix |
Scale(Vector2)
Creates a scaling matrix.
Declaration
public static Matrix2D Scale(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The scaling vector |
Returns
Type | Description |
---|---|
Matrix2D | The scaling matrix |
SetColumn(Int32, Vector2)
Sets a column of the matrix.
Declaration
public void SetColumn(int index, Vector2 column)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The column index, between 0 and 2 inclusively |
Vector2 | column | The column |
SetRow(Int32, Vector3)
Sets a row of the matrix.
Declaration
public void SetRow(int index, Vector3 row)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The column index, between 0 and 1 inclusively |
Vector3 | row | The row |
SkewX(Single)
Creates a skew matrix on X.
Declaration
public static Matrix2D SkewX(float angleRadians)
Parameters
Type | Name | Description |
---|---|---|
Single | angleRadians | The skew angle, in radians |
Returns
Type | Description |
---|---|
Matrix2D | The skew matrix |
SkewY(Single)
Creates a skew matrix on U.
Declaration
public static Matrix2D SkewY(float angleRadians)
Parameters
Type | Name | Description |
---|---|---|
Single | angleRadians | The skew angle, in radians |
Returns
Type | Description |
---|---|
Matrix2D | The skew matrix |
ToString()
Returns a string representation of the matrix.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The matrix string representation |
Overrides
ToString(String)
Returns a string representation of the matrix using a format.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format | The format to be used for the matrix components |
Returns
Type | Description |
---|---|
String | The matrix string representation |
Translate(Vector2)
Creates a translation matrix.
Declaration
public static Matrix2D Translate(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The translation vector |
Returns
Type | Description |
---|---|
Matrix2D | The translation matrix |
Operators
Equality(Matrix2D, Matrix2D)
Checks if two matrices are equal.
Declaration
public static bool operator ==(Matrix2D lhs, Matrix2D rhs)
Parameters
Type | Name | Description |
---|---|---|
Matrix2D | lhs | The left hand side matrix of the comparison |
Matrix2D | rhs | The right hand side matrix of the comparison |
Returns
Type | Description |
---|---|
Boolean | True if "lhs" and "rhs" are equal, or false otherwise. |
Inequality(Matrix2D, Matrix2D)
Checks if two matrices are not equal.
Declaration
public static bool operator !=(Matrix2D lhs, Matrix2D rhs)
Parameters
Type | Name | Description |
---|---|---|
Matrix2D | lhs | The left hand side matrix of the comparison |
Matrix2D | rhs | The right hand side matrix of the comparison |
Returns
Type | Description |
---|---|
Boolean | True if "lhs" and "rhs" not are equal, or false otherwise. |
Multiply(Matrix2D, Matrix2D)
Multiplies two matrices.
Declaration
public static Matrix2D operator *(Matrix2D lhs, Matrix2D rhs)
Parameters
Type | Name | Description |
---|---|---|
Matrix2D | lhs | The left hand side matrix of the operation |
Matrix2D | rhs | The right hand side matrix of the operation |
Returns
Type | Description |
---|---|
Matrix2D | The multiplied matrix |
Multiply(Matrix2D, Vector2)
Transforms a Vector2 by a matrix.
Declaration
public static Vector2 operator *(Matrix2D lhs, Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Matrix2D | lhs | The left hand side matrix of the operation |
Vector2 | vector | The vector the matrix will be multiplied with |
Returns
Type | Description |
---|---|
Vector2 | The transformed vector |