Table of Contents

Struct Matrix

Namespace
Avalonia
Assembly
Avalonia.Base.dll

A 3x3 matrix.

public readonly struct Matrix : IEquatable<Matrix>
Implements
Inherited Members

Remarks

Matrix layout: | 1st col | 2nd col | 3r col | 1st row | scaleX | skewY | perspX | 2nd row | skewX | scaleY | perspY | 3rd row | transX | transY | perspZ |

        Note: Skia.SkMatrix uses a transposed layout (where for example skewX/skewY and persp0/transX are swapped).

Constructors

Matrix(double, double, double, double, double, double)

Initializes a new instance of the Matrix struct (equivalent to a 2x3 Matrix without perspective).

public Matrix(double scaleX, double skewY, double skewX, double scaleY, double offsetX, double offsetY)

Parameters

scaleX double

The first element of the first row.

skewY double

The second element of the first row.

skewX double

The first element of the second row.

scaleY double

The second element of the second row.

offsetX double

The first element of the third row.

offsetY double

The second element of the third row.

Matrix(double, double, double, double, double, double, double, double, double)

Initializes a new instance of the Matrix struct.

public Matrix(double scaleX, double skewY, double perspX, double skewX, double scaleY, double perspY, double offsetX, double offsetY, double perspZ)

Parameters

scaleX double

The first element of the first row.

skewY double

The second element of the first row.

perspX double

The third element of the first row.

skewX double

The first element of the second row.

scaleY double

The second element of the second row.

perspY double

The third element of the second row.

offsetX double

The first element of the third row.

offsetY double

The second element of the third row.

perspZ double

The third element of the third row.

Properties

HasInverse

HasInverse Property - returns true if this matrix is invertible, false otherwise.

public bool HasInverse { get; }

Property Value

bool

Identity

Returns the multiplicative identity matrix.

public static Matrix Identity { get; }

Property Value

Matrix

IsIdentity

Returns whether the matrix is the identity matrix.

public bool IsIdentity { get; }

Property Value

bool

M11

The first element of the first row (scaleX).

public double M11 { get; }

Property Value

double

M12

The second element of the first row (skewY).

public double M12 { get; }

Property Value

double

M13

The third element of the first row (perspX: input x-axis perspective factor).

public double M13 { get; }

Property Value

double

M21

The first element of the second row (skewX).

public double M21 { get; }

Property Value

double

M22

The second element of the second row (scaleY).

public double M22 { get; }

Property Value

double

M23

The third element of the second row (perspY: input y-axis perspective factor).

public double M23 { get; }

Property Value

double

M31

The first element of the third row (offsetX/translateX).

public double M31 { get; }

Property Value

double

M32

The second element of the third row (offsetY/translateY).

public double M32 { get; }

Property Value

double

M33

The third element of the third row (perspZ: perspective scale factor).

public double M33 { get; }

Property Value

double

Methods

Append(Matrix)

Appends another matrix as post-multiplication operation. Equivalent to this * value;

public Matrix Append(Matrix value)

Parameters

value Matrix

A matrix.

Returns

Matrix

Post-multiplied matrix.

ContainsPerspective()

Determines if the current matrix contains perspective (non-affine) transforms (true) or only (affine) transforms that could be mapped into an 2x3 matrix (false).

public bool ContainsPerspective()

Returns

bool

CreateRotation(double)

Creates a rotation matrix using the given rotation in radians.

public static Matrix CreateRotation(double radians)

Parameters

radians double

The amount of rotation, in radians.

Returns

Matrix

A rotation matrix.

CreateRotation(double, Point)

Creates a rotation matrix using the given rotation in radians around center point.

public static Matrix CreateRotation(double radians, Point center)

Parameters

radians double

The amount of rotation, in radians.

center Point

The location of center point.

Returns

Matrix

CreateScale(Vector)

Creates a scale matrix from the given vector scale.

public static Matrix CreateScale(Vector scales)

Parameters

scales Vector

The scale to use.

Returns

Matrix

A scaling matrix.

CreateScale(double, double)

Creates a scale matrix from the given X and Y components.

public static Matrix CreateScale(double xScale, double yScale)

Parameters

xScale double

Value to scale by on the X-axis.

yScale double

Value to scale by on the Y-axis.

Returns

Matrix

A scaling matrix.

CreateSkew(double, double)

Creates a skew matrix from the given axis skew angles in radians.

public static Matrix CreateSkew(double xAngle, double yAngle)

Parameters

xAngle double

The amount of skew along the X-axis, in radians.

yAngle double

The amount of skew along the Y-axis, in radians.

Returns

Matrix

A rotation matrix.

CreateTranslation(Vector)

Creates a translation matrix from the given vector.

public static Matrix CreateTranslation(Vector position)

Parameters

position Vector

The translation position.

Returns

Matrix

A translation matrix.

CreateTranslation(double, double)

Creates a translation matrix from the given X and Y components.

public static Matrix CreateTranslation(double xPosition, double yPosition)

Parameters

xPosition double

The X position.

yPosition double

The Y position.

Returns

Matrix

A translation matrix.

Equals(Matrix)

Returns a boolean indicating whether the matrix is equal to the other given matrix.

public bool Equals(Matrix other)

Parameters

other Matrix

The other matrix to test equality against.

Returns

bool

True if this matrix is equal to other; False otherwise.

Equals(object?)

Returns a boolean indicating whether the given Object is equal to this matrix instance.

public override bool Equals(object? obj)

Parameters

obj object

The Object to compare against.

Returns

bool

True if the Object is equal to this matrix; False otherwise.

GetDeterminant()

Calculates the determinant for this matrix.

public double GetDeterminant()

Returns

double

The determinant.

Remarks

The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1).

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

The hash code.

Invert()

Inverts the Matrix.

public Matrix Invert()

Returns

Matrix

The inverted matrix.

Exceptions

InvalidOperationException

Matrix is not invertible.

Parse(string)

Parses a Matrix string.

public static Matrix Parse(string s)

Parameters

s string

Six or nine comma-delimited double values (m11, m12, m21, m22, offsetX, offsetY[, perspX, perspY, perspZ]) that describe the new Matrix

Returns

Matrix

The Matrix.

Prepend(Matrix)

Prepends another matrix as pre-multiplication operation. Equivalent to value * this;

public Matrix Prepend(Matrix value)

Parameters

value Matrix

A matrix.

Returns

Matrix

Pre-multiplied matrix.

ToRadians(double)

Converts an angle in degrees to radians.

public static double ToRadians(double angle)

Parameters

angle double

The angle in degrees.

Returns

double

The angle in radians.

ToString()

Returns a String representing this matrix instance.

public override string ToString()

Returns

string

The string representation.

Transform(Point)

Transforms the point with the matrix

public Point Transform(Point p)

Parameters

p Point

The point to be transformed

Returns

Point

The transformed point

TryDecomposeTransform(Matrix, out Decomposed)

Decomposes given matrix into transform operations.

public static bool TryDecomposeTransform(Matrix matrix, out Matrix.Decomposed decomposed)

Parameters

matrix Matrix

Matrix to decompose.

decomposed Matrix.Decomposed

Decomposed matrix.

Returns

bool

The status of the operation.

TryInvert(out Matrix)

Attempts to invert the Matrix.

public bool TryInvert(out Matrix inverted)

Parameters

inverted Matrix

Returns

bool

The inverted matrix or null when matrix is not invertible.

Operators

operator ==(Matrix, Matrix)

Returns a boolean indicating whether the given matrices are equal.

public static bool operator ==(Matrix value1, Matrix value2)

Parameters

value1 Matrix

The first source matrix.

value2 Matrix

The second source matrix.

Returns

bool

True if the matrices are equal; False otherwise.

operator !=(Matrix, Matrix)

Returns a boolean indicating whether the given matrices are not equal.

public static bool operator !=(Matrix value1, Matrix value2)

Parameters

value1 Matrix

The first source matrix.

value2 Matrix

The second source matrix.

Returns

bool

True if the matrices are not equal; False if they are equal.

operator *(Matrix, Matrix)

Multiplies two matrices together and returns the resulting matrix.

public static Matrix operator *(Matrix value1, Matrix value2)

Parameters

value1 Matrix

The first source matrix.

value2 Matrix

The second source matrix.

Returns

Matrix

The product matrix.

operator -(Matrix)

Negates the given matrix by multiplying all values by -1.

public static Matrix operator -(Matrix value)

Parameters

value Matrix

The source matrix.

Returns

Matrix

The negated matrix.