本文整理汇总了Java中processing.core.PVector.add方法的典型用法代码示例。如果您正苦于以下问题:Java PVector.add方法的具体用法?Java PVector.add怎么用?Java PVector.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.core.PVector
的用法示例。
在下文中一共展示了PVector.add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersectionSegments
import processing.core.PVector; //导入方法依赖的package包/类
PVector intersectionSegments(Segment s, PVector p1, PVector p2) {
final float eps = 1e-10f;
PVector p3 = s.p0, p4 = s.p1;
float den = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);
float numa = (p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x);
float numb = (p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x);
if (PApplet.abs(numa) < eps && PApplet.abs(numb) < eps && PApplet.abs(den) < eps) // Coincident
return PVector.add(PVector.mult(p1, 0.5f), PVector.mult(p2, 0.5f));
if (PApplet.abs(den) < eps)
return null; // Parallel
float mua = numa / den, mub = numb / den;
if (mua < 0 || mua > 1 || mub < 0 || mub > 1)
return null; // Outside of the segments
return PVector.add(PVector.mult(p1, 1 - mua), PVector.mult(p2, mua));
}
示例2: relaxEdges
import processing.core.PVector; //导入方法依赖的package包/类
void relaxEdges() {
ArrayList<PVector> tempPos = new ArrayList<PVector>();
for (int i = 0; i < pointsList.size(); i++) {
Point pt = pointsList.get(i);
if (pt.border)
tempPos.add(pt.pos);
else {
PVector p = new PVector(0, 0);
for (Face f : pt.faces)
p.add(f.pos);
p.mult(1.0f / pt.faces.size());
tempPos.add(p);
}
}
for (int i = 0; i < tempPos.size(); i++)
pointsList.get(i).pos = lerpVector(pointsList.get(i).pos, tempPos.get(i), relaxEdgesAmount);
}
示例3: 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;
}
示例4: 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());
}
示例5: getCentroid
import processing.core.PVector; //导入方法依赖的package包/类
PVector getCentroid() {
PVector centroid = new PVector();
float area = 0;
int nb = points.size();
PVector p2 = points.get(nb - 1).pos;
for (Point p : points) {
float a = p.pos.x * p2.y - p2.x * p.pos.y; // (cross
// product)
area += a;
centroid.add(PVector.mult(PVector.add(p.pos, p2), a));
p2 = p.pos;
}
centroid.mult(1 / (3 * area));
return centroid;
}
示例6: translate
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Translates the scan position and the scan center
*
* @param translationVector the translation vector
*/
public void translate(PVector translationVector) {
// Translate the scan points
for (PVector point : points) {
point.add(translationVector);
}
// Translate the scan center
center.add(translationVector);
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
示例7: 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;
}
示例8: 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;
}
示例9: reduceResolution
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Reduces the scan resolution by a given factor, smoothing the points at the same time
*
* @param reductionFactor the scale reduction factor
*/
public void reduceResolution(int reductionFactor) {
if (reductionFactor > 1) {
// Obtain the dimensions of the new reduced arrays
int widthNew = width / reductionFactor + 2;
int heightNew = height / reductionFactor + 2;
int nPointsNew = widthNew * heightNew;
PVector[] pointsNew = new PVector[nPointsNew];
int[] colorsNew = new int[nPointsNew];
boolean[] visibilityMaskNew = new boolean[nPointsNew];
// Populate the arrays
for (int row = 0; row < heightNew; row++) {
for (int col = 0; col < widthNew; col++) {
int indexNew = col + row * widthNew;
// Average between nearby pixels
PVector pointAverage = new PVector();
int redAverage = 0;
int greenAverage = 0;
int blueAverage = 0;
int counter = 0;
for (int i = -reductionFactor / 2; i <= reductionFactor / 2; i++) {
for (int j = -reductionFactor / 2; j <= reductionFactor / 2; j++) {
int rowNearby = row * reductionFactor + i;
int colNearby = col * reductionFactor + j;
if (colNearby >= 0 && colNearby < width && rowNearby >= 0 && rowNearby < height) {
int indexNearby = colNearby + rowNearby * width;
if (visibilityMask[indexNearby]) {
pointAverage.add(points[indexNearby]);
int color = colors[indexNearby];
redAverage += (color >> 16) & 0xff;
greenAverage += (color >> 8) & 0xff;
blueAverage += color & 0xff;
counter++;
}
}
}
}
if (counter > 0) {
pointsNew[indexNew] = pointAverage.div(counter);
colorsNew[indexNew] = ((redAverage / counter) << 16) | ((greenAverage / counter) << 8)
| (blueAverage / counter) | 0xff000000;
visibilityMaskNew[indexNew] = true;
} else {
pointsNew[indexNew] = pointAverage;
}
}
}
// Update the arrays to the new resolution
width = widthNew;
height = heightNew;
nPoints = nPointsNew;
points = pointsNew;
colors = colorsNew;
visibilityMask = visibilityMaskNew;
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
}
示例10: gaussianSmooth
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Smoothes the scan points using a Gaussian kernel
*
* @param kernelSize the kernel size. Should be an odd number larger than 1
*/
public void gaussianSmooth(int kernelSize) {
if (kernelSize > 1) {
// Make sure that the kernel size is an even number
if (kernelSize % 2 == 0) {
kernelSize++;
}
// Create the Gaussian kernel
float[][] kernel = new float[kernelSize][kernelSize];
int kernelMiddlePoint = (kernelSize - 1) / 2;
float maxDistanceSq = PApplet.sq(kernelMiddlePoint);
float sigmaSq = PApplet.sq(kernelMiddlePoint / 2f);
for (int i = 0; i < kernelSize; i++) {
for (int j = 0; j < kernelSize; j++) {
float distanceSq = PApplet.sq(i - kernelMiddlePoint) + PApplet.sq(j - kernelMiddlePoint);
if (distanceSq <= maxDistanceSq) {
kernel[i][j] = PApplet.pow(2.718f, -distanceSq / (2 * sigmaSq));
}
}
}
// Calculate the smoothed points
PVector[] smoothedPoints = new PVector[nPoints];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
int index = col + row * width;
if (visibilityMask[index]) {
PVector pointsSum = new PVector();
float kernelValueCounter = 0;
for (int i = 0; i < kernelSize; i++) {
int rowStep = row - kernelMiddlePoint + i;
for (int j = 0; j < kernelSize; j++) {
int colStep = col - kernelMiddlePoint + j;
if (colStep >= 0 && colStep < width && rowStep >= 0 && rowStep < height) {
int indexStep = colStep + rowStep * width;
if (visibilityMask[indexStep]) {
PVector pointStep = points[indexStep];
float kernelValue = kernel[i][j];
if (kernelValue != 0 && connected(points[index], pointStep)) {
pointsSum.add(kernelValue * pointStep.x, kernelValue * pointStep.y,
kernelValue * pointStep.z);
kernelValueCounter += kernelValue;
}
}
}
}
}
smoothedPoints[index] = pointsSum.div(kernelValueCounter);
} else {
smoothedPoints[index] = points[index];
}
}
}
// Update the points array
points = smoothedPoints;
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
}
示例11: initDraw
import processing.core.PVector; //导入方法依赖的package包/类
public void initDraw(Camera cam, PVector userPos, float nearPlane, float farPlane, boolean isAnaglyph, boolean isLeft, boolean isOnly) {
PGraphicsOpenGL graphics = getGraphics();
if (initPosM == null) {
this.isOpenGL = true;
// Transformation Camera -> Marker
initPosM = this.getLocation(cam);
initPosM.translate(this.getDrawSizeX() / 2, this.getDrawSizeY() / 2);
// All is relative to the paper's center. not the corner.
initPosM.scale(-1, 1, -1);
}
// get the current transformation...
PMatrix3D newPos = this.getLocation(cam);
newPos.translate(this.getDrawSizeX() / 2, this.getDrawSizeY() / 2);
newPos.scale(-1, 1, -1);
newPos.invert();
newPos.apply(initPosM);
PVector user = new PVector();
if (isAnaglyph && isLeft) {
userPos.add(-halfEyeDist * 2, 0, 0);
}
newPos.mult(userPos, user);
PVector paperCameraPos = user;
// Camera must look perpendicular to the screen.
graphics.camera(paperCameraPos.x, paperCameraPos.y, paperCameraPos.z,
paperCameraPos.x, paperCameraPos.y, 0,
0, 1, 0);
// http://www.gamedev.net/topic/597564-view-and-projection-matrices-for-vr-window-using-head-tracking/
float nearFactor = nearPlane / paperCameraPos.z;
float left = nearFactor * (-size.x / 2f - paperCameraPos.x);
float right = nearFactor * (size.x / 2f - paperCameraPos.x);
float top = nearFactor * (size.y / 2f - paperCameraPos.y);
float bottom = nearFactor * (-size.y / 2f - paperCameraPos.y);
graphics.frustum(left, right, bottom, top, nearPlane, farPlane);
graphics.projection.m11 = -graphics.projection.m11;
// No detection?
PMatrix3D transformation = this.getLocation(cam);
if (transformation.m03 == 0 && transformation.m13 == 0 && transformation.m23 == 0) {
resetPos();
}
}