本文整理汇总了Java中com.leapmotion.leap.Vector类的典型用法代码示例。如果您正苦于以下问题:Java Vector类的具体用法?Java Vector怎么用?Java Vector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vector类属于com.leapmotion.leap包,在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseToCurves
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Gets the curve (path) of each of the fingers
* @return the set of curves which are each finger
*/
public Curve[] parseToCurves() {
Curve[] c = new Curve[5];
for (int i = 0; i < c.length; i++) {
c[i] = new Curve();
}
for (int i = 0; i < data.handList.size(); i++) {
HandShape hs = data.handList.get(i);
for (int i2 = 0; i2 < hs.getPos().length; i2++) {
Vector thisPoint = hs.getPos()[i2];
c[i2].addPoint(thisPoint.getX(), thisPoint.getY(),
thisPoint.getZ(), (float) i);
}
}
return c;
}
示例2: getJointAngle
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Return the angle of the finger for the hand specified This computes the
* angle based on the dot product of the palmNormal and the fingerDirection
* Theta = arccos( (V1.V2) / ( |V1| * |V2| )
*
* @param hand
* - "left" or "right"
* @param tip
* - 0 (thumb) / 1 (index) .. etc..
* @return angle in degrees
*/
public double getJointAngle(String hand, Integer tip) {
com.leapmotion.leap.Hand h = null;
if ("left".equalsIgnoreCase(hand)) {
// left hand
h = controller.frame().hands().leftmost();
} else {
// right hand
h = controller.frame().hands().rightmost();
}
// TODO: does this return the correct finger?
Finger f = h.fingers().get(tip);
Vector palmNormal = h.palmNormal();
Vector fDir = f.direction();
// TODO: validate that this is what we actually want.
// otherwise we can directly compute the angleTo in java.
float angleInRadians = palmNormal.angleTo(fDir);
// convert to degrees so it's easy to pass to servos
double angle = Math.toDegrees(angleInRadians);
return angle;
}
示例3: getJointAngle
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Return the angle of the finger for the hand specified This computes the
* angle based on the dot product of the palmNormal and the fingerDirection
* Theta = arccos( (V1.V2) / ( |V1| * |V2| )
*
* @param hand
* - "left" or "right"
* @param tip
* - 0 (thumb) / 1 (index) .. etc..
* @return angle in degrees
*/
public double getJointAngle(String hand, Integer tip) {
com.leapmotion.leap.Hand h = null;
if ("left".equalsIgnoreCase(hand)) {
// left hand
h = controller.frame().hands().leftmost();
} else {
// right hand
h = controller.frame().hands().rightmost();
}
// TODO: does this return the correct finger?
Finger f = h.fingers().get(tip);
Vector palmNormal = h.palmNormal();
Vector fDir = f.direction();
// TODO: validate that this is what we actually want.
// otherwise we can directly compute the angleTo in java.
float angleInRadians = palmNormal.angleTo(fDir);
// convert to degrees so it's easy to pass to servos
double angle = Math.toDegrees(angleInRadians);
return angle;
}
示例4: calculateProjectionOfFinger
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private Vector calculateProjectionOfFinger(Vector fingerPoint, AppScreenPlan screenPlan) {
//TODO: Verify and test the equation
Vector p1 = screenPlan.getP1();
float d = -(planNormalVector.getX() * p1.getX()
+ planNormalVector.getY() * p1.getY()
+ planNormalVector.getZ() * p1.getZ());
float k = -(planNormalVector.getX() * fingerPoint.getX()
+ planNormalVector.getY() * fingerPoint.getY()
+ planNormalVector.getZ() * fingerPoint.getZ()+ d)
/ (planNormalVector.getX()* planNormalVector.getX()
+ planNormalVector.getY()* planNormalVector.getY()
+ planNormalVector.getZ()* planNormalVector.getZ()
);
Vector PF = new Vector(fingerPoint.getX()
-(k* planNormalVector.getX()), fingerPoint.getY()
-(k* planNormalVector.getY()), fingerPoint.getZ()
-(k* planNormalVector.getZ()));
return PF;
}
示例5: getTipOnScreen
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* to use this utility you have to have the leap calibrated to your screen.
*
* @param pointable the finger you want the intersection with your screen from
* @return null until rewritten
*/
public Vector3f getTipOnScreen(Pointable pointable) {
Vector3f pos;
ScreenList sl = controller.locatedScreens();
com.leapmotion.leap.Screen calibratedScreen = sl.get(activeScreenNr);
Vector loc = calibratedScreen.intersect(pointable, true);
//TODO: Processing specific code commented out for Jitter
/*
float x = PApplet.map(loc.getX(), 0, 1, 0, p.displayWidth);
x -= p.getLocationOnScreen().x;
float y = PApplet.map(loc.getY(), 0, 1, p.displayHeight, 0);
y -= p.getLocationOnScreen().y;
pos = new Vector3f(x, y, 0f);
return pos;
*/
return null;
}
示例6: getDetectionData
import com.leapmotion.leap.Vector; //导入依赖的package包/类
public DetectionData getDetectionData(Hand hand)
{
// Get the hand's normal vector and direction
Vector normal = hand.palmNormal();
Vector direction = hand.direction();
float pitch = ((Double) Math.toDegrees(direction.pitch())).floatValue()
/ MAX_PITCH;
float roll = ((Double) Math.toDegrees(normal.roll())).floatValue()
/ MAX_ROLL;
float yaw = ((Double) Math.toDegrees(direction.yaw())).floatValue()
/ MAX_YAW;
float height = hand.palmPosition().getY() / MAX_HEIGHT;
return new DetectionData(roll, pitch, yaw, height);
}
示例7: readObject
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
palmLocation = new Vector(in.readFloat(), in.readFloat(), in.readFloat());
palmDirection = new Vector(in.readFloat(), in.readFloat(), in.readFloat());
fingerPositions = new Vector[in.readInt()];
for(int i = 0; i < fingerPositions.length; i++){
fingerPositions[i] = new Vector(in.readFloat(), in.readFloat(), in.readFloat());
}
}
示例8: HandShape
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Constructs a hand shape from the Hand object
*
* @param hand
* the hand to construct the hand shape from
*/
public HandShape(Hand hand) {
if (hand.isLeft()) {
this.data.handSide = LEFT;
} else {
this.data.handSide = RIGHT;
}
this.data.fingerPositions = new Vector[hand.fingers().count()];
for (int i = 0; i < data.fingerPositions.length; i++) {
data.fingerPositions[i] = hand.fingers().get(i).tipPosition();
}
this.data.palmLocation = hand.palmPosition();
// this.data.handBasis = hand.basis();
this.data.palmDirection = hand.palmNormal();
}
示例9: standardizeVectors
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Standardizes the vectors by using the Z score
*
* @param vects
* the vectors you want to standardize
* @return the standardized vectors
*/
private Vector[] standardizeVectors(Vector[] vects) {
float[] xArr = new float[vects.length];
float[] yArr = new float[vects.length];
float[] zArr = new float[vects.length];
for (int i = 0; i < vects.length; i++) {
xArr[i] = vects[i].getX();
yArr[i] = vects[i].getY();
zArr[i] = vects[i].getZ();
}
float xMean = Stats.getMean(xArr);
float xStdDev = Stats.getStdDev(xArr, xMean);
float yMean = Stats.getMean(yArr);
float yStdDev = Stats.getStdDev(yArr, yMean);
float zMean = Stats.getMean(zArr);
float zStdDev = Stats.getStdDev(zArr, zMean);
for (int i = 0; i < xArr.length; i++) {
xArr[i] = (xArr[i] - xMean) / xStdDev;
}
for (int i = 0; i < yArr.length; i++) {
yArr[i] = (yArr[i] - yMean) / yStdDev;
}
for (int i = 0; i < zArr.length; i++) {
zArr[i] = (zArr[i] - zMean) / zStdDev;
}
Vector[] vecs = new Vector[vects.length];
for (int i = 0; i < vecs.length; i++) {
vecs[i] = new Vector(xArr[i], yArr[i], zArr[i]);
}
return vecs;
}
示例10: getRelPos
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Gets the position of the fingers relative to the palm
*
* @return the position of the fingers relative to the palm
*/
public Vector[] getRelPos() {
Vector relPos[] = new Vector[data.fingerPositions.length];
for (int i = 0; i < relPos.length; i++) {
relPos[i] = data.fingerPositions[i].minus(data.palmLocation);
}
return relPos;
}
示例11: isStatic
import com.leapmotion.leap.Vector; //导入依赖的package包/类
/**
* Determines if a hand sign is static or not based on the current palm
* orientation and the previous palm orientation
*
* @return boolean indicating whether the sign is static or not
*/
public boolean isStatic() {
if (last.data.handList.size() < PEEK_BACK_LENGTH)
return true;
HandShape previous = last.data.handList.get(last.data.handList.size() - PEEK_BACK_LENGTH);
HandShape current = last.data.handList.getLast();
Vector distance = current.data.palmLocation.minus(previous.data.palmLocation);
Vector orientation = current.data.palmDirection.minus(previous.data.palmDirection);
float fingerChange = current.distance(previous);
if (distance.magnitudeSquared() < DISTANCE_EPSILON
&& orientation.magnitudeSquared() < ORIENTATION_EPSILON
&& fingerChange < FINGER_EPSILON)
return true;
return false;
}
示例12: computeAngleDegrees
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private double computeAngleDegrees(Finger f, Vector palmNormal) {
Vector fDir = f.direction();
// TODO: validate that this is what we actually want.
// otherwise we can directly compute the angleTo in java.
double angleInRadians = palmNormal.angleTo(fDir);
// convert to degrees so it's easy to pass to servos
double angle = Math.toDegrees(angleInRadians);
return angle;
}
示例13: mapLeapHandData
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private LeapMotion2.Hand mapLeapHandData(Hand lh) {
LeapMotion2.Hand mrlHand = new LeapMotion2.Hand();
// process the normal
Vector palmNormal = lh.palmNormal();
mrlHand.palmNormalX = palmNormal.getX();
mrlHand.palmNormalY = palmNormal.getY();
mrlHand.palmNormalZ = palmNormal.getZ();
// handle the fingers.
for (Finger.Type t : Finger.Type.values()) {
Finger f = lh.fingers().get(t.ordinal());
double angle = computeAngleDegrees(f, palmNormal);
if (t.equals(Finger.Type.TYPE_INDEX))
mrlHand.index = angle;
else if (t.equals(Finger.Type.TYPE_MIDDLE))
mrlHand.middle = angle;
else if (t.equals(Finger.Type.TYPE_RING))
mrlHand.ring = angle;
else if (t.equals(Finger.Type.TYPE_PINKY))
mrlHand.pinky = angle;
else if (t.equals(Finger.Type.TYPE_THUMB))
mrlHand.thumb = angle;
else
log.warn("Unknown finger! eek..");
}
return mrlHand;
}
示例14: vAverage
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private Vector vAverage(LimitQueue<Vector> vectors){
float vx=0f, vy=0f, vz=0f;
for(Vector v:vectors){
vx=vx+v.getX();
vy=vy+v.getY();
vz=vz+v.getZ();
}
return new Vector(vx/vectors.size(), vy/vectors.size(), vz/vectors.size());
}
示例15: computeAngleDegrees
import com.leapmotion.leap.Vector; //导入依赖的package包/类
private double computeAngleDegrees(Finger f, Vector palmNormal) {
Vector fDir = f.direction();
// TODO: validate that this is what we actually want.
// otherwise we can directly compute the angleTo in java.
double angleInRadians = palmNormal.angleTo(fDir);
// convert to degrees so it's easy to pass to servos
double angle = Math.toDegrees(angleInRadians);
return angle;
}