Search in sources :

Example 11 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangulatedIrregularNetwork method getTriangles.

default List<Triangle> getTriangles(final Point point) {
    final List<Triangle> triangles = new ArrayList<>();
    final Predicate<Triangle> filter = (triangle) -> {
        return triangle.containsPoint(point);
    };
    final BoundingBox boundingBox = point.getBoundingBox();
    forEachTriangle(boundingBox, filter, triangles::add);
    return triangles;
}
Also used : BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Predicate(java.util.function.Predicate) IoFactory(com.revolsys.io.IoFactory) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Consumer(java.util.function.Consumer) IoFactoryRegistry(com.revolsys.io.IoFactoryRegistry) List(java.util.List) ScaledIntegerTriangulatedIrregularNetwork(com.revolsys.elevation.tin.compactbinary.ScaledIntegerTriangulatedIrregularNetwork) Resource(com.revolsys.spring.resource.Resource) GeometryFactoryProxy(com.revolsys.geometry.model.GeometryFactoryProxy) Triangle(com.revolsys.geometry.model.Triangle) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) Predicates(com.revolsys.predicate.Predicates) MapEx(com.revolsys.collection.map.MapEx) AsciiTin(com.revolsys.elevation.tin.tin.AsciiTin) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Lists(com.revolsys.collection.list.Lists) Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) BoundingBox(com.revolsys.geometry.model.BoundingBox) Triangle(com.revolsys.geometry.model.Triangle) ArrayList(java.util.ArrayList)

Example 12 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangulatedIrregularNetwork method getElevation.

default double getElevation(Point point) {
    point = convertGeometry(point);
    final List<Triangle> triangles = getTriangles(point);
    for (final Triangle triangle : triangles) {
        final Point t0 = triangle.getP0();
        if (t0.equals(point)) {
            return t0.getZ();
        }
        final Point t1 = triangle.getP1();
        if (t1.equals(point)) {
            return t1.getZ();
        }
        final Point t2 = triangle.getP2();
        if (t2.equals(point)) {
            return t2.getZ();
        }
        Point closestCorner = t0;
        LineSegment oppositeEdge = new LineSegmentDoubleGF(t1, t2);
        double closestDistance = point.distancePoint(closestCorner);
        final double t1Distance = point.distancePoint(t1);
        if (closestDistance > t1Distance) {
            closestCorner = t1;
            oppositeEdge = new LineSegmentDoubleGF(t2, t0);
            closestDistance = t1Distance;
        }
        if (closestDistance > point.distancePoint(t2)) {
            closestCorner = t2;
            oppositeEdge = new LineSegmentDoubleGF(t0, t1);
        }
        LineSegment segment = new LineSegmentDoubleGF(closestCorner, point).extend(0, t0.distancePoint(t1) + t1.distancePoint(t2) + t0.distancePoint(t2));
        final Geometry intersectCoordinates = oppositeEdge.getIntersection(segment);
        if (intersectCoordinates.getVertexCount() > 0) {
            final Point intersectPoint = intersectCoordinates.getVertex(0);
            final double z = oppositeEdge.getElevation(intersectPoint);
            if (!Double.isNaN(z)) {
                final double x = intersectPoint.getX();
                final double y = intersectPoint.getY();
                final Point end = new PointDoubleXYZ(x, y, z);
                segment = new LineSegmentDoubleGF(t0, end);
                return segment.getElevation(point);
            }
        }
    }
    return Double.NaN;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Triangle(com.revolsys.geometry.model.Triangle) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 13 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangulatedIrregularNetwork method getTriangles.

default List<Triangle> getTriangles(final double x, final double y) {
    final List<Triangle> triangles = new ArrayList<>();
    final Predicate<Triangle> filter = triangle -> triangle.containsPoint(x, y);
    final BoundingBox boundingBox = new BoundingBoxDoubleXY(x, y);
    forEachTriangle(boundingBox, filter, triangles::add);
    return triangles;
}
Also used : BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Predicate(java.util.function.Predicate) IoFactory(com.revolsys.io.IoFactory) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Consumer(java.util.function.Consumer) IoFactoryRegistry(com.revolsys.io.IoFactoryRegistry) List(java.util.List) ScaledIntegerTriangulatedIrregularNetwork(com.revolsys.elevation.tin.compactbinary.ScaledIntegerTriangulatedIrregularNetwork) Resource(com.revolsys.spring.resource.Resource) GeometryFactoryProxy(com.revolsys.geometry.model.GeometryFactoryProxy) Triangle(com.revolsys.geometry.model.Triangle) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) Predicates(com.revolsys.predicate.Predicates) MapEx(com.revolsys.collection.map.MapEx) AsciiTin(com.revolsys.elevation.tin.tin.AsciiTin) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Lists(com.revolsys.collection.list.Lists) Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) BoundingBox(com.revolsys.geometry.model.BoundingBox) Triangle(com.revolsys.geometry.model.Triangle) ArrayList(java.util.ArrayList) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 14 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class QuadEdgeSubdivision method forEachTriangle.

public void forEachTriangle(final Consumer<? super Triangle> action) {
    forEachTriangle((x1, y1, z1, x2, y2, z2, x3, y3, z3) -> {
        final Triangle triangle = new TriangleDoubleXYZ(x1, y1, z1, x2, y2, z2, x3, y3, z3);
        action.accept(triangle);
    });
}
Also used : Triangle(com.revolsys.geometry.model.Triangle) TriangleDoubleXYZ(com.revolsys.geometry.model.impl.TriangleDoubleXYZ)

Example 15 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangleLinearRing method forEachVertex.

@Override
public void forEachVertex(final BiConsumerDouble action) {
    if (!isEmpty()) {
        final Triangle triangle = this.triangle;
        for (int i = 0; i < 3; i++) {
            final double x = triangle.getX(i);
            final double y = triangle.getY(i);
            action.accept(x, y);
        }
    }
}
Also used : Triangle(com.revolsys.geometry.model.Triangle)

Aggregations

Triangle (com.revolsys.geometry.model.Triangle)16 Point (com.revolsys.geometry.model.Point)6 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 AbstractTriangle (com.revolsys.geometry.model.impl.AbstractTriangle)5 ArrayList (java.util.ArrayList)5 Geometry (com.revolsys.geometry.model.Geometry)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)3 TriangleDoubleXYZ (com.revolsys.geometry.model.impl.TriangleDoubleXYZ)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)3 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)3 List (java.util.List)3 Lists (com.revolsys.collection.list.Lists)2 MapEx (com.revolsys.collection.map.MapEx)2 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)2 ScaledIntegerTriangulatedIrregularNetwork (com.revolsys.elevation.tin.compactbinary.ScaledIntegerTriangulatedIrregularNetwork)2 AsciiTin (com.revolsys.elevation.tin.tin.AsciiTin)2 GeometryFactoryProxy (com.revolsys.geometry.model.GeometryFactoryProxy)2 LineString (com.revolsys.geometry.model.LineString)2 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)2