# Matrix¶

Matrix Struct Reference

The Matrix struct represents a transformation matrix. More...

## Public Member Functions

bool Equals (Matrix other)
Compare Matrix equality component-wise. More...

Matrix (Matrix other)
Constructs a copy of the specified Matrix object. More...

Matrix (Vector xBasis, Vector yBasis, Vector zBasis)
Constructs a transformation matrix from the specified basis vectors. More...

Matrix (Vector xBasis, Vector yBasis, Vector zBasis, Vector origin)
Constructs a transformation matrix from the specified basis and translation vectors. More...

Constructs a transformation matrix specifying a rotation around the specified vector. More...

Matrix (Vector axis, float angleRadians, Vector translation)
Constructs a transformation matrix specifying a rotation around the specified vector and a translation by the specified vector. More...

Matrix RigidInverse ()
Performs a matrix inverse if the matrix consists entirely of rigid transformations (translations and rotations). More...

void SetRotation (Vector axis, float angleRadians)
Sets this transformation matrix to represent a rotation around the specified vector. More...

float[] ToArray3x3 (float[] output)
Copy this matrix to the specified array of 9 float values in row-major order. More...

double[] ToArray3x3 (double[] output)
Copy this matrix to the specified array containing 9 double values in row-major order. More...

float[] ToArray3x3 ()
Convert this matrix to an array containing 9 float values in row-major order. More...

float[] ToArray4x4 (float[] output)
Copy this matrix to the specified array of 16 float values in row-major order. More...

double[] ToArray4x4 (double[] output)
Copy this matrix to the specified array of 16 double values in row-major order. More...

float[] ToArray4x4 ()
Convert this matrix to an array containing 16 float values in row-major order. More...

override string ToString ()
Write the matrix to a string in a human readable format. More...

Vector TransformDirection (Vector direction)
Transforms a vector with this matrix by transforming its rotation and scale only. More...

Vector TransformPoint (Vector point)
Transforms a vector with this matrix by transforming its rotation, scale, and translation. More...

## Static Public Member Functions

static Matrix operator* (Matrix m1, Matrix m2)
Multiply two matrices. More...

## Static Public Attributes

static readonly Matrix Identity = new Matrix(Vector.XAxis, Vector.YAxis, Vector.ZAxis, Vector.Zero)
Returns the identity matrix specifying no translation, rotation, and scale. More...

## Properties

Vector origin [get, set]
The translation factors for all three axes. More...

Vector xBasis [get, set]
The basis vector for the x-axis. More...

Vector yBasis [get, set]
The basis vector for the y-axis. More...

Vector zBasis [get, set]
The basis vector for the z-axis. More...

## Detailed Description

The Matrix struct represents a transformation matrix.

To use this struct to transform a Vector, construct a matrix containing the desired transformation and then use the Matrix::transformPoint() or Matrix::transformDirection() functions to apply the transform.

Transforms can be combined by multiplying two or more transform matrices using the * operator.

Since
1.0

## Constructor & Destructor Documentation

 Matrix ( Matrix other )

Constructs a copy of the specified Matrix object.

Matrix thisMatrix = new Matrix (thatMatrix);
Since
1.0
 Matrix ( Vector xBasis, Vector yBasis, Vector zBasis )

Constructs a transformation matrix from the specified basis vectors.

Vector xBasis = new Vector (23, 0, 0);
Vector yBasis = new Vector (0, 12, 0);
Vector zBasis = new Vector (0, 0, 45);
Matrix transformMatrix = new Matrix (xBasis, yBasis, zBasis);
Parameters
 xBasis A Vector specifying rotation and scale factors for the x-axis. yBasis A Vector specifying rotation and scale factors for the y-axis. zBasis A Vector specifying rotation and scale factors for the z-axis.
Since
1.0
 Matrix ( Vector xBasis, Vector yBasis, Vector zBasis, Vector origin )

Constructs a transformation matrix from the specified basis and translation vectors.

Hand leapHand = frame.Hand (handID);
Vector handXBasis = leapHand.PalmNormal.Cross (leapHand.Direction.Normalized);
Vector handYBasis = -leapHand.PalmNormal;
Vector handZBasis = -leapHand.Direction;
Vector handOrigin = leapHand.PalmPosition;
Matrix handTransform = new Matrix (handXBasis, handYBasis, handZBasis, handOrigin);
Parameters
 xBasis A Vector specifying rotation and scale factors for the x-axis. yBasis A Vector specifying rotation and scale factors for the y-axis. zBasis A Vector specifying rotation and scale factors for the z-axis. origin A Vector specifying translation factors on all three axes.
Since
1.0
 Matrix ( Vector axis, float angleRadians )

Constructs a transformation matrix specifying a rotation around the specified vector.

Vector axisOfRotation = hand.Direction;
float angleOfRotation = 1.27f;
Matrix rotator = new Matrix (axisOfRotation, angleOfRotation);
Parameters
 axis A Vector specifying the axis of rotation. angleRadians The amount of rotation in radians.
Since
1.0
 Matrix ( Vector axis, float angleRadians, Vector translation )

Constructs a transformation matrix specifying a rotation around the specified vector and a translation by the specified vector.

Vector rotationAxis = Vector.YAxis;
float angle = .733f;
Vector translation = new Vector (10, 220, 103);
Matrix transform = new Matrix (rotationAxis, angle, translation);
Parameters
 axis A Vector specifying the axis of rotation. angleRadians The angle of rotation in radians. translation A Vector representing the translation part of the transform.
Since
1.0

## Member Function Documentation

 bool Equals ( Matrix other )

Compare Matrix equality component-wise.

thisMatrix == thatMatrix;
Since
1.0
 static Matrix operator* ( Matrix m1, Matrix m2 )
static

Multiply two matrices.

 Matrix RigidInverse ( )

Performs a matrix inverse if the matrix consists entirely of rigid transformations (translations and rotations).

If the matrix is not rigid, this operation will not represent an inverse.

thisMatrix = thatMatrix.RigidInverse ();

Note that all matrices that are directly returned by the API are rigid.

Returns
The rigid inverse of the matrix.
Since
1.0
 void SetRotation ( Vector axis, float angleRadians )

Sets this transformation matrix to represent a rotation around the specified vector.

thisMatrix.SetRotation (Vector.ZAxis, 1.46f);

This function erases any previous rotation and scale transforms applied to this matrix, but does not affect translation.

Parameters
 axis A Vector specifying the axis of rotation. angleRadians The amount of rotation in radians.
Since
1.0
 float [] ToArray3x3 ( float[] output )

Copy this matrix to the specified array of 9 float values in row-major order.

 double [] ToArray3x3 ( double[] output )

Copy this matrix to the specified array containing 9 double values in row-major order.

 float [] ToArray3x3 ( )

Convert this matrix to an array containing 9 float values in row-major order.

 float [] ToArray4x4 ( float[] output )

Copy this matrix to the specified array of 16 float values in row-major order.

 double [] ToArray4x4 ( double[] output )

Copy this matrix to the specified array of 16 double values in row-major order.

 float [] ToArray4x4 ( )

Convert this matrix to an array containing 16 float values in row-major order.

 override string ToString ( )

Write the matrix to a string in a human readable format.

Since
1.0
 Vector TransformDirection ( Vector direction )

Transforms a vector with this matrix by transforming its rotation and scale only.

Vector newDirection = thisMatrix.TransformDirection (oldDirection);
Parameters
 in The Vector to transform.
Returns
A new Vector representing the transformed original.
Since
1.0
 Vector TransformPoint ( Vector point )

Transforms a vector with this matrix by transforming its rotation, scale, and translation.

Vector newPosition = thisMatrix.TransformPoint (oldPosition);

Translation is applied after rotation and scale.

Parameters
 point The Vector to transform.
Returns
A new Vector representing the transformed original.
Since
1.0

## Member Data Documentation

 readonly Matrix Identity = new Matrix(Vector.XAxis, Vector.YAxis, Vector.ZAxis, Vector.Zero)
static

Returns the identity matrix specifying no translation, rotation, and scale.

Matrix identity = Matrix.Identity;
Returns
The identity matrix.
Since
1.0

## Property Documentation

 Vector origin
getset

The translation factors for all three axes.

Vector thisTranslation = thisMatrix.origin;
Since
1.0
 Vector xBasis
getset

The basis vector for the x-axis.

Vector xTransform = thisMatrix.xBasis;
Since
1.0
 Vector yBasis
getset

The basis vector for the y-axis.

Vector yTransform = thisMatrix.yBasis;
Since
1.0
 Vector zBasis
getset

The basis vector for the z-axis.

Vector zTransform = thisMatrix.zBasis;
Since
1.0