Package toxi.geom

Examples of toxi.geom.Polygon2D


        return cw.unweightInto(out);
    }

    public Polygon2D toPolygon2D(int res) {
        float delta = 1f / (res - 1);
        Polygon2D poly = new Polygon2D();
        for (int i = 0; i < res; i++) {
            poly.add(pointOnCurve(i * delta).to2DXY());
        }
        return poly;
    }
View Full Code Here


                    continue;
                }
                done.add(site);
                List<DelaunayTriangle> list = delaunay.surroundingTriangles(
                        site, triangle);
                Polygon2D poly = new Polygon2D();
                for (DelaunayTriangle tri : list) {
                    DelaunayVertex circumeter = tri.getCircumcenter();
                    poly.add(new Vec2D((float) circumeter.coord(0),
                            (float) circumeter.coord(1)));
                }
                regions.add(poly);
            }
        }
View Full Code Here

        float ratio = area / area2;
        assertTrue((1 - ratio) < 0.01);
    }

    public void testClockwise() {
        Polygon2D p = new Circle(50).toPolygon2D(8);
        assertTrue(p.isClockwise());
    }
View Full Code Here

        assertTrue(p.isClockwise());
    }

    public void testContainment() {
        final Vec2D origin = new Vec2D(100, 100);
        Polygon2D p = new Circle(origin, 50).toPolygon2D(8);
        assertTrue(p.containsPoint(origin));
        assertTrue(p.containsPoint(p.vertices.get(0)));
        assertFalse(p.containsPoint(p.vertices.get(3).scale(1.01f)));
    }
View Full Code Here

        assertFalse(p.containsPoint(p.vertices.get(3).scale(1.01f)));
    }

    public void testIncreaseVertcount() {
        final Vec2D origin = new Vec2D(100, 100);
        Polygon2D p = new Circle(origin, 50).toPolygon2D(3);
        p.increaseVertexCount(6);
        assertEquals(6, p.getNumVertices());
    }
View Full Code Here

        p.increaseVertexCount(6);
        assertEquals(6, p.getNumVertices());
    }

    public void testReduce() {
        Polygon2D p = new Circle(100).toPolygon2D(30);
        float len = p.vertices.get(0).distanceTo(p.vertices.get(1));
        p.reduceVertices(len * 0.99f);
        assertEquals(30, p.getNumVertices());
        p.reduceVertices(len * 1.5f);
        assertEquals(15, p.getNumVertices());
    }
View Full Code Here

import toxi.geom.Vec2D;

public class PolygonTest extends TestCase {

    public void testAreaAndCentroid() {
        Polygon2D p = new Polygon2D();
        p.add(new Vec2D());
        p.add(new Vec2D(1, 0));
        p.add(new Vec2D(1, 1));
        p.add(new Vec2D(0, 1));
        p.add(new Vec2D());
        assertEquals(4, p.getNumVertices());
        float area = p.getArea();
        assertEquals(1f, area);
        ReadonlyVec2D centroid = p.getCentroid();
        assertEquals(new Vec2D(0.5f, 0.5f), centroid);
    }
View Full Code Here

    }

    public void testCircleArea() {
        float radius = 1;
        int subdiv = 36;
        Polygon2D p = new Circle(radius).toPolygon2D(subdiv);
        float area = p.getArea();
        float area2 = new Circle(radius).getArea();
        float ratio = area / area2;
        assertTrue((1 - ratio) < 0.01);
    }
View Full Code Here

    private boolean showBounds = true;

    public void draw() {
        background(51);
        noFill();
        Polygon2D poly = new Circle(new Vec2D(mouseX, mouseY), 100)
                .toPolygon2D(12);
        if (showBounds) {
            if (useConvex) {
                stroke(255, 0, 0);
                gfx.polygon2D(convexClipper.getBounds());
            } else {
                stroke(255, 0, 255);
                gfx.rect(rectClipper.getBounds());
            }
            stroke(255, 255, 0);
            gfx.polygon2D(poly);
        }
        fill(255, 128, 0);
        noStroke();
        Polygon2D clipped;
        if (useConvex) {
            clipped = convexClipper.clipPolygon(poly);
        } else {
            clipped = rectClipper.clipPolygon(poly);
        }
View Full Code Here

    }

    public void setup() {
        size(400, 400);
        gfx = new ToxiclibsSupport(this);
        Polygon2D bounds = new Polygon2D();
        bounds.add(new Vec2D(100, 100));
        bounds.add(new Vec2D(150, 80));
        bounds.add(new Vec2D(300, 130));
        bounds.add(new Vec2D(320, 300));
        bounds.add(new Vec2D(200, 220));
        bounds.center(bounds.getBounds().getCentroid());
        rectClipper = new SutherlandHodgemanClipper(bounds.getBounds());
        convexClipper = new ConvexPolygonClipper(bounds);
        textFont(createFont("SansSerif", 10));
    }
View Full Code Here

TOP

Related Classes of toxi.geom.Polygon2D

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.