LeapVectorΒΆ
Properties:
Methods:
The LeapVector class represents a three-component mathematical vector or point such as a direction or position in three-dimensional space.
The Leap software employs a right-handed Cartesian coordinate system. Values given are in units of real-world millimeters. The origin is centered at the center of the Leap device. The x- and z-axes lie in the horizontal plane, with the x-axis running parallel to the long edge of the device. The y-axis is vertical, with positive values increasing upwards (in contrast to the downward orientation of most computer graphics coordinate systems). The z-axis has positive values increasing away from the computer screen.
Public Functions
- Since 1.0
Property- (float) angleTo:(const LeapVector *) vectorThe angle between this vector and the specified vector in radians.
float angleInRadians = [[LeapVector xAxis] angleTo:[LeapVector yAxis]]; // angleInRadians = PI/2 (90 degrees)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.
- Return
- The angle between this vector and the specified vector in radians.
- Since 1.0
- Parameters
- vector -
A LeapVector object.
The cross product of this vector and the specified vector.
LeapVector *crossProduct = [thisVector cross:thatVector];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 negate] cross:A].
- Return
- The cross product of this vector and the specified vector.
- Since 1.0
- Parameters
- vector -
A LeapVector object.
- (float) distanceTo:(const LeapVector *) vectorThe distance between the point represented by this LeapVector object and a point represented by the specified LeapVector object.
LeapVector *aPoint = [[LeapVector alloc] initWithX:10 y:0 z:0]; LeapVector *origin = [LeapVector zero]; float distance = [origin distanceTo:aPoint]; // distance = 10
- Return
- The distance from this point to the specified point.
- Since 1.0
- Parameters
- vector -
A LeapVector object.
- (LeapVector *) divide:(float) scalarDivide this vector by a number.
LeapVector *quotient = [thisVector divide:2.5];
- Return
- The dividend of this LeapVector divided by a scalar.
- Since 1.0
- Parameters
- scalar -
The scalar divisor;
- (float) dot:(const LeapVector *) vectorThe dot product of this vector with another vector.
float dotProduct = [thisVector dot:thatVector];The dot product is the magnitude of the projection of this vector onto the specified vector.
- Return
- The dot product of this vector and the specified vector.
- Since 1.0
- Parameters
- vector -
A LeapVector object.
- (BOOL) equals:(const LeapVector *) vectorChecks LeapVector equality.
bool vectorsAreEqual = [thisVector equals:thatVector];Vectors are equal if each corresponding component is equal.
- Return
- YES, if the LeapVectors are equal.
- Since 1.0
- Parameters
- vector -
The LeapVector to compare.
- (id) initWithVector:(const LeapVector *) vectorCopies the specified LeapVector.
LeapVector *copiedVector = [[LeapVector alloc] initWithVector:otherVector];
- Since 1.0
- Parameters
- vector -
The LeapVector to copy.
- (id) initWithX:(float) x y:(float) y z:(float) zCreates a new LeapVector with the specified component values.
LeapVector *newVector = [[LeapVector alloc] initWithX:0.5 y:200.3 z:67];
- Since 1.0
- Parameters
- x -
The horizontal component.
- y -
The vertical component.
- z -
The depth component.
Subtract a vector from this vector.
LeapVector *difference = [thisVector minus:thatVector];
- Return
- the difference between the two LeapVectors.
- Since 1.0
- Parameters
- vector -
the LeapVector subtrahend.
- (LeapVector *) negateNegate this vector.
LeapVector *negation = thisVector.negate;
- Return
- The negation of this LeapVector.
- Since 1.0
Adds two vectors.
LeapVector *sum = [thisVector plus:thatVector];
- Return
- The sum of the two LeapVectors.
- Since 1.0
- Parameters
- vector -
The LeapVector addend.
- (LeapVector *) times:(float) scalarMultiply this vector by a number.
LeapVector *product = [thisVector times:5.0];
- Return
- The product of this LeapVector and a scalar.
- Since 1.0
- Parameters
- scalar -
The scalar factor.
Public Static Functionsmagnitude- (float) magnitudeThe magnitude, or length, of this vector.
float length = thisVector.magnitude;The magnitude is the L2 norm, or Euclidean distance between the origin and the point represented by the (x, y, z) components of this LeapVector object.
- Return
- The length of this vector.
- Since 1.0
magnitudeSquared- (float) magnitudeSquaredThe square of the magnitude, or length, of this vector.
float lengthSquared = thisVector.magnitudeSquared;
- Return
- The square of the length of this vector.
- Since 1.0
normalized- (LeapVector *) normalizedA normalized copy of this vector.
LeapVector *normalizedVector = otherVector.normalized;A normalized vector has the same direction as the original vector, but with a length of one.
- Return
- A LeapVector object with a length of one, pointing in the same direction as this Vector object.
- Since 1.0
pitch- (float) pitchThe pitch angle in radians.
float pitchInRadians = thisVector.pitch;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.
- Return
- The angle of this vector above or below the horizon (x-z plane).
- Since 1.0
roll- (float) rollThe roll angle in radians.
float rollInRadians = thatVector.roll;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.
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.
- Return
- The angle of this vector to the right or left of the y-axis.
- Since 1.0
toFloatPointer- (NSMutableData *) toFloatPointerReturns an NSMutableData object containing the vector components as consecutive floating point values.
NSData *vectorData = thisVector.toFloatPointer; float x, y, z; [vectorData getBytes:&x length:sizeof(float)]; [vectorData getBytes:&y length:sizeof(float)]; [vectorData getBytes:&z length:sizeof(float)]; //Or access as an array of float: float array[3]; [vectorData getBytes:&array length:sizeof(float) * 3]; x = array[0]; y = array[1]; z = array[2];
- Since 1.0
toNSArray- (NSArray *) toNSArrayReturns an NSArray object containing the vector components in the order: x, y, z.
NSArray *vectorArray = thisVector.toNSArray;
- Since 1.0
x- (float) xThe horizontal component.
- Since 1.0
y- (float) yThe vertical component.
- Since 1.0
yaw- (float) yawThe yaw angle in radians.
float yawInRadians = thisVector.yaw;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.
- Return
- The angle of this vector to the right or left of the negative z-axis.
- Since 1.0
z- (float) zThe depth component.
- Since 1.0
+ (LeapVector *) backwardThe unit vector pointing backward along the positive z-axis: (0, 0, 1).
LeapVector *backwardVector = [LeapVector backward];
- Since 1.0
+ (LeapVector *) downThe unit vector pointing down along the negative y-axis: (0, -1, 0).
LeapVector *downVector = [LeapVector down];
- Since 1.0
+ (LeapVector *) forwardThe unit vector pointing forward along the negative z-axis: (0, 0, -1).
LeapVector *forwardVector = [LeapVector forward];
- Since 1.0
+ (LeapVector *) leftThe unit vector pointing left along the negative x-axis: (-1, 0, 0).
LeapVector *leftVector = [LeapVector left];
- Since 1.0
+ (LeapVector *) rightThe unit vector pointing right along the positive x-axis: (1, 0, 0).
LeapVector *rightVector = [LeapVector right];
- Since 1.0
+ (LeapVector *) upThe unit vector pointing up along the positive y-axis: (0, 1, 0).
LeapVector *upVector = [LeapVector up];
- Since 1.0
+ (LeapVector *) xAxis+ (LeapVector *) yAxis+ (LeapVector *) zAxis+ (LeapVector *) zero






