Java Code Examples for toxi.geom.Triangle3D#computeNormal()

The following examples show how to use toxi.geom.Triangle3D#computeNormal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlignBoxToTriFace.java    From haxademic with MIT License 6 votes vote down vote up
void randomize() {
	// create random triangle
	tri=new Triangle3D(
			Vec3D.randomVector().scale(100), 
			Vec3D.randomVector().scale(100), 
			Vec3D.randomVector().scale(100)
			);
	// create box mesh around origin
	mesh = (TriangleMesh)new AABB(50).toMesh();
	// get triangle normal
	Vec3D n=tri.computeNormal();
	// rotate mesh such that the +Z axis is aligned with the triangle normal
	mesh.pointTowards(n);
	// move box in the normal direction 100 units relative from the triangle center
	mesh.translate(tri.computeCentroid().add(n.scale(100)));
}
 
Example 2
Source File: ToxiclibsSupport.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public final void triangle(Triangle3D tri, boolean isFullShape) {
    if (isFullShape) {
        gfx.beginShape(PConstants.TRIANGLES);
    }
    Vec3D n = tri.computeNormal();
    gfx.normal(n.x, n.y, n.z);
    gfx.vertex(tri.a.x, tri.a.y, tri.a.z);
    gfx.vertex(tri.b.x, tri.b.y, tri.b.z);
    gfx.vertex(tri.c.x, tri.c.y, tri.c.z);
    if (isFullShape) {
        gfx.endShape();
    }
}
 
Example 3
Source File: TriangleTest.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testNormal() {
    Vec3D a = new Vec3D(0, 100, 0);
    Vec3D b = new Vec3D(100, 0, 0);
    Vec3D c = new Vec3D(-100, -100, 0);
    Triangle3D t = new Triangle3D(a, b, c);
    ReadonlyVec3D n = t.computeNormal();
    assertTrue("normal wrong", n.equals(new Vec3D(0, 0, 1)));
}
 
Example 4
Source File: PlaneTest.java    From toxiclibs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testContainment() {
    Triangle3D t = new Triangle3D(new Vec3D(-100, 0, 0), new Vec3D(0, 0,
            -100), new Vec3D(0, 0, 100));
    Plane pl = new Plane(t.computeCentroid(), t.computeNormal());
}