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;
}
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;
}
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;
}
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);
});
}
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);
}
}
}
Aggregations