SOFA plugin: LeapMotion  master
Open source framework for multi-physics simuation
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Leap::Vector Struct Reference

#include <LeapMath.h>

Detailed Description

The Vector struct 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 Attributes

float x
 
float y
 
float z
 

Public Member Functions

 Vector ()
 
 Vector (float _x, float _y, float _z)
 
 Vector (const Vector &vector)
 
float magnitude () const
 
float magnitudeSquared () const
 
float distanceTo (const Vector &other) const
 
float angleTo (const Vector &other) const
 
float pitch () const
 
float yaw () const
 
float roll () const
 
float dot (const Vector &other) const
 
Vector cross (const Vector &other) const
 
Vector normalized () const
 
Vector operator- () const
 
Vector operator+ (const Vector &other) const
 
Vector operator- (const Vector &other) const
 
Vector operator* (float scalar) const
 
Vector operator/ (float scalar) const
 
Vectoroperator+= (const Vector &other)
 
Vectoroperator-= (const Vector &other)
 
Vectoroperator*= (float scalar)
 
Vectoroperator/= (float scalar)
 
std::string toString () const
 
bool operator== (const Vector &other) const
 
bool operator!= (const Vector &other) const
 
bool isValid () const
 
float operator[] (unsigned int index) const
 
const float * toFloatPointer () const
 
template<typename Vector3Type >
const Vector3Type toVector3 () const
 
template<typename Vector4Type >
const Vector4Type toVector4 (float w=0.0f) const
 

Static Public Member Functions

static const Vectorzero ()
 
static const VectorxAxis ()
 
static const VectoryAxis ()
 
static const VectorzAxis ()
 
static const Vectorleft ()
 
static const Vectorright ()
 
static const Vectordown ()
 
static const Vectorup ()
 
static const Vectorforward ()
 
static const Vectorbackward ()
 

Friends

Vector operator* (float scalar, const Vector &vector)
 
std::ostream & operator<< (std::ostream &out, const Vector &vector)
 

Attribute details

◆ x

float Leap::Vector::x

The horizontal component.

◆ y

float Leap::Vector::y

The vertical component.

◆ z

float Leap::Vector::z

The depth component.

Constructor details

◆ Vector() [1/3]

Leap::Vector::Vector ( )
inline

Creates a new Vector with all components set to zero.

◆ Vector() [2/3]

Leap::Vector::Vector ( float  _x,
float  _y,
float  _z 
)
inline

Creates a new Vector with the specified component values.

◆ Vector() [3/3]

Leap::Vector::Vector ( const Vector vector)
inline

Copies the specified Vector.

Function details

◆ angleTo()

float Leap::Vector::angleTo ( const Vector other) const
inline

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.

Parameters
otherA Vector object.
Returns
The angle between this vector and the specified vector in radians.

◆ backward()

static const Vector& Leap::Vector::backward ( )
inlinestatic

The unit vector pointing backward along the positive z-axis: (0, 0, 1)

◆ cross()

Vector Leap::Vector::cross ( const Vector other) const
inline

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).

Parameters
otherA Vector object.
Returns
The cross product of this vector and the specified vector.

◆ distanceTo()

float Leap::Vector::distanceTo ( const Vector other) const
inline

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

Parameters
otherA Vector object.
Returns
The distance from this point to the specified point.

◆ dot()

float Leap::Vector::dot ( const Vector other) const
inline

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.

Parameters
otherA Vector object.
Returns
The dot product of this vector and the specified vector.

◆ down()

static const Vector& Leap::Vector::down ( )
inlinestatic

The unit vector pointing down along the negative y-axis: (0, -1, 0)

◆ forward()

static const Vector& Leap::Vector::forward ( )
inlinestatic

The unit vector pointing forward along the negative z-axis: (0, 0, -1)

◆ isValid()

bool Leap::Vector::isValid ( ) const
inline

Returns true if all of the vector's components are finite. If any component is NaN or infinite, then this returns false.

◆ left()

static const Vector& Leap::Vector::left ( )
inlinestatic

The unit vector pointing left along the negative x-axis: (-1, 0, 0)

◆ magnitude()

float Leap::Vector::magnitude ( ) const
inline

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.

Returns
The length of this vector.

◆ magnitudeSquared()

float Leap::Vector::magnitudeSquared ( ) const
inline

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

Returns
The square of the length of this vector.

◆ normalized()

Vector Leap::Vector::normalized ( ) const
inline

A normalized copy of this vector.

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

Returns
A Vector object with a length of one, pointing in the same direction as this Vector object.

◆ operator!=()

bool Leap::Vector::operator!= ( const Vector other) const
inline

Compare Vector inequality component-wise.

◆ operator*()

Vector Leap::Vector::operator* ( float  scalar) const
inline

Multiply vector by a scalar.

◆ operator*=()

Vector& Leap::Vector::operator*= ( float  scalar)
inline

Multiply vector by a scalar and assign the product.

◆ operator+()

Vector Leap::Vector::operator+ ( const Vector other) const
inline

Add vectors component-wise.

◆ operator+=()

Vector& Leap::Vector::operator+= ( const Vector other)
inline

Add vectors component-wise and assign the sum.

◆ operator-() [1/2]

Vector Leap::Vector::operator- ( ) const
inline

A copy of this vector pointing in the opposite direction.

Returns
A Vector object with all components negated.

◆ operator-() [2/2]

Vector Leap::Vector::operator- ( const Vector other) const
inline

Subtract vectors component-wise.

◆ operator-=()

Vector& Leap::Vector::operator-= ( const Vector other)
inline

Subtract vectors component-wise and assign the difference.

◆ operator/()

Vector Leap::Vector::operator/ ( float  scalar) const
inline

Divide vector by a scalar.

◆ operator/=()

Vector& Leap::Vector::operator/= ( float  scalar)
inline

Divide vector by a scalar and assign the quotient.

◆ operator==()

bool Leap::Vector::operator== ( const Vector other) const
inline

Compare Vector equality component-wise.

◆ operator[]()

float Leap::Vector::operator[] ( unsigned int  index) const
inline

Index vector components numerically. Index 0 is x, index 1 is y, and index 2 is z.

Returns
The x, y, or z component of this Vector, if the specified index value is at least 0 and at most 2; otherwise, returns zero.

◆ pitch()

float Leap::Vector::pitch ( ) const
inline

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.

Returns
The angle of this vector above or below the horizon (x-z plane).

◆ right()

static const Vector& Leap::Vector::right ( )
inlinestatic

The unit vector pointing right along the positive x-axis: (1, 0, 0)

◆ roll()

float Leap::Vector::roll ( ) const
inline

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.

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.

Returns
The angle of this vector to the right or left of the y-axis.

◆ toFloatPointer()

const float* Leap::Vector::toFloatPointer ( ) const
inline

Cast the vector to a float array.

◆ toString()

std::string Leap::Vector::toString ( ) const
inline

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

◆ toVector3()

template<typename Vector3Type >
const Vector3Type Leap::Vector::toVector3 ( ) const
inline

Convert a Leap::Vector to another 3-component Vector type.

The specified type must define a constructor that takes the x, y, and z components as separate parameters.

◆ toVector4()

template<typename Vector4Type >
const Vector4Type Leap::Vector::toVector4 ( float  w = 0.0f) const
inline

Convert a Leap::Vector to another 4-component Vector type.

The specified type must define a constructor that takes the x, y, z, and w components as separate parameters. (The homogeneous coordinate, w, is set to zero by default, but you should typically set it to one for vectors representing a position.)

◆ up()

static const Vector& Leap::Vector::up ( )
inlinestatic

The unit vector pointing up along the positive y-axis: (0, 1, 0)

◆ xAxis()

static const Vector& Leap::Vector::xAxis ( )
inlinestatic

The x-axis unit vector: (1, 0, 0)

◆ yaw()

float Leap::Vector::yaw ( ) const
inline

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.

Returns
The angle of this vector to the right or left of the negative z-axis.

◆ yAxis()

static const Vector& Leap::Vector::yAxis ( )
inlinestatic

The y-axis unit vector: (0, 1, 0)

◆ zAxis()

static const Vector& Leap::Vector::zAxis ( )
inlinestatic

The z-axis unit vector: (0, 0, 1)

◆ zero()

static const Vector& Leap::Vector::zero ( )
inlinestatic

The zero vector: (0, 0, 0)

Related details

◆ operator*

Vector operator* ( float  scalar,
const Vector vector 
)
friend

Multiply vector by a scalar on the left-hand side (C++ only).

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Vector vector 
)
friend

Writes the vector to the output stream using a human readable format: (x, y, z).