# InteractionBox¶

Attributes:

Methods:

class Leap.InteractionBox

The InteractionBox class represents a box-shaped region completely within the field of view of the Leap Motion controller.

The interaction box is an axis-aligned rectangular prism and provides normalized coordinates for hands, fingers, and tools within this box. The InteractionBox region is defined by a center and dimensions along the x, y, and z axes.

Get an InteractionBox object from a Frame object.

interaction_box = frame.interaction_box


The InteractionBox class can make it easier to map positions in the Leap Motion coordinate system to 2D or 3D coordinate systems used for application drawing. The following example illustrates how to convert coordinates from the Leap Motion coordinate system to an application-defined coordinate system using the normalize_point() function. This example is 2D (it ignores the z-axis), but the technique can be be used for all three dimensions.

app_width = 600
app_height = 400
i_box = frame.interaction_box
normalized_tip = i_box.normalize_point(finger.tip_position)
app_x = app_width  * normalized_tip.x
app_y = app_height * (1 - normalized_tip.y)


Note that the y-dimension is inverted since most 2D drawing coordinate systems put the zero-point of the y-axis at the top of the window.

New in version 1.0.

center
Type: Vector

The center of the InteractionBox in device coordinates (millimeters). This point is equidistant from opposing sides of the box.

center = interaction_box.center


New in version 1.0.

width
Type: float

The width of the InteractionBox in millimeters, measured along the x-axis.

x_dimension = interaction_box.width


New in version 1.0.

height
Type: float

The height of the InteractionBox in millimeters, measured along the y-axis.

y_dimension = interaction_box.height


New in version 1.0.

depth
Type: float

The depth of the InteractionBox in millimeters, measured along the z-axis.

z_dimension = interaction_box.depth


New in version 1.0.

is_valid
Type: boolean

Reports whether this is a valid InteractionBox object.

if interaction_box.is_valid:
#Use the box


New in version 1.0.

normalize_point(position[, clamp=True])

Normalizes the coordinates of a point using the interaction box.

Coordinates from the Leap Motion frame of reference (millimeters) are converted to a range of [0..1] such that the minimum value of the InteractionBox maps to 0 and the maximum value of the InteractionBox maps to 1. The coordinates for normalized points outside the InteractionBox boundaries can be negative or greater than one (unless the clamp parameter is True, which is the default).

leap_point = finger.tip_position
normalized_point = interaction_box.normalize_point(leap_point, True)

Parameters: position (Vector) – The input position in device coordinates. clamp (boolean) – Whether or not to limit the output value to the range [0,1] when the input position is outside the InteractionBox. Defaults to True. Vector – The normalized position.

New in version 1.0.

denormalize_point(normalizedPosition)

Converts a position defined by normalized InteractionBox coordinates into device coordinates in millimeters.

leap_point = interaction_box.denormalize_point(normalized_point)


This function performs the inverse of InteractionBox.normalize_point(). Note that if the position originally normalized was outside the box and the clamp parameter was True, then the denormalized coordinates will not be the original position. Instead, the denormalized coordinates will be those of the nearset point on the boundary of the interaction box.

Parameters: normalizedPosition (Vector) – The input position in normalixed, InteractionBox coordinates. Vector – The corresponding denormalized position in device coordinates.

New in version 1.0.

invalid
Type: InteractionBox

An invalid InteractionBox object.

New in version 1.0.

eq(a, b)

Compare InteractionBox object equality. Two InteractionBox objects are equal if and only if both InteractionBox objects represent the exact same InteractionBox and both InteractionBoxes are valid.

New in version 1.0.

ne(a, b)

Compare InteractionBox object inequality. Two InteractionBox objects are equal if and only if both InteractionBox objects represent the exact same InteractionBox and both InteractionBoxes are valid.

New in version 1.0.