# LeapMatrixΒΆ

LeapMatrix Class Reference

The LeapMatrix class represents a transformation matrix. More...

Inherits NSObject.

## Instance Methods

(BOOL) - equals:
Compare LeapMatrix equality component-wise. More...

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

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

(id) - initWithMatrix:
Constructs a copy of the specified Matrix object. More...

(id) - initWithXBasis:yBasis:zBasis:origin:
Constructs a transformation matrix from the specified basis and translation vectors. More...

(LeapMatrix *) - times:
Multiply transform matrices. More...

(LeapVector *) - transformDirection:
Transforms a vector with this matrix by transforming its rotation and scale only. More...

(LeapVector *) - transformPoint:
Transforms a vector with this matrix by transforming its rotation, scale, and translation. More...

## Class Methods

(LeapMatrix *) + identity
Returns the identity matrix specifying no translation, rotation, and scale. More...

## Properties

LeapVectororigin
The translation factors for all three axes. More...

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

NSMutableArray * toNSArray3x3
Converts a LeapMatrix object to a 9-element NSArray object. More...

NSMutableArray * toNSArray4x4
Converts a LeapMatrix object to a 16-element NSArray object. More...

LeapVectorxBasis
The rotation and scale factors for the x-axis. More...

LeapVectoryBasis
The rotation and scale factors for the y-axis. More...

LeapVectorzBasis
The rotation and scale factors for the z-axis. More...

## Detailed Description

The LeapMatrix class represents a transformation matrix.

To use this class to transform a LeapVector, construct a matrix containing the desired transformation and then use the [LeapMatrix transformPoint:] or [LeapMatrix transformDirection:] functions to apply the transform.

Transforms can be combined by multiplying two or more transform matrices using the [LeapMatrix times:] function.

Since 1.0

## Method Documentation

 - (BOOL) equals: (const LeapMatrix *) other

Compare LeapMatrix equality component-wise.

bool matricesAreEqual = [thisMatrix equals:thatMatrix];
Parameters
 other The LeapMatrix object to compare.
Returns
YES, if the corresponding elements in the two matrices are equal.
Since 1.0
 + (LeapMatrix *) identity

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

Returns
The identity matrix.
Since 1.0

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

LeapMatrix *rotation = [[LeapMatrix alloc] initWithAxis:[LeapVector up]
Parameters
 axis A LeapVector specifying the axis of rotation. angleRadians The amount of rotation in radians.
Since 1.0
 - (id) initWithAxis: (const LeapVector *) axis angleRadians: (float) angleRadians translation: (const LeapVector *) translation

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

LeapMatrix *transform = [[LeapMatrix alloc] initWithAxis:[LeapVector zAxis]
translation:[[LeapVector alloc]
initWithX:5
y:3
z:1]];
Parameters
 axis A LeapVector specifying the axis of rotation. angleRadians The angle of rotation in radians. translation A LeapVector representing the translation part of the transform.
Since 1.0
 - (id) initWithMatrix: (LeapMatrix *) matrix

Constructs a copy of the specified Matrix object.

LeapMatrix *copyMatrix = [[LeapMatrix alloc] initWithMatrix:otherMatrix];
Parameters
 matrix the LeapMatrix to copy.
Since 1.0
 - (id) initWithXBasis: (const LeapVector *) xBasis yBasis: (const LeapVector *) yBasis zBasis: (const LeapVector *) zBasis origin: (const LeapVector *) origin

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

LeapMatrix *newMatrix = [[LeapMatrix alloc] initWithXBasis:[LeapVector xAxis]
yBasis:[LeapVector yAxis]
zBasis:[LeapVector zAxis]
origin:[LeapVector zero]];
Parameters
 xBasis A LeapVector specifying rotation and scale factors for the x-axis. yBasis A LeapVector specifying rotation and scale factors for the y-axis. zBasis A LeapVector specifying rotation and scale factors for the z-axis. origin A LeapVector specifying translation factors on all three axes.
Since 1.0
 - (LeapMatrix *) times: (const LeapMatrix *) other

Multiply transform matrices.

LeapMatrix *product = [thisMatrix times:thatMatrix];

Combines two transformations into a single equivalent transformation.

Parameters
 other A LeapMatrix to multiply on the right hand side.
Returns
A new LeapMatrix representing the transformation equivalent to applying the other transformation followed by this transformation.
Since 1.0
 - (LeapVector *) transformDirection: (const LeapVector *) direction

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

LeapVector *direction = [[LeapVector alloc] initWithX:-13 y:87 z:42];
LeapVector *transformedDirection = [thisMatrix transformPoint:point];
Parameters
 direction The LeapVector to transform.
Returns
A new LeapVector representing the transformed original.
Since 1.0
 - (LeapVector *) transformPoint: (const LeapVector *) point

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

Translation is applied after rotation and scale.

LeapVector *point = [[LeapVector alloc] initWithX:10 y:100 z:-30];
LeapVector *transformedPoint = [thisMatrix transformPoint:point];
Parameters
 point A LeapVector representing the 3D position to transform.
Returns
A new LeapVector representing the transformed original.
Since 1.0

## Property Documentation

 - (LeapVector*) origin

The translation factors for all three axes.

LeapVector *origin = matrix.origin;
Since 1.0
 - (LeapMatrix*) 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.

LeapMatrix *rigidInverse = [matrix rigidInverse];

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

Returns
The rigid inverse of the matrix.
Since 1.0
 - (NSMutableArray*) toNSArray3x3

Converts a LeapMatrix object to a 9-element NSArray object.

The elements of the matrix are inserted into the array in row-major order.

NSArray *matrix3x3Array = thisMatrix.toNSArray3x3;
float R2C1 = [[matrix3x3Array objectAtIndex:4] floatValue];

Since 1.0
 - (NSMutableArray*) toNSArray4x4

Converts a LeapMatrix object to a 16-element NSArray object.

The elements of the matrix are inserted into the array in row-major order.

NSArray *matrix4x4Array = thisMatrix.toNSArray4x4;
float R4C3 = [[matrix4x4Array objectAtIndex:15] floatValue];
Since 1.0
 - (LeapVector*) xBasis

The rotation and scale factors for the x-axis.

LeapVector *xBasis = matrix.xBasis;
Since 1.0
 - (LeapVector*) yBasis