Matrix¶
Attributes:
Methods:
- class Leap.Matrix¶
The Matrix class represents a transformation matrix.
To use this class to transform a Vector, construct a matrix containing the desired transformation and then use the transform_point() or transform_direction() methods to apply the transform.
Transforms can be combined by multiplying two or more transform matrices using the * operator.
New in version 1.0.
- classmethod Matrix()¶
Constructs an identity transformation matrix.
matrix = Leap.Matrix()
New in version 1.0.
- classmethod Matrix(other)
Constructs a copy of the specified Matrix object.
other = Leap.Matrix.identity copied_matrix = Leap.Matrix(other)
Parameters: other (Matrix) – The matrix to copy. New in version 1.0.
- classmethod Matrix(xBasis, yBasis, zBasis)
Constructs a transformation matrix from the specified basis vectors.
basis = bone.basis x_basis = basis.x_basis y_basis = basis.y_basis z_basis = basis.z_basis matrix = Leap.Matrix(x_basis, y_basis, z_basis)
Parameters: New in version 1.0.
- classmethod Matrix(xBasis, yBasis, zBasis, origin)
Constructs a transformation matrix from the specified basis and translation vectors.
basis = bone.basis x_basis = basis.x_basis y_basis = basis.y_basis z_basis = basis.z_basis origin = basis.origin matrix = Leap.Matrix(x_basis, y_basis, z_basis, origin)
Parameters: - xBasis (Vector) – A Vector specifying rotation and scale factors for the x-axis.
- yBasis (Vector) – A Vector specifying rotation and scale factors for the y-axis.
- zBasis (Vector) – A Vector specifying rotation and scale factors for the z-axis.
- origin (Vector) – A Vector specifying translation factors on all three axes.
New in version 1.0.
- classmethod Matrix(axis, angleRadians)
Constructs a transformation matrix specifying a rotation around the specified vector.
matrix = Leap.Matrix(Leap.Vector.y_axis, 1.23)
Parameters: - axis (Vector) – A Vector specifying the axis of rotation.
- angleRadians (float) – The amount of rotation in radians.
New in version 1.0.
- classmethod Matrix(axis, angleRadians, translation)
Constructs a transformation matrix specifying a rotation around the specified vector and a translation by the specified vector.
matrix = Leap.Matrix(Leap.Vector.y_axis, .345, Leap.Vector(45, 73, -123))
Parameters: New in version 1.0.
- x_basis¶
Type: Vector The rotation and scale factors for the x-axis.
basis = matrix.x_basis
New in version 1.0.
- y_basis¶
Type: Vector The rotation and scale factors for the y-axis.
basis = matrix.y_basis
New in version 1.0.
- set_rotation(axis, angleRadians)¶
Sets this transformation matrix to represent a rotation around the specified vector.
matrix.set_rotation(Leap.Vector.z_axis, .34)
This function erases any previous rotation and scale transforms applied to this matrix, but does not affect translation.
Parameters: - axis (Vector) – A Vector specifying the axis of rotation.
- angleRadians (float) – The amount of rotation in radians.
New in version 1.0.
- transform_point(in)¶
Transforms a vector with this matrix by transforming its rotation, scale, and translation.
point = Leap.Vector(-53, 256, 132) transformed = matrix.transform_point(point)
Translation is applied after rotation and scale.
Parameters: in (Vector) – The Vector to transform. Return type: Vector – A new Vector representing the transformed original. New in version 1.0.
- transform_direction(in)¶
Transforms a vector with this matrix by transforming its rotation and scale only.
direction = Leap.Vector(.12, .34, .54) transformed = matrix.transform_direction(direction)
Parameters: in (Vector) – The Vector to transform. Return type: Vector – A new Vector representing the transformed original. New in version 1.0.
- rigid_inverse()¶
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.
inverse = matrix.rigid_inverse()
Note that all matricies that are directly returned by the API are rigid.
Return type: Matrix – An inverted copy of this matrix. New in version 1.0.
- to_array_3x3()¶
Convert a 3x3 Matrix object to a 9-element, row-major, float array.
array_matrix = matrix.to_array_3x3()
Translation factors are discarded.
Return type: Array New in version 1.0.
- to_array_4x4()¶
Convert a 4x4 Matrix object to a 16-element, row-major, float array.
array_matrix = matrix.to_array_4x4()
Return type: Array New in version 1.0.
- mul(a, b)¶
Multiply transform matrices.
product = matrix * other
Combines two transformations into a single equivalent transformation.
New in version 1.0.
- imul(a, b)¶
Multiply transform matrices and assign the product.
matrix *= other
New in version 1.0.
- eq(a, b)¶
Compare Matrix equality component-wise.
New in version 1.0.
- ne(a, b)¶
Compare Matrix inequality component-wise.
New in version 1.0.
- identity¶
Type: Matrix The identity matrix specifying no translation, rotation, and scale.
if(matrix == Leap.Matrix.identity): print "Is identity matrix"
New in version 1.0.