Java源码示例:org.poly2tri.triangulation.TriangulationPoint

示例1
public void drawTrianglesForBlob(Blob b) {
	// create points array, skipping over blob edge vertices
	points.clear();
	EdgeVertex eA;
	for (int m=0;m<b.getEdgeNb();m+=10) {
		eA = b.getEdgeVertexA(m);
		if (eA != null) {
			PolygonPoint point = new PolygonPoint(eA.x * p.width, eA.y * p.height);
			points.add(point);
		}
	}
	
	if (points.size() < 10) return;

	// calculate triangles
	doTriangulation();

	// draw it
	p.stroke(0,255,0);
	p.strokeWeight(2);
	p.fill(255, 120);
	
	TriangulationPoint point1, point2, point3;
	for (DelaunayTriangle triangle : triangles) {
		point1 = triangle.points[0];
		point2 = triangle.points[1];
		point3 = triangle.points[2];
		if( point1.getYf() > 0 && point1.getYf() < p.height &&
			point2.getYf() > 0 && point2.getYf() < p.height &&
			point3.getYf() > 0 && point3.getYf() < p.height && 
			point1.getXf() > 0 && point1.getXf() < p.width &&
			point2.getXf() > 0 && point2.getXf() < p.width &&
			point3.getXf() > 0 && point3.getXf() < p.width) {
			
			p.line( point1.getXf(), point1.getYf(), point2.getXf(), point2.getYf() );
			p.line( point3.getXf(), point3.getYf(), point2.getXf(), point2.getYf() );
			p.line( point1.getXf(), point1.getYf(), point3.getXf(), point3.getYf() );
			
			// sometimes fill triangles
			if (MathUtil.randBoolean() == true ) {
				p.beginShape();
				p.vertex( point1.getXf(), point1.getYf() );
				p.vertex( point2.getXf(), point2.getYf() );
				p.vertex( point3.getXf(), point3.getYf() );
				p.endShape();
			}
		}
	}

	
}
 
示例2
public void drawTrianglesForBlob(Blob b) {
	// create points array, skipping over blob edge vertices
	points.clear();
	EdgeVertex eA;
	for (int m=0;m<b.getEdgeNb();m+=10) {
		eA = b.getEdgeVertexA(m);
		if (eA != null) {
			PolygonPoint point = new PolygonPoint(eA.x * _canvasW, eA.y * _canvasH);
			points.add(point);
		}
	}
	
	if (points.size() < 10) return;

	// calculate triangles
	doTriangulation();

	// draw it
	_canvas.stroke(0,255,0);
	_canvas.strokeWeight(2);
	_canvas.fill(255, 120);
	
	TriangulationPoint point1, point2, point3;
	for (DelaunayTriangle triangle : triangles) {
		point1 = triangle.points[0];
		point2 = triangle.points[1];
		point3 = triangle.points[2];
		if( point1.getYf() > 0 && point1.getYf() < _canvasH &&
			point2.getYf() > 0 && point2.getYf() < _canvasH &&
			point3.getYf() > 0 && point3.getYf() < _canvasH && 
			point1.getXf() > 0 && point1.getXf() < _canvasW &&
			point2.getXf() > 0 && point2.getXf() < _canvasW &&
			point3.getXf() > 0 && point3.getXf() < _canvasW) {
			
			_canvas.line( point1.getXf(), point1.getYf(), point2.getXf(), point2.getYf() );
			_canvas.line( point3.getXf(), point3.getYf(), point2.getXf(), point2.getYf() );
			_canvas.line( point1.getXf(), point1.getYf(), point3.getXf(), point3.getYf() );
			
			// sometimes fill triangles
			if (MathUtil.randBoolean() == true ) {
				_canvas.beginShape();
				_canvas.vertex( point1.getXf(), point1.getYf() );
				_canvas.vertex( point2.getXf(), point2.getYf() );
				_canvas.vertex( point3.getXf(), point3.getYf() );
				_canvas.endShape();
			}
		}
	}

	
}