Skip to main content

Matrix Struct

Definition

Namespace:Avalonia
Assembly:Avalonia.Base
Package:Avalonia
Source:Matrix.cs

A 3x3 matrix.

public struct Matrix

Inheritance: ValueType -> Matrix

Implements: IEquatable<Matrix>

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

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

Matrix overloads

Matrix Constructor

Initializes a new instance of the Avalonia.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 Constructor

Initializes a new instance of the Avalonia.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.

Methods

NameDescription
AppendAppends another matrix as post-multiplication operation. Equivalent to this * value;
ContainsPerspectiveDetermines if the current matrix contains perspective (non-affine) transforms (true) or only (affine) transforms that could be mapped into an 2x3 matrix (false).
CreateRotation (2 overloads)Creates a rotation matrix using the given rotation in radians.
CreateScale (2 overloads)Creates a scale matrix from the given vector scale.
CreateSkewCreates a skew matrix from the given axis skew angles in radians.
CreateTranslation (2 overloads)Creates a translation matrix from the given vector.
Equals (2 overloads)Returns a boolean indicating whether the matrix is equal to the other given matrix.
GetDeterminantCalculates the determinant for this matrix.
GetHashCodeReturns the hash code for this instance.
InvertInverts the Matrix.
ParseParses a Avalonia.Matrix string.
PrependPrepends another matrix as pre-multiplication operation. Equivalent to value * this;
ToRadiansConverts an angle in degrees to radians.
ToStringReturns a String representing this matrix instance.
TransformTransforms the point with the matrix
TryDecomposeTransformNo summary available.
TryInvertNo summary available.

Append Method

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

public Avalonia.Matrix Append(Avalonia.Matrix value)

Parameters

value Avalonia.Matrix

A matrix.

Returns

Avalonia.Matrix

Post-multiplied matrix.

ContainsPerspective Method

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 overloads

CreateRotation Method

Creates a rotation matrix using the given rotation in radians.

public Avalonia.Matrix CreateRotation(double radians)
Parameters

radians double

The amount of rotation, in radians.

Returns

Avalonia.Matrix

A rotation matrix.

CreateRotation Method

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

public Avalonia.Matrix CreateRotation(double radians, Avalonia.Point center)
Parameters

radians double

The amount of rotation, in radians.

center Avalonia.Point

The location of center point.

Returns

Avalonia.Matrix

CreateScale overloads

CreateScale Method

Creates a scale matrix from the given vector scale.

public Avalonia.Matrix CreateScale(Avalonia.Vector scales)
Parameters

scales Avalonia.Vector

The scale to use.

Returns

Avalonia.Matrix

A scaling matrix.

CreateScale Method

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

public Avalonia.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

Avalonia.Matrix

A scaling matrix.

CreateSkew Method

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

public Avalonia.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

Avalonia.Matrix

A rotation matrix.

CreateTranslation overloads

CreateTranslation Method

Creates a translation matrix from the given vector.

public Avalonia.Matrix CreateTranslation(Avalonia.Vector position)
Parameters

position Avalonia.Vector

The translation position.

Returns

Avalonia.Matrix

A translation matrix.

CreateTranslation Method

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

public Avalonia.Matrix CreateTranslation(double xPosition, double yPosition)
Parameters

xPosition double

The X position.

yPosition double

The Y position.

Returns

Avalonia.Matrix

A translation matrix.

Equals overloads

Equals Method

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

public bool Equals(Avalonia.Matrix other)
Parameters

other Avalonia.Matrix

The other matrix to test equality against.

Returns

bool

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

Equals Method

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

public 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 Method

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 Method

Returns the hash code for this instance.

public int GetHashCode()

Returns

int

The hash code.

Invert Method

Inverts the Matrix.

public Avalonia.Matrix Invert()

Returns

Avalonia.Matrix

The inverted matrix.

Exceptions

Parse Method

Parses a Avalonia.Matrix string.

public Avalonia.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 Avalonia.Matrix

Returns

Avalonia.Matrix

The Avalonia.Matrix.

Prepend Method

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

public Avalonia.Matrix Prepend(Avalonia.Matrix value)

Parameters

value Avalonia.Matrix

A matrix.

Returns

Avalonia.Matrix

Pre-multiplied matrix.

ToRadians Method

Converts an angle in degrees to radians.

public double ToRadians(double angle)

Parameters

angle double

The angle in degrees.

Returns

double

The angle in radians.

ToString Method

Returns a String representing this matrix instance.

public string ToString()

Returns

string

The string representation.

Transform Method

Transforms the point with the matrix

public Avalonia.Point Transform(Avalonia.Point p)

Parameters

p Avalonia.Point

The point to be transformed

Returns

Avalonia.Point

The transformed point

TryDecomposeTransform Method

public bool TryDecomposeTransform(Avalonia.Matrix matrix, Avalonia.Matrix.Decomposed& decomposed)

Parameters

matrix Avalonia.Matrix

decomposed Avalonia.Matrix.Decomposed&

Returns

bool

TryInvert Method

public bool TryInvert(Avalonia.Matrix& inverted)

Parameters

inverted Avalonia.Matrix&

Returns

bool

Properties

NameDescription
HasInverseHasInverse Property - returns true if this matrix is invertible, false otherwise.
IdentityReturns the multiplicative identity matrix.
IsIdentityReturns whether the matrix is the identity matrix.
M11The first element of the first row (scaleX).
M12The second element of the first row (skewY).
M13The third element of the first row (perspX: input x-axis perspective factor).
M21The first element of the second row (skewX).
M22The second element of the second row (scaleY).
M23The third element of the second row (perspY: input y-axis perspective factor).
M31The first element of the third row (offsetX/translateX).
M32The second element of the third row (offsetY/translateY).
M33The third element of the third row (perspZ: perspective scale factor).

HasInverse Property

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

public bool HasInverse { get; set; }

Identity Property

Returns the multiplicative identity matrix.

public Avalonia.Matrix Identity { get; set; }

IsIdentity Property

Returns whether the matrix is the identity matrix.

public bool IsIdentity { get; set; }

M11 Property

The first element of the first row (scaleX).

public double M11 { get; set; }

M12 Property

The second element of the first row (skewY).

public double M12 { get; set; }

M13 Property

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

public double M13 { get; set; }

M21 Property

The first element of the second row (skewX).

public double M21 { get; set; }

M22 Property

The second element of the second row (scaleY).

public double M22 { get; set; }

M23 Property

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

public double M23 { get; set; }

M31 Property

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

public double M31 { get; set; }

M32 Property

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

public double M32 { get; set; }

M33 Property

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

public double M33 { get; set; }