本文整理汇总了Java中processing.core.PVector.sub方法的典型用法代码示例。如果您正苦于以下问题:Java PVector.sub方法的具体用法?Java PVector.sub怎么用?Java PVector.sub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.core.PVector
的用法示例。
在下文中一共展示了PVector.sub方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finish
import processing.core.PVector; //导入方法依赖的package包/类
void finish(PVector p) {
if (done)
return;
p1 = pointsLookup.getPoint(p);
done = true;
// s0 must be on the "left" of this segment
PVector v0 = PVector.sub(p0, s0.pos), v1 = PVector.sub(p1, p0);
if (v0.x * v1.y - v0.y * v1.x < 0) { // z coordinate of the
// cross
// product
Site tmp = s0;
s0 = s1;
s1 = tmp;
}
}
示例2: rotate
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Rotates the scan around the scan center
*
* @param rotationAngle the scan rotation angle in radians
*/
public void rotate(float rotationAngle) {
// Rotate the scan points around the scan center
float cos = (float) Math.cos(rotationAngle);
float sin = (float) Math.sin(rotationAngle);
for (PVector point : points) {
point.sub(center);
point.set(cos * point.x - sin * point.z, point.y, sin * point.x + cos * point.z);
point.add(center);
}
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
示例3: scale
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Increases or decreases the size of the scan by a given factor
*
* @param scaleFactor the size scaling factor
*/
public void scale(float scaleFactor) {
// Scale the scan points
for (PVector point : points) {
point.sub(center);
point.mult(scaleFactor);
point.add(center);
}
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
// Update the maximum scan separation between points
setMaxPointSeparation(scaleFactor * getMaxPointSeparation());
}
示例4: savePoints
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Save the scan points and colors on a file
*
* @param fileName the file name
*/
public void savePoints(String fileName) {
// Create the array that will contain the file lines
String[] lines = new String[nPoints + 1];
// The first line contains the scan dimensions
lines[0] = width + " " + height;
// Write each point coordinates and color on a separate line
for (int index = 0; index < nPoints; index++) {
if (visibilityMask[index]) {
// Center the points coordinates
PVector point = PVector.sub(points[index], center);
int col = colors[index];
int red = (col >> 16) & 0xff;
int green = (col >> 8) & 0xff;
int blue = col & 0xff;
lines[index + 1] = point.x + " " + point.y + " " + point.z + " " + red + " " + green + " " + blue;
} else {
// Use a dummy line if the point should be masked
lines[index + 1] = "-99" + " " + "-99" + " " + "-99" + " " + "-99" + " " + "-99" + " " + "-99";
}
}
// Save the data on the file
p.saveStrings(fileName, lines);
}
示例5: getProjectedPointOnPlane
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Computes the 3D coordinates of a projected pixel in the tracking camera
* coordinate system.
*
* @param planeCalibCam projection plane
* @param px x axis in pixel coordinates
* @param py x axis in pixel coordinates
* @return
*/
public PVector getProjectedPointOnPlane(PlaneCalibration planeCalibCam, float px, float py) {
// Create ray from the projector (origin / viewed pixel)
// Intersect this ray with the piece of paper.
// Compute the Two points for the ray
PVector originP = new PVector(0, 0, 0);
PVector viewedPtP = getProjectiveDeviceP().pixelToWorldNormalized(px, py);
// Pass it to the camera point of view (origin)
PMatrix3D proCamExtrinsics = getExtrinsicsInv();
PVector originC = new PVector();
PVector viewedPtC = new PVector();
proCamExtrinsics.mult(originP, originC);
proCamExtrinsics.mult(viewedPtP, viewedPtC);
// Second argument is a direction
viewedPtC.sub(originC);
Ray3D ray = new Ray3D(new Vec3D(originC.x,
originC.y,
originC.z),
new Vec3D(viewedPtC.x,
viewedPtC.y,
viewedPtC.z));
// Intersect ray with Plane
ReadonlyVec3D inter = planeCalibCam.getPlane().getIntersectionWithRay(ray);
if (inter == null) {
return null;
}
return new PVector(inter.x(), inter.y(), inter.z());
}
示例6: computeRotation
import processing.core.PVector; //导入方法依赖的package包/类
protected float computeRotation(Touch touch0, Touch touch1) {
PVector currentDirection = PVector.sub(touch0.pposition, touch1.pposition);
PVector previousDirection = PVector.sub(touch0.position, touch1.position);
currentDirection.normalize();
previousDirection.normalize();
float cos = currentDirection.dot(previousDirection);
float angle = acos(cos);
PVector sin = currentDirection.cross(previousDirection);
if (sin.z < 0) {
angle = -angle;
}
return angle;
}
示例7: computeScale
import processing.core.PVector; //导入方法依赖的package包/类
protected float computeScale(Touch touch0, Touch touch1) {
PVector distT0 = touch0.pposition.get();
distT0.sub(touch1.pposition);
PVector distT1 = touchs[0].position.get();
distT1.sub(touch1.position);
return distT1.mag() / distT0.mag();
}
示例8: computeTranslate
import processing.core.PVector; //导入方法依赖的package包/类
protected PVector computeTranslate(Touch touch0, Touch touch1) {
PVector previousCenter = PVector.add(touch0.pposition, touch1.pposition);
previousCenter.mult(0.5f);
PVector currentCenter = PVector.add(touch0.position, touch1.position);
currentCenter.mult(0.5f);
PVector diff = PVector.sub(currentCenter, previousCenter);
// diff.mult(0.5f);
return diff;
}
示例9: getAngleBetween
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Calculates angle between two points, i.e. between the sum vector and the x-axis.
*
* @param p1
* The first point.
* @param p2
* The second point.
* @return The angle between both points.
*/
public static float getAngleBetween(PVector p1, PVector p2) {
// float angle = (float) Math.atan2(p2.y - p1.y, p2.x - p1.x);
// Note: Raw values between point 1 and point 2 not valid, as they are are origin-based.
PVector sub = PVector.sub(p2, p1);
PVector xaxis = new PVector(1, 0);
float angle = PVector.angleBetween(xaxis, sub);
if (p2.y < p1.y) {
angle = PApplet.TWO_PI - angle;
}
return angle;
}
示例10: combineSlits
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Creates a scan from the combination of several slits, assuming that all have the same orientation and dimensions
*
* @param p the parent Processing applet
* @param slitList the list of slits to combine
* @param rotate if true the slits will rotated around their center
* @param commonCenter if true all the slits will be moved to have the same center
* @return the scan formed from the combination of the slits
*/
public static Scan combineSlits(PApplet p, ArrayList<Slit> slitList, boolean rotate, boolean commonCenter) {
// Create an empty scan with the same center as the last slit added to the list
Slit slit = slitList.get(slitList.size() - 1);
boolean verticalSlits = slit.vertical;
int width = verticalSlits ? slitList.size() : slit.points.length;
int height = verticalSlits ? slit.points.length : slitList.size();
Scan scan = new Scan(p, width, height);
scan.center.set(slit.center);
// Loop over the slits in the list and fill the scan arrays
for (int i = 0; i < slitList.size(); i++) {
slit = slitList.get(i);
float offset = (slitList.size() - 1 - i) * 5;
float rotationAngle = 4 * (slitList.size() - 1 - i) * PApplet.PI / 180;
float cos = PApplet.cos(rotationAngle);
float sin = PApplet.sin(rotationAngle);
for (int j = 0; j < slit.points.length; j++) {
if (slit.visibilityMask[j]) {
int index = verticalSlits ? i + j * width : j + i * width;
PVector point = scan.points[index];
point.set(slit.points[j]);
// Check if the slit points should be rotated or shifted
if (rotate) {
point.sub(slit.center);
if (verticalSlits) {
point.set(cos * point.x - sin * point.z, point.y, sin * point.x + cos * point.z);
} else {
point.set(point.x, cos * point.y - sin * point.z, sin * point.y + cos * point.z);
}
point.add(slit.center);
} else {
if (verticalSlits) {
point.x += offset;
} else {
point.y += offset;
}
}
// Check if the slit points should be moved to have the same center
if (commonCenter) {
point.sub(slit.center);
point.add(scan.center);
}
scan.colors[index] = slit.colors[j];
scan.visibilityMask[index] = true;
}
}
}
return scan;
}
示例11: projectPointer3DVec3D
import processing.core.PVector; //导入方法依赖的package包/类
protected ReadonlyVec3D projectPointer3DVec3D(Screen screen, float px, float py) {
// Create ray from the projector (origin / viewed pixel)
// Intersect this ray with the piece of paper.
// Compute the Two points for the ray
PVector originP = new PVector(0, 0, 0);
PVector viewedPtP = projectiveDeviceP.pixelToWorldNormP((int) (px * frameWidth), (int) (py * frameHeight));
// Pass it to the camera point of view (origin)
PMatrix3D extr = extrinsicsInv;
PVector originC = new PVector();
PVector viewedPtC = new PVector();
extr.mult(originP, originC);
extr.mult(viewedPtP, viewedPtC);
// Second argument is a direction
viewedPtC.sub(originC);
Ray3D ray
= new Ray3D(new Vec3D(originC.x,
originC.y,
originC.z),
new Vec3D(viewedPtC.x,
viewedPtC.y,
viewedPtC.z));
// Intersect ray with Plane
// TODO: Do no use screen.getPlane !!!
ReadonlyVec3D inter = screen.getPlane().getIntersectionWithRay(ray);
// It may not intersect.
if (inter == null) {
return null;
} else {
return inter;
}
// Check the error of the ray casting -- Debug only
// PVector inter1P = new PVector();
// projExtrinsicsP3D.mult(interP, inter1P);
// PVector px2 = projectiveDeviceP.worldToPixel(inter1P, false);
// px2.sub(px * frameWidth, py * frameHeight, 0);
// System.out.println("Error " + px2.mag());
}
示例12: setPrevPos
import processing.core.PVector; //导入方法依赖的package包/类
public void setPrevPos(PVector prevPosition) {
pposition = prevPosition;
speed = PVector.sub(prevPosition, position);
}
示例13: compute3DPoint
import processing.core.PVector; //导入方法依赖的package包/类
/**
* *
*
* @param projectedPoint in 3D coordinate of the projector
* @param detectedPoint in 2D coordinate of the camera
* @return the 3D intersection or null if the error is too important.
*/
public PVector compute3DPoint(PVector projectedPoint, PVector detectedPoint) {
// We create two diffent "rays", so 4 different locations:
// Projector location, point seen by the projector.
// Camera location, point seen by the camera.
// The origin is the camera as always.
// point seen by the projector.
PVector projectedPointCam = new PVector();
extrinsicsInv.mult(projectedPoint, projectedPointCam);
projectedPointCam.sub(projPos);
// point seen the camera.
PVector observedPoint = cameraDevice.pixelToWorldNormP((int) detectedPoint.x, (int) detectedPoint.y);
PVector intersection = intersectLineWithLine3D(projPos, projectedPointCam,
camPos, observedPoint);
// We have the point, we can compute its error !
//////// Error computation ////////
// Intersection from the Projector's coordinate system.
PVector interProj = new PVector();
extrinsics.mult(intersection, interProj);
int w = projector.getWidth();
// int projCoord = projectorDevice.worldToPixel(interProj, true);
// PVector projPixels = new PVector((projCoord % w), projCoord / w);
PVector projPixels = projectorDevice.worldToPixel(interProj, true);
// Need Lens distorsions ?!
// int projCoordOrig = projectorDevice.worldToPixel(projectedPoint);
// PVector projPixelsOrig = new PVector((projCoordOrig % w), projCoordOrig / w);
PVector projPixelsOrig = projectorDevice.worldToPixel(projectedPoint, false);
// TODO : specify error || or create a struct ?
float errX = Math.abs(projPixelsOrig.x - projPixels.x);
float errY = Math.abs(projPixelsOrig.y - projPixels.y);
float error = PVector.dist(projPixels, projPixelsOrig);
lastError.x = errX;
lastError.y = errY;
lastError.z = error;
// Need Lens distorsions !
// println("Projected " + projPixelsOrig);
// if (error < 40) {
// return intersection;
// }
return intersection;
}
示例14: getDistanceBetween
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Calculates distance between two points, i.e. between the sum vector and the x-axis.
*
* @param p1
* The first point.
* @param p2
* The second point.
* @return The distance between both points.
*/
public static float getDistanceBetween(PVector p1, PVector p2) {
// Note: Raw values between point 1 and point 2 not valid, as they are are origin-based.
PVector sub = PVector.sub(p1, p2);
PVector xaxis = new PVector(1, 0);
float dist = PVector.dist(sub, xaxis);
return dist;
}