当前位置: 首页>>代码示例>>Java>>正文


Java PVector类代码示例

本文整理汇总了Java中processing.core.PVector的典型用法代码示例。如果您正苦于以下问题:Java PVector类的具体用法?Java PVector怎么用?Java PVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PVector类属于processing.core包,在下文中一共展示了PVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildNoisyEdges

import processing.core.PVector; //导入依赖的package包/类
/***********************************************************/
 void buildNoisyEdges(PApplet ap)
{
  final float f = 0.5f; 
  for(VoronoiGenerator.Map.Edge e : map.edgesList) {
    if(e.f2 == null) continue;
    
    PVector m = lerpVector(e.p1.pos, e.p2.pos, f);  // midpoint
    PVector t = lerpVector(e.p1.pos, e.f1.pos, f);
    PVector q = lerpVector(e.p1.pos, e.f2.pos, f);
    PVector r = lerpVector(e.p2.pos, e.f1.pos, f);
    PVector s = lerpVector(e.p2.pos, e.f2.pos, f);
    
    int minLength = 4;
    if(e.f1.ocean && e.f2.ocean) minLength = 100;
    if(e.f1.ocean != e.f2.ocean) minLength = 2;  // coast
    if(e.river > 0) minLength = 3;
    
    e.noisy1 = buildNoisyLineSegments(ap,e.p1.pos, t, m, q, minLength);
    e.noisy2 = buildNoisyLineSegments(ap,e.p2.pos, s, m, r, minLength);
  }
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:23,代码来源:VoronoiGenerator.java

示例2: subdivideNoisyLineSegment

import processing.core.PVector; //导入依赖的package包/类
void subdivideNoisyLineSegment(PApplet ap,ArrayList<PVector> pts, 
  PVector A, PVector B, PVector C, PVector D, int minLength)
{
  if(PVector.sub(A, C).mag() < minLength || PVector.sub(B, D).mag() < minLength)
    return;
    
  float p = ap.random(0.2f, 0.8f);
  float q = ap.random(0.2f, 0.8f);
  
  PVector E = lerpVector(A, D, p);
  PVector F = lerpVector(B, C, p);
  PVector G = lerpVector(A, B, q);
  PVector I = lerpVector(D, C, q);
  
  PVector H = lerpVector(E, F, q);
  
  subdivideNoisyLineSegment(ap,pts, A, G, H, E, minLength);
  pts.add(H);
  subdivideNoisyLineSegment(ap,pts, H, F, C, I, minLength);
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:21,代码来源:VoronoiGenerator.java

示例3: 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;
	}
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:17,代码来源:VoronoiGenerator.java

示例4: intersectionParabolaArc

import processing.core.PVector; //导入依赖的package包/类
boolean intersectionParabolaArc(PVector p, Arc a, PVector res) {
	if (a.site.pos.x == p.x)
		return false;

	double i0 = 0, i1 = 0;
	if (a.prev != null) // Intersection of i.prev, i
		i0 = intersectionParabolas(a.prev.site.pos, a.site.pos, p.x).y;
	if (a.next != null) // Intersection of i, i.next
		i1 = intersectionParabolas(a.site.pos, a.next.site.pos, p.x).y;

	if ((a.prev == null || i0 <= p.y) && (a.next == null || i1 >= p.y)) {
		if (res != null) {
			res.y = p.y;
			res.x = (a.site.pos.x * a.site.pos.x + (a.site.pos.y - res.y) * (a.site.pos.y - res.y) - p.x * p.x)
					/ (2 * a.site.pos.x - 2 * p.x);
		}
		return true;
	}

	return false;
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:22,代码来源:VoronoiGenerator.java

示例5: intersectionParabolas

import processing.core.PVector; //导入依赖的package包/类
PVector intersectionParabolas(PVector p0, PVector p1, float l) {
	PVector res = new PVector(), p = p0;
	if (p0.x == p1.x)
		res.y = (p0.y + p1.y) / 2;
	else if (p1.x == l)
		res.y = p1.y;
	else if (p0.x == l) {
		res.y = p0.y;
		p = p1;
	} else {
		float s0 = 2 * (p0.x - l), s1 = 2 * (p1.x - l);
		float a = 1 / s0 - 1 / s1;
		float b = -2 * (p0.y / s0 - p1.y / s1);
		float c = (p0.y * p0.y + p0.x * p0.x - l * l) / s0 - (p1.y * p1.y + p1.x * p1.x - l * l) / s1;
		res.y = (-b - PApplet.sqrt(b * b - 4 * a * c)) / (2 * a);
	}
	res.x = (p.x * p.x + (p.y - res.y) * (p.y - res.y) - l * l) / (2 * p.x - 2 * l);
	return res;
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:20,代码来源:VoronoiGenerator.java

示例6: computeCircle

import processing.core.PVector; //导入依赖的package包/类
CircleResponse computeCircle(PVector a, PVector b, PVector c) {
	// BC must be a right turn from AB
	if ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) > 0)
		return new CircleResponse(false);

	// Algorithm from O'Rourke 2ed p. 189.
	float A = b.x - a.x, B = b.y - a.y, C = c.x - a.x, D = c.y - a.y, E = A * (a.x + b.x) + B * (a.y + b.y), F = C
			* (a.x + c.x) + D * (a.y + c.y), G = 2 * (A * (c.y - b.y) - B * (c.x - b.x));

	// co-linear
	if (G == 0)
		return new CircleResponse(false);

	// p is the center
	CircleResponse r = new CircleResponse(true);
	r.p.x = (D * E - B * F) / G;
	r.p.y = (A * F - C * E) / G;

	// max x coordinate
	r.x = r.p.x + PApplet.sqrt(PApplet.pow(a.x - r.p.x, 2) + PApplet.pow(a.y - r.p.y, 2));
	return r;
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:23,代码来源:VoronoiGenerator.java

示例7: 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));
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:21,代码来源:VoronoiGenerator.java

示例8: PointsLookup

import processing.core.PVector; //导入依赖的package包/类
PointsLookup(float xmin, float ymin, float xmax, float ymax, int cellSize, float tolerance) {
	_xmin = xmin;
	_xmax = xmax;
	_ymin = ymin;
	_ymax = ymax;
	_cs = cellSize;
	_tol = tolerance;
	_tol2 = tolerance * tolerance;
	_data = new Vector<Vector<PVector>>();
	float fw = xmax - xmin, fh = ymax - ymin;
	_w = PApplet.ceil(fw / (float) _cs);
	_h = PApplet.ceil(fh / (float) _cs); // grid of 10x10 pixels
	int s = _w * _h;
	for (int i = 0; i < s; i++)
		_data.add(new Vector<PVector>());
	_points = new Vector<PVector>();
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:18,代码来源:VoronoiGenerator.java

示例9: testGrid

import processing.core.PVector; //导入依赖的package包/类
boolean testGrid(PVector p, float minDist) {
	int minX = PApplet.floor(PApplet.max(0, (p.x - minDist - _xmin) / _cellSize));
	int maxX = PApplet.ceil(PApplet.min(_gridWidth - 1, (p.x + minDist - _xmin) / _cellSize));
	int minY = PApplet.floor(PApplet.max(0, (p.y - minDist - _ymin) / _cellSize));
	int maxY = PApplet.ceil(PApplet.min(_gridHeight - 1, (p.y + minDist - _ymin) / _cellSize));

	for (int y = minY; y <= maxY; y++) {
		for (int x = minX; x <= maxX; x++) {
			Vector<PVector> cell = _grid.get(y * _gridWidth + x);
			for (PVector t : cell)
				if (PApplet.dist(p.x, p.y, t.x, t.y) <= minDist)
					return false;
		}
	}

	return true;
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:18,代码来源:VoronoiGenerator.java

示例10: createPointsGrid

import processing.core.PVector; //导入依赖的package包/类
void createPointsGrid(PApplet ap)
{
	
	Vector<PVector> pnts =  new Vector<PVector>();
	int dw = width /nbPoints;
	int dh = height /nbPoints;
	int xoffset = dw,yoffset = dh;
	for(int i = 1 ; i*dw < width - dw ;i++)
	{
		for(int j = 1 ; j*dh< height - dh ;j++)
		{				
			pnts.add(new PVector(xoffset + i*dw,yoffset+j*dh));
		}
		
	}
	System.out.println(pnts);
	voronoiPoints = pnts;
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:19,代码来源:VoronoiGenerator.java

示例11: 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);
}
 
开发者ID:abuzreq,项目名称:ConstrainedGraphPartitioning,代码行数:19,代码来源:VoronoiGenerator.java

示例12: getColorOccurencesFrom

import processing.core.PVector; //导入依赖的package包/类
/**
 * Unsafe do not use unless you are sure.
 */
public int getColorOccurencesFrom(PVector coord, PImage cameraImage, int radius, int col, int threshold, PaperTouchScreen paperTouchScreen) {
    int x = (int) coord.x;
    int y = (int) coord.y;
    int minX = PApplet.constrain(x - radius, 0, cameraImage.width - 1);
    int maxX = PApplet.constrain(x + radius, 0, cameraImage.width - 1);
    int minY = PApplet.constrain(y - radius, 0, cameraImage.height - 1);
    int maxY = PApplet.constrain(y + radius, 0, cameraImage.height - 1);
    int k = 0;
    for (int j = minY; j <= maxY; j++) {
        for (int i = minX; i <= maxX; i++) {
            int offset = i + j * cameraImage.width;
            int pxCol = cameraImage.pixels[offset];
            if (colorDistRGB(col, pxCol, threshold)) {
                k++;
            }
        }
    }
    return k;
}
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:23,代码来源:MathUtils.java

示例13: MarkerBoardJavaCV

import processing.core.PVector; //导入依赖的package包/类
public MarkerBoardJavaCV(String fileName, float width, float height) throws Exception {
    super(fileName, width, height);
    trackers = new ArrayList<ObjectFinder>();
    imagePoints = new PVector[4];
    objectPoints = new PVector[4];

    objectPoints[0] = new PVector(0, 0, 0);
    objectPoints[1] = new PVector(width, 0, 0);
    objectPoints[2] = new PVector(width, height, 0);
    objectPoints[3] = new PVector(0, height, 0);

    Logger logger = Logger.getLogger(ObjectFinder.class.getName());
    logger.setLevel(Level.OFF);
    this.type = MarkerType.JAVACV_FINDER;
    imgToFind = cvLoadImage(this.fileName);

    // TODO: something less violent than a runtime exception... 
    if (imgToFind == null) {
        throw new Exception("MarkerBoardJavaCV: Impossible to load the image: " + this.fileName);
    }

}
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:23,代码来源:MarkerBoardJavaCV.java

示例14: addPoint

import processing.core.PVector; //导入依赖的package包/类
public void addPoint(DepthPoint pce) {

        if (pce == null || pce.position == null) {
            return;
        }

        PVector p = pce.position;

//                float[] vert = vertices[nbToDraw];
        verticesJava[currentVertNo++] = p.x;
        verticesJava[currentVertNo++] = p.y;
        verticesJava[currentVertNo++] = p.z;
        verticesJava[currentVertNo++] = 1;

        int c = pce.colorPt;
        int c2 = javaToNativeARGB(c);
        colorsJava[nbColors++] = c2;
    }
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:19,代码来源:PointCloud.java

示例15: CreatePlaneCalibrationFrom

import processing.core.PVector; //导入依赖的package包/类
/**
     * Get a plane from a 3D  matrix. 
     * Here the size is not that important, might be removed.  
     * @param mat
     * @param size
     * @return 
     */
    public static PlaneCalibration CreatePlaneCalibrationFrom(PMatrix3D mat, PVector size) {
        PMatrix3D matrix = mat.get();
        PlaneCreator planeCreator = new PlaneCreator();
        
        planeCreator.addPoint(new Vec3D(matrix.m03, matrix.m13, matrix.m23));
        matrix.translate(size.x, 0, 0);
        planeCreator.addPoint(new Vec3D(matrix.m03, matrix.m13, matrix.m23));
        matrix.translate(0, size.y, 0);
        planeCreator.addPoint(new Vec3D(matrix.m03, matrix.m13, matrix.m23));

        planeCreator.setHeight(DEFAULT_PLANE_HEIGHT);
        assert (planeCreator.isComputed());
        PlaneCalibration planeCalibration = planeCreator.getPlaneCalibration();
        
        planeCalibration.flipNormal();
//        planeCalibration.moveAlongNormal(DEFAULT_PLANE_SHIFT);
        assert (planeCalibration.isValid());
        return planeCalibration;
    }
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:27,代码来源:PlaneCalibration.java


注:本文中的processing.core.PVector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。