LeapJS API Reference

Function

Leap.Vector. AngleTo

The angle between this vector and the specified vector in radians.

The angle is measured in the plane formed by the two vectors. The angle returned is always the smaller of the two conjugate angles. Thus A.angleTo(B) == B.angleTo(A) and is always a positive value less than or equal to pi radians (180 degrees).

If either vector has zero length, then this function returns zero.

Vector AngleTo

vector.js at line 85
Leap.Vector. Cross

The cross product of this vector and the specified vector.

The cross product is a vector orthogonal to both original vectors. It has a magnitude equal to the area of a parallelogram having the two vectors as sides. The direction of the returned vector is determined by the right-hand rule. Thus A.cross(B) == -B.cross(A).

Vector Cross

vector.js at line 109
Leap.Matrix. compare

Compare Matrix equality component-wise.

matrix.js at line 275
Leap.Vector. compare

Compare Vector equality component-wise.

vector.js at line 345
Leap.Vector. distanceTo

The distance between the point represented by this Vector object and a point represented by the specified Vector object.

vector.js at line 132
Leap.Vector. dividedBy

Divide vector by a scalar.

vector.js at line 198
Leap.Vector. dot

The dot product of this vector with another vector.

The dot product is the magnitude of the projection of this vector onto the specified vector.

Vector Dot

vector.js at line 145
Leap.Frame. dump

Returns a JSON-formatted string containing the hands, pointables and gestures in this frame.

frame.js at line 396
Leap.Frame. finger

The finger with the specified ID in this frame.

Use the Frame finger() function to retrieve the finger from this frame using an ID value obtained from a previous frame. This function always returns a Finger object, but if no finger with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a finger is lost and subsequently regained, the new Pointable object representing that physical finger may have a different ID than that representing the finger in an earlier frame.

frame.js at line 197
Leap.Hand. finger

The finger with the specified ID attached to this hand.

Use this function to retrieve a Pointable object representing a finger attached to this hand using an ID value obtained from a previous frame. This function always returns a Pointable object, but if no finger with the specified ID is present, an invalid Pointable object is returned.

Note that the ID values assigned to fingers persist across frames, but only until tracking of a particular finger is lost. If tracking of a finger is lost and subsequently regained, the new Finger object representing that finger may have a different ID than that representing the finger in an earlier frame.

hand.js at line 154
Leap.Controller. frame

Returns a frame of tracking data from the Leap.

Use the optional history parameter to specify which frame to retrieve. Call frame() or frame(0) to access the most recent frame; call frame(1) to access the previous frame, and so on. If you use a history value greater than the number of stored frames, then the controller returns an invalid frame.

controller.js at line 93
Leap.Frame. hand

The Hand object with the specified ID in this frame.

Use the Frame hand() function to retrieve the Hand object from this frame using an ID value obtained from a previous frame. This function always returns a Hand object, but if no hand with the specified ID is present, an invalid Hand object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a hand is lost and subsequently regained, the new Hand object representing that physical hand may have a different ID than that representing the physical hand in an earlier frame.

frame.js at line 222
Leap.Vector. isValid

Returns true if all of the vector's components are finite.

If any component is NaN or infinite, then this returns false.

vector.js at line 357
Leap. loop

The Leap.loop() function passes a frame of Leap data to your callback function and then calls window.requestAnimationFrame() after executing your callback function.

Leap.loop() sets up the Leap controller and WebSocket connection for you. You do not need to create your own controller when using this method.

Your callback function is called on an interval determined by the client browser. Typically, this is on an interval of 60 frames/second. The most recent frame of Leap data is passed to your callback function. If the Leap is producing frames at a slower rate than the browser frame rate, the same frame of Leap data can be passed to your function in successive animation updates.

As an alternative, you can create your own Controller object and use a Controller#onFrame onFrame callback to process the data at the frame rate of the Leap device. See Controller for an example.

index.js at line 19
Leap.Vector. magnitude

The magnitude, or length, of this vector.

The magnitude is the L2 norm, or Euclidean distance between the origin and the point represented by the (x, y, z) components of this Vector object.

vector.js at line 210
Leap.Vector. magnitudeSquared

The square of the magnitude, or length, of this vector.

vector.js at line 225
Leap.Vector. minus

Subtract vectors component-wise.

vector.js at line 174
Leap.Vector. multiply

Multiply vector by a scalar.

vector.js at line 186
Leap.Vector. normalized

A normalized copy of this vector.

A normalized vector has the same direction as the original vector, but with a length of one.

vector.js at line 236
Leap.Vector. pitch

The pitch angle in radians.

Pitch is the angle between the negative z-axis and the projection of the vector onto the y-z plane. In other words, pitch represents rotation around the x-axis. If the vector points upward, the returned angle is between 0 and pi radians (180 degrees); if it points downward, the angle is between 0 and -pi radians.

Vector Pitch

vector.js at line 253
Leap.Vector. plus

Add vectors component-wise.

vector.js at line 162
Leap.Frame. pointable

The Pointable object with the specified ID in this frame.

Use the Frame pointable() function to retrieve the Pointable object from this frame using an ID value obtained from a previous frame. This function always returns a Pointable object, but if no finger or tool with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a finger or tool is lost and subsequently regained, the new Pointable object representing that finger or tool may have a different ID than that representing the finger or tool in an earlier frame.

frame.js at line 173
Leap.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.

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

matrix.js at line 185
Leap.Vector. roll

The roll angle in radians.

Roll is the angle between the y-axis and the projection of the vector onto the x-y plane. In other words, roll represents rotation around the z-axis. If the vector points to the left of the y-axis, then the returned angle is between 0 and pi radians (180 degrees); if it points to the right, the angle is between 0 and -pi radians.

Vector Roll

Use this function to get roll angle of the plane to which this vector is a normal. For example, if this vector represents the normal to the palm, then this function returns the tilt or roll of the palm plane compared to the horizontal (x-z) plane.

vector.js at line 273
Leap.Frame. rotationAngle

The angle of rotation around the rotation axis derived from the overall rotational motion between the current frame and the specified frame.

The returned angle is expressed in radians measured clockwise around the rotation axis (using the right-hand rule) between the start and end frames. The value is always between 0 and pi radians (0 and 180 degrees).

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then the angle of rotation is zero.

frame.js at line 245
Leap.Hand. rotationAngle

The angle of rotation around the rotation axis derived from the change in orientation of this hand, and any associated fingers and tools, between the current frame and the specified frame.

The returned angle is expressed in radians measured clockwise around the rotation axis (using the right-hand rule) between the start and end frames. The value is always between 0 and pi radians (0 and 180 degrees).

If a corresponding Hand object is not found in sinceFrame, or if either this frame or sinceFrame are invalid Frame objects, then the angle of rotation is zero.

hand.js at line 180
Leap.Frame. rotationAxis

The axis of rotation derived from the overall rotational motion between the current frame and the specified frame.

The returned direction vector is normalized.

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, or if no rotation is detected between the two frames, a zero vector is returned.

frame.js at line 281
Leap.Hand. rotationAxis

The axis of rotation derived from the change in orientation of this hand, and any associated fingers and tools, between the current frame and the specified frame.

The returned direction vector is normalized.

If a corresponding Hand object is not found in sinceFrame, or if either this frame or sinceFrame are invalid Frame objects, then this method returns a zero vector.

hand.js at line 218
Leap.Frame. rotationMatrix

The transform matrix expressing the rotation derived from the overall rotational motion between the current frame and the specified frame.

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then this method returns an identity matrix.

frame.js at line 308
Leap.Hand. rotationMatrix

The transform matrix expressing the rotation derived from the change in orientation of this hand, and any associated fingers and tools, between the current frame and the specified frame.

If a corresponding Hand object is not found in sinceFrame, or if either this frame or sinceFrame are invalid Frame objects, then this method returns an identity matrix.

hand.js at line 245
Leap.Frame. scaleFactor

The scale factor derived from the overall motion between the current frame and the specified frame.

The scale factor is always positive. A value of 1.0 indicates no scaling took place. Values between 0.0 and 1.0 indicate contraction and values greater than 1.0 indicate expansion.

The Leap derives scaling from the relative inward or outward motion of all objects detected in the field of view (independent of translation and rotation).

If either this frame or sinceFrame is an invalid Frame object, then this method returns 1.0.

frame.js at line 333
Leap.Hand. scaleFactor

The scale factor derived from the hand's motion between the current frame and the specified frame.

The scale factor is always positive. A value of 1.0 indicates no scaling took place. Values between 0.0 and 1.0 indicate contraction and values greater than 1.0 indicate expansion.

The Leap derives scaling from the relative inward or outward motion of a hand and its associated fingers and tools (independent of translation and rotation).

If a corresponding Hand object is not found in sinceFrame, or if either this frame or sinceFrame are invalid Frame objects, then this method returns 1.0.

hand.js at line 272
Leap.Matrix. setRotation

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

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

matrix.js at line 112
Leap.Matrix. times

Multiply transform matrices.

Combines two transformations into a single equivalent transformation.

matrix.js at line 166
Leap.Vector. toArray

Returns the vector as a float array.

vector.js at line 320
Leap.Matrix. toArray3x3

Writes the 3x3 Matrix object to a 9 element row-major float array.

Translation factors are discarded.

matrix.js at line 206
Leap.Matrix. toArray4x4

Convert a 4x4 Matrix object to a 16 element row-major float array.

Translation factors are discarded.

matrix.js at line 230
Leap.Frame. toString

A string containing a brief, human readable description of the Frame object.

frame.js at line 382
Leap.Hand. toString

A string containing a brief, human readable description of the Hand object.

hand.js at line 324
Leap.Matrix. toString

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

matrix.js at line 261
Leap.Pointable. toString

A string containing a brief, human readable description of the Pointable object.

pointable.js at line 120
Leap.Vector. toString

Returns a string containing this vector in a human readable format: (x, y, z).

vector.js at line 331
Leap.Frame. tool

The tool with the specified ID in this frame.

Use the Frame tool() function to retrieve a tool from this frame using an ID value obtained from a previous frame. This function always returns a Pointable object, but if no tool with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a tool is lost and subsequently regained, the new Pointable object representing that tool may have a different ID than that representing the tool in an earlier frame.

frame.js at line 148
Leap.Matrix. transformDirection

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

matrix.js at line 150
Leap.Matrix. transformPoint

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

Translation is applied after rotation and scale.

matrix.js at line 135
Leap.Frame. translation

The change of position derived from the overall linear motion between the current frame and the specified frame.

The returned translation vector provides the magnitude and direction of the movement in millimeters.

The Leap derives frame translation from the linear motion of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then this method returns a zero vector.

frame.js at line 355
Leap.Hand. translation

The change of position of this hand between the current frame and the specified frame

The returned translation vector provides the magnitude and direction of the movement in millimeters.

If a corresponding Hand object is not found in sinceFrame, or if either this frame or sinceFrame are invalid Frame objects, then this method returns a zero vector.

hand.js at line 298
Leap.Vector. yaw

The yaw angle in radians.

Yaw is the angle between the negative z-axis and the projection of the vector onto the x-z plane. In other words, yaw represents rotation around the y-axis. If the vector points to the right of the negative z-axis, then the returned angle is between 0 and pi radians (180 degrees); if it points to the left, the angle is between 0 and -pi radians.

Vector Roll

vector.js at line 299