Package toxi.geom

Examples of toxi.geom.Triangle2D


    }

    public List<Triangle2D> getTriangles() {
        List<Triangle2D> tris = new ArrayList<Triangle2D>();
        for (DelaunayTriangle t : delaunay) {
            tris.add(new Triangle2D(t.get(0).toVec2D(), t.get(1).toVec2D(), t
                    .get(2).toVec2D()));
        }
        return tris;
    }
View Full Code Here


    public void testBarycentric() {
        Vec2D a = new Vec2D(-100, 0);
        Vec2D b = new Vec2D(0, -100);
        Vec2D c = new Vec2D(100, 0);
        Triangle2D t = new Triangle2D(a, b, c);
        assertEquals(new Vec3D(1, 0, 0), t.toBarycentric(a));
        assertEquals(new Vec3D(0, 1, 0), t.toBarycentric(b));
        assertEquals(new Vec3D(0, 0, 1), t.toBarycentric(c));
        // test roundtrip
        assertEquals(a, t.fromBarycentric(t.toBarycentric(a)));
        assertEquals(b, t.fromBarycentric(t.toBarycentric(b)));
        assertEquals(c, t.fromBarycentric(t.toBarycentric(c)));
        Vec2D p = new Vec2D(0, 0);
        assertEquals(p, t.fromBarycentric(t.toBarycentric(p)));
        // test point outside
        Vec3D bp = t.toBarycentric(new Vec2D(0, -150));
        assertTrue(bp.magnitude() > 1);
    }
View Full Code Here

    public void testCentroid() {
        Vec2D a = new Vec2D(-100, 0);
        Vec2D b = new Vec2D(0, 100);
        Vec2D c = new Vec2D(100, 0);
        Triangle2D t = new Triangle2D(a, b, c);
        ReadonlyVec2D centroid = t.computeCentroid();
        assertTrue("incorrect centroid",
                centroid.equals(new Vec2D(0, 100).scaleSelf(1f / 3)));
    }
View Full Code Here

    public void testContainment() {
        Vec2D a = new Vec2D(-100, 0);
        Vec2D b = new Vec2D(0, -100);
        Vec2D c = new Vec2D(100, 0);
        Triangle2D t = new Triangle2D(a, b, c);
        assertTrue(t.containsPoint(new Vec2D(0, -50)));
        assertTrue(t.containsPoint(a));
        assertTrue(t.containsPoint(b));
        assertTrue(t.containsPoint(c));
        assertFalse(t.containsPoint(new Vec2D(0, -101)));
        // check anti-clockwise
        t.flipVertexOrder();
        assertTrue(t.containsPoint(new Vec2D(0, -50)));
        assertTrue(t.containsPoint(a));
        assertTrue(t.containsPoint(b));
        assertTrue(t.containsPoint(c));
        assertFalse(t.containsPoint(new Vec2D(0, -101)));
    }
View Full Code Here

        assertTrue(t.containsPoint(c));
        assertFalse(t.containsPoint(new Vec2D(0, -101)));
    }

    public void testEquilateral() {
        Triangle2D t = Triangle2D.createEquilateralFrom(new Vec2D(-100, 0),
                new Vec2D(100, 0));
        assertEquals(new Vec2D(0, -57.735027f), t.computeCentroid());
    }
View Full Code Here

        Vec2D b = new Vec2D(0, -100);
        Vec2D c = new Vec2D(100, 0);
        Vec2D d = new Vec2D(-200, -50);
        Vec2D e = new Vec2D(0, 100);
        Vec2D f = new Vec2D(0, -30);
        Triangle2D t = new Triangle2D(a, b, c);
        Triangle2D t2 = new Triangle2D(d, e, f);
        assertTrue(t.intersectsTriangle(t2));
        f.x = 100;
        assertTrue(t.intersectsTriangle(t2));
        assertTrue(t.intersectsTriangle(new Triangle2D(a, c, e)));
        assertFalse(t.intersectsTriangle(new Triangle2D(a.add(0, 0.01f), c.add(
                0, 0.01f), e)));
        assertTrue(t.intersectsTriangle(new Triangle2D(a.add(0, 0.01f), c.add(
                0, 0.01f), f)));
    }
View Full Code Here

        background(255);
        noFill();
        final Vec2D p1 = new Vec2D(100, 200);
        final Vec2D p2 = new Vec2D(200, 50);
        final Vec2D p3 = new Vec2D(mouseX, mouseY);
        gfx.triangle(new Triangle2D(p1, p2, p3));
        Circle circle = Circle.from3Points(p1, p2, p3);
        if (circle != null) {
            gfx.ellipse(circle);
            gfx.circle(p1, 3);
            gfx.circle(p2, 3);
View Full Code Here

TOP

Related Classes of toxi.geom.Triangle2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.