# Matrix¶

Methods:

class com::leapmotion::leap::Matrix

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

Public Functions

boolean equals(Matrix other)

Compare Matrix equality component-wise.

thisMatrix.equals(thatMatrix);


Since
1.0

Vector getOrigin()

The translation factors for all three axes.

Vector thisTranslation = thisMatrix.getOrigin();


Since
1.0

Vector getXBasis()

The basis vector for the x-axis.

Vector xTransform = thisMatrix.getXBasis();


Since
1.0

Vector getYBasis()

The basis vector for the y-axis.

Vector yTransform = thisMatrix.getYBasis();


Since
1.0

Vector getZBasis()

The basis vector for the z-axis.

Vector zTransform = thisMatrix.getZBasis();


Since
1.0

Matrix()

Constructs an identity transformation matrix.

Matrix identity = new Matrix();


Since
1.0

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);


Since
1.0
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.

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().opposite();
Vector handZBasis = leapHand.direction().opposite();
Vector handOrigin =  leapHand.palmPosition();
Matrix handTransform = new Matrix(handXBasis, handYBasis, handZBasis, handOrigin);


Since
1.0
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.

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

Vector axisOfRotation = leapHand.direction();
float angleOfRotation = 1.27f;
Matrix rotator = new Matrix(axisOfRotation, angleOfRotation);


Since
1.0
Parameters
• axis -

A Vector specifying the axis of rotation.

The amount of rotation in radians.

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);


Since
1.0
Parameters
• axis -

A Vector specifying the axis of rotation.

The angle of rotation in radians.

• translation -

A Vector representing the translation part of the transform.

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.

Return
The rigid inverse of the matrix.
Since
1.0

void setOrigin(Vector value)

The translation factors for all three axes.

Vector thisTranslation = thisMatrix.getOrigin();


Since
1.0

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.

Since
1.0
Parameters
• axis -

A Vector specifying the axis of rotation.

The amount of rotation in radians.

void setXBasis(Vector value)

The basis vector for the x-axis.

Vector xTransform = thisMatrix.getXBasis();


Since
1.0

void setYBasis(Vector value)

The basis vector for the y-axis.

Vector yTransform = thisMatrix.getYBasis();


Since
1.0

void setZBasis(Vector value)

The basis vector for the z-axis.

Vector zTransform = thisMatrix.getZBasis();


Since
1.0

Matrix times(Matrix other)

Multiply transform matrices.

Combines two transformations into a single equivalent transformation.

thisMatrix.times(thatMatrix);


Return
A new Matrix representing the transformation equivalent to applying the other transformation followed by this transformation.
Since
1.0
Parameters
• other -

A Matrix to multiply on the right hand side.

String toString()

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

Since
1.0

Vector transformDirection(Vector in)

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

Vector newDirection = thisMatrix.transformDirection(oldDirection);


Return
A new Vector representing the transformed original.
Since
1.0
Parameters
• in -

The Vector to transform.

Vector transformPoint(Vector in)

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.

Return
A new Vector representing the transformed original.
Since
1.0
Parameters
• in -

The Vector to transform.

Public Static Functions

Matrix identity()

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

Matrix identity = Matrix.identity();


Return
The identity matrix.
Since
1.0