Search in sources :

Example 31 with Path2D

use of java.awt.geom.Path2D in project cytoscape-impl by cytoscape.

the class GraphicsUtilities method triangleArrow.

static Shape triangleArrow(double size) {
    Path2D path = new Path2D.Double();
    path.moveTo(0.0, 0.0);
    path.lineTo(-size / 2.0, -size / 2.0);
    path.lineTo(-size / 2.0, size / 2.0);
    path.closePath();
    return path;
}
Also used : Path2D(java.awt.geom.Path2D)

Example 32 with Path2D

use of java.awt.geom.Path2D in project energy3d by concord-consortium.

the class Foundation method containsPoint.

public boolean containsPoint(final double x, final double y) {
    final Path2D foundationPoly = new Path2D.Double();
    foundationPoly.moveTo(points.get(0).getX(), points.get(0).getY());
    foundationPoly.lineTo(points.get(2).getX(), points.get(2).getY());
    foundationPoly.lineTo(points.get(3).getX(), points.get(3).getY());
    foundationPoly.lineTo(points.get(1).getX(), points.get(1).getY());
    foundationPoly.closePath();
    return foundationPoly.contains(x, y);
}
Also used : Path2D(java.awt.geom.Path2D)

Example 33 with Path2D

use of java.awt.geom.Path2D in project energy3d by concord-consortium.

the class Foundation method updateHandle.

private void updateHandle(final Vector3 p, final ReadOnlyVector3 dir) {
    final ReadOnlyVector3 step = dir.normalize(null).multiplyLocal(3);
    if (step.length() == 0) {
        return;
    }
    final ReadOnlyVector3 center = getCenter();
    p.set(center).addLocal(dir).addLocal(step);
    final Point2D p2D = new Point2D.Double();
    for (final HousePart part : Scene.getInstance().getParts()) {
        if (part != this && part instanceof Foundation) {
            final ArrayList<Vector3> points = part.getPoints();
            final Path2D foundationPoly = new Path2D.Double();
            foundationPoly.moveTo(points.get(0).getX(), points.get(0).getY());
            foundationPoly.lineTo(points.get(2).getX(), points.get(2).getY());
            foundationPoly.lineTo(points.get(3).getX(), points.get(3).getY());
            foundationPoly.lineTo(points.get(1).getX(), points.get(1).getY());
            foundationPoly.closePath();
            p2D.setLocation(p.getX(), p.getY());
            if (foundationPoly.contains(p2D)) {
                while (foundationPoly.contains(p2D)) {
                    p.addLocal(step);
                    p2D.setLocation(p.getX(), p.getY());
                }
                p.addLocal(step);
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Point2D(java.awt.geom.Point2D) Path2D(java.awt.geom.Path2D) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 34 with Path2D

use of java.awt.geom.Path2D in project energy3d by concord-consortium.

the class MeshLib method fillMeshWithPolygon.

// private static boolean isAlmost180(final ReadOnlyVector3 p1, final ReadOnlyVector3 p2, final ReadOnlyVector3 p3) {
// return Math.abs(p1.subtract(p2, null).normalizeLocal().smallestAngleBetween(p3.subtract(p1, null).normalizeLocal())) > Math.PI - Math.PI / 180.0;
// }
public static void fillMeshWithPolygon(final Mesh mesh, final PolygonWithHoles polygon, final CoordinateTransform fromXY, final boolean generateNormals, final TPoint o, final TPoint u, final TPoint v, final boolean isWall) {
    /* round all points */
    for (final Point p : polygon.getPoints()) {
        p.set(Util.round(p.getX()), Util.round(p.getY()), Util.round(p.getZ()));
    }
    if (polygon.getHoles() != null) {
        for (final Polygon hole : polygon.getHoles()) {
            for (final Point p : hole.getPoints()) {
                p.set(Util.round(p.getX()), Util.round(p.getY()), Util.round(p.getZ()));
            }
        }
    }
    /* remove holes that collide with polygon or other holes */
    if (polygon.getHoles() != null) {
        // ensure polygon doesn't collide with holes
        final Path2D polygonPath = Util.makePath2D(polygon.getPoints());
        final Map<Polygon, Object> skipHoles = new HashMap<Polygon, Object>();
        for (final Polygon hole : polygon.getHoles()) {
            for (final Point p : hole.getPoints()) {
                if (!polygonPath.contains(new Point2D.Double(p.getX(), p.getY()))) {
                    skipHoles.put(hole, null);
                    break;
                }
            }
        }
        // ensure holes don't collide with each other
        for (int i = 0; i < polygon.getHoles().size(); i++) {
            final Polygon hole1 = polygon.getHoles().get(i);
            if (skipHoles.containsKey(hole1)) {
                continue;
            }
            for (int j = i + 1; j < polygon.getHoles().size(); j++) {
                final Polygon hole2 = polygon.getHoles().get(j);
                if (skipHoles.containsKey(hole2)) {
                    continue;
                }
                boolean found = false;
                for (final Point p : hole2.getPoints()) {
                    if (Util.insidePolygon(p, hole1.getPoints())) {
                        skipHoles.put(hole2, null);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    final int n1 = hole1.getPoints().size();
                    for (int i1 = 0; i1 < n1; i1++) {
                        final Point l1p1 = hole1.getPoints().get(i1);
                        final Point l1p2 = hole1.getPoints().get((i1 + 1) % n1);
                        final Line2D line1 = new Line2D.Double(l1p1.getX(), l1p1.getY(), l1p2.getX(), l1p2.getY());
                        found = false;
                        final int n2 = hole2.getPoints().size();
                        for (int i2 = 0; i2 < n2; i2++) {
                            final Point l2p1 = hole2.getPoints().get(i2);
                            final Point l2p2 = hole2.getPoints().get((i2 + 1) % n2);
                            final Line2D line2 = new Line2D.Double(l2p1.getX(), l2p1.getY(), l2p2.getX(), l2p2.getY());
                            if (line2.intersectsLine(line1)) {
                                skipHoles.put(hole2, null);
                                found = true;
                                break;
                            }
                        }
                        if (found) {
                            break;
                        }
                    }
                }
            }
        }
        for (final Polygon hole : skipHoles.keySet()) {
            polygon.getHoles().remove(hole);
        }
    }
    try {
        Poly2Tri.triangulate(polygon);
        if (fromXY == null) {
            ArdorMeshMapper.updateTriangleMesh(mesh, polygon);
        } else {
            ArdorMeshMapper.updateTriangleMesh(mesh, polygon, fromXY);
        }
        if (generateNormals) {
            if (fromXY == null) {
                ArdorMeshMapper.updateFaceNormals(mesh, polygon.getTriangles());
            } else {
                ArdorMeshMapper.updateFaceNormals(mesh, polygon.getTriangles(), fromXY);
            }
        }
        if (o != null) {
            ArdorMeshMapper.updateTextureCoordinates(mesh, polygon.getTriangles(), 1.0, o, u, v);
        }
        mesh.getMeshData().updateVertexCount();
        mesh.updateModelBound();
    } catch (final RuntimeException e) {
        System.err.println("Points:");
        for (final Point p : polygon.getPoints()) {
            System.err.println(p);
        }
        System.err.println("Holes:");
        if (polygon.getHoles() != null) {
            for (final Polygon hole : polygon.getHoles()) {
                for (final Point p : hole.getPoints()) {
                    System.err.println(p);
                }
            }
        }
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) Path2D(java.awt.geom.Path2D) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) Polygon(org.poly2tri.geometry.polygon.Polygon) Line2D(java.awt.geom.Line2D) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Example 35 with Path2D

use of java.awt.geom.Path2D in project energy3d by concord-consortium.

the class Util method makePath2D.

public static Path2D makePath2D(final List<? extends Point> polygon) {
    final Path2D path = new Path2D.Double();
    path.moveTo(polygon.get(0).getX(), polygon.get(0).getY());
    for (int i = 1; i < polygon.size(); i++) {
        final Point point = polygon.get(i);
        path.lineTo(point.getX(), point.getY());
    }
    path.closePath();
    return path;
}
Also used : Path2D(java.awt.geom.Path2D) Point(org.poly2tri.geometry.primitives.Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) Point(org.poly2tri.geometry.primitives.Point)

Aggregations

Path2D (java.awt.geom.Path2D)126 Point2D (java.awt.geom.Point2D)20 Area (java.awt.geom.Area)16 Rectangle2D (java.awt.geom.Rectangle2D)13 Shape (java.awt.Shape)9 Point (java.awt.Point)8 Line2D (java.awt.geom.Line2D)8 PathIterator (java.awt.geom.PathIterator)8 ArrayList (java.util.ArrayList)8 AffineTransform (java.awt.geom.AffineTransform)7 GeneralPath (java.awt.geom.GeneralPath)7 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)6 Paint (java.awt.Paint)6 ShapeRoi (ij.gui.ShapeRoi)5 BasicStroke (java.awt.BasicStroke)4 RadialGradientPaint (java.awt.RadialGradientPaint)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Vector2D (de.gurkenlabs.litiengine.util.geom.Vector2D)2