Vector结构体(Leap::Vector)

Vector结构体(Leap::Vector)

这个结构体代表三维空间中的向量和点(三分量),还提供了一些有用的向量操作函数(在LeapMath.h中提供了这些数学函数的函数体)。Leap Motion的系统采用了右手笛卡尔坐标系。返回的数值都是以真实世界的毫米为单位(和Kinect的深度数据一样的)。原点在Leap Motion 控制器的中心。x轴和z轴在器件的水平面上,x轴和设备的长边平行。y轴是垂直的,以正值增加形式朝上(与计算机图形学的坐标系朝下的方向相反)。距离计算机屏幕越远,z轴正值不断增加(摆放时要确保那个小绿灯朝向我们)。如下图。

这里写图片描述

float x: 表示水平分量。
float y: 表示垂直分量。
float z: 表示深度分量。
float angleTo(const Vector & other): 表示这个向量与一个指定的向量之间的角度,单位是弧度。这个角度是在形成这两个向量的平面上衡量的,返回的角总是两个共轭角中较小的那个。因此A.angleTo(B)== B.angleTo(A),而且总是不大于pi弧度。如果其中一个向量长度为0,则该函数返回0.

这里写图片描述

用法:float angleInRadians=Vector::xAxis().angleTo(Vector::yAxis());
//the angle between the x and y axes
Vector cross(const Vector & other): 表示这个向量与一个指定的向量的向量积。这个向量积与这两个向量是正交的,大小等于以这两个向量为边的平行四边形的面积,方向由右手定则决定。因此A.cross(B)== -B.cross(A).

这里写图片描述

用法:Vector crossProduct=thisVector.cross(thatVector);
float distanceTo(const Vector & other): 表示由这个Vector结构体表示的点与一个指定的Vector对象表示的点之间的距离。
用法:Vector aPoint = Vector(10, 0, 0);
Vector origin = Vector::zero();
float distance = origin.distanceTo(aPoint); // distance = 10
float cross(const Vector & other): 表示这个向量与一个指定的向量的点积。大小是这个向量在一个指定的向量上的投影。

这里写图片描述

用法:float dotProduct=thisVector.dot(thatVector);
bool isValid(): 如果向量所有的元素是有限的,则返回True。如果任何一个元素是非数值或者是无穷的,则返回false。
用法:bool vectorIsValid=thisVector.isValid();
float magnitude(): 表示这个向量的大小或长度。这个大小是这个Vector结构体的L2范数或是欧氏距离。如果Vector对象是(x,y,z),则该函数返回sqrt(x*x + y*y + z*z)。
用法:float length=thisVector. magnitude();
float magnitudeSquared(): 表示这个向量的大小或长度的平方。如果Vector对象是(x,y,z),则该函数返回x*x + y*y + z*z。
用法:float lengthSquared=thisVector. magnitudeSquared();
Vector normalized(): 表示这个向量的归一化复制。归一化方向不变,长度为1.
用法:Vector normalVector=otherVector. normalized();
bool operator!=(const Vector & other): 比较Vector结构体中的元素是否不相等。
Vector operator*(float scalar): 表示向量乘以一个标量。
用法:Vector product=thisVector*5.0;
Vector & operator*=(float scalar): 表示向量乘以一个标量,把值赋给结果。
Vector operator + ( const Vector & other): 表示与一个向量元素相加。
用法:Vector sum=thisVector+ thatVector;
Vector & operator+=( const Vector & other): 表示与一个向量元素相加,把值赋给结果。
Vector operator - (): 表示复制这个向量,指向相反的方向。
用法:Vector negation= - thisVector;
Vector operator - ( const Vector & other): 表示与一个向量元素相减。
用法:Vector difference=thisVector - thatVector;
Vector & operator-=( const Vector & other): 表示与一个向量元素相减,把值赋给结果。
Vector operator / (float scalar): 表示向量除以一个标量。
用法:Vector quotient=thisVector / 2.5;
Vector & operator/=(float scalar): 表示向量乘以一个标量,把值赋给商。
bool operator==(const Vector & other): 比较Vector结构体中的元素是否相等。
float operator[](unsigned int index): 表示向量元素的索引。0表示x,1表示y,2表示z。
用法:float x= thisVector[0];
float y= thisVector[1];
float z= thisVector[2];
float pitch(): 表示俯仰角(弧度)。俯仰角是向量在y-z平面上的投影与-z轴的夹角。换句话说,俯仰角代表了绕x轴的旋转。如果向量指向上方,则返回的角度在0到pi之间。如果向量指向下方,则返回的角度在0到-pi之间。

这里写图片描述

用法:float pitchInRadians= thisVector.pitch();
float roll(): 表示侧倾角(弧度)。俯仰角是向量在x-y平面上的投影与y轴的夹角。换句话说,俯仰角代表了绕z轴的旋转。如果向量指向左方,则返回的角度在0到pi之间。如果向量指向右方,则返回的角度在0到-pi之间。

这里写图片描述

用法:float rollInRadians= thisVector.roll();
const float * toFloatPointer(): 表示把向量投影为浮点数组。
用法:const float *vectorData = thisVector.toFloatPointer();
float x = *vectorData;
float y = *(++vectorData);
float z = *(++vectorData);
std::string toString(): 返回包含这个向量的字符串,格式为(x,y,z)。
template
const Vector3Type toVector3(): 表示把Leap::Vector转化为另一种三分量的Vector形式。这种指定的形式必须定义一个构造器,把x,y,z分量作为独立的参数。
template
const Vector4Type toVector4(float w=0.0f): 表示把Leap::Vector转化为另一种四分量的Vector形式(齐次坐标)。这种指定的形式必须定义一个构造器,把x,y,z,w分量作为独立的参数。其中,w默认为0,但是经常需要设为1,代表一个方向。
Vector(): 创建一个新的Vector对象,所有的元素设为0.
Vector(float _x,float _y,float _z): 创建一个新的Vector结构体,每个元素带有指定的值。
用法:Vector newVector=Vector(0.5,200.3,67);
Vector(const Vector & vector): 复制一个指定的Vector。
用法:Vector copiedVector=Vector(otherVector);
float yaw(): 表示偏航角(弧度)。俯仰角是向量在x-z平面上的投影与-z轴的夹角。换句话说,俯仰角代表了绕y轴的旋转。如果向量指向-z轴的右边,则返回的角度在0到pi之间。如果向量指向左边,则返回的角度在0到-pi之间。

这里写图片描述

用法:float yawInRadians= thisVector.yaw();
const Vector & backward(): 表示指向z轴正方向的单位向量:(0,0,1)。
用法:Vector backwardVector=Vector::backward();
const Vector & forward(): 表示指向z轴反方向的单位向量:(0,0,-1)。
用法:Vector forwardVector=Vector::forward();
const Vector & down(): 表示指向y轴反方向的单位向量:(0,-1,0)。
用法:Vector downVector=Vector::down();
const Vector & up(): 表示指向y轴正方向的单位向量:(0,1,0)。
用法:Vector upVector=Vector::up();
const Vector & left(): 表示指向x轴反方向的单位向量:(-1,0,0)。
用法:Vector leftVector=Vector::down();
const Vector & right(): 表示指向x轴正方向的单位向量:(1,0,0)。
用法:Vector rightVector=Vector::right();
const Vector & xAxis(): 表示x轴的单位向量:(1,0,0)。
用法:Vector xAxisVector=Vector::xAxis();
const Vector & yAxis(): 表示y轴的单位向量:(0,1,0)。
用法:Vector yAxisVector=Vector::yAxis();
const Vector & zAxis(): 表示z轴的单位向量:(0,0,1)。
用法:Vector zAxisVector=Vector::zAxis();
const Vector & zero(): 表示零向量:(0,0,0)。
用法:Vector zeroVector=Vector::zero();

译自:https://developer.leapmotion.com/documentation/cpp/api/Leap.Vector.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值