Search in sources :

Example 1 with GeometryLocation

use of com.revolsys.geometry.operation.distance.GeometryLocation in project com.revolsys.open by revolsys.

the class Distance3DOp method computeMinDistanceLineLine.

private void computeMinDistanceLineLine(final LineString line0, final LineString line1, final boolean flip) {
    // brute force approach!
    int i = 0;
    for (final Segment segment1 : line0.segments()) {
        int j = 0;
        for (final Segment segment2 : line1.segments()) {
            final Point line1point1 = segment1.getPoint(0);
            final Point line1Point2 = segment1.getPoint(1);
            final Point line2Point1 = segment2.getPoint(0);
            final Point line2Point2 = segment2.getPoint(1);
            final double distance = CGAlgorithms3D.distanceSegmentSegment(line1point1, line1Point2, line2Point1, line2Point2);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                // TODO: compute closest pts in 3D
                final Point[] closestPt = segment1.closestPoints(segment2);
                updateDistance(distance, new GeometryLocation(line0, i, closestPt[0].newPoint2D()), new GeometryLocation(line1, j, closestPt[1].newPoint2D()), flip);
            }
            if (this.isDone) {
                return;
            }
            j++;
        }
        i++;
    }
}
Also used : GeometryLocation(com.revolsys.geometry.operation.distance.GeometryLocation) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Example 2 with GeometryLocation

use of com.revolsys.geometry.operation.distance.GeometryLocation in project com.revolsys.open by revolsys.

the class Distance3DOp method computeMinDistancePolygonPoint.

private void computeMinDistancePolygonPoint(final PlanarPolygon3D polyPlane, final Point point, final boolean flip) {
    final Point pt = point.getPoint();
    final LineString shell = polyPlane.getPolygon().getShell();
    if (polyPlane.intersects(pt, shell)) {
        // point is either inside or in a hole
        final int nHole = polyPlane.getPolygon().getHoleCount();
        for (int i = 0; i < nHole; i++) {
            final LineString hole = polyPlane.getPolygon().getHole(i);
            if (polyPlane.intersects(pt, hole)) {
                computeMinDistanceLinePoint(hole, point, flip);
                return;
            }
        }
        // point is in interior of polygon
        // distance is distance to polygon plane
        final double dist = Math.abs(polyPlane.getPlane().orientedDistance(pt));
        updateDistance(dist, new GeometryLocation(polyPlane.getPolygon(), 0, pt), new GeometryLocation(point, 0, pt), flip);
    }
    // point is outside polygon, so compute distance to shell linework
    computeMinDistanceLinePoint(shell, point, flip);
}
Also used : GeometryLocation(com.revolsys.geometry.operation.distance.GeometryLocation) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 3 with GeometryLocation

use of com.revolsys.geometry.operation.distance.GeometryLocation in project com.revolsys.open by revolsys.

the class Distance3DOp method computeMinDistanceLinePoint.

private void computeMinDistanceLinePoint(final LineString line, final Point point, final boolean flip) {
    final Point coord = point.getPoint();
    // brute force approach!
    int i = 0;
    for (final Segment segment : line.segments()) {
        final double dist = CGAlgorithms3D.distancePointSegment(coord, segment.getPoint(0), segment.getPoint(1));
        if (dist < this.minDistance) {
            final Point segClosestPoint = segment.closestPoint(coord);
            updateDistance(dist, new GeometryLocation(line, i, segClosestPoint.newPoint2D()), new GeometryLocation(point, 0, coord), flip);
        }
        if (this.isDone) {
            return;
        }
        i++;
    }
}
Also used : GeometryLocation(com.revolsys.geometry.operation.distance.GeometryLocation) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Example 4 with GeometryLocation

use of com.revolsys.geometry.operation.distance.GeometryLocation in project com.revolsys.open by revolsys.

the class Distance3DOp method computeMinDistancePolygonLine.

private void computeMinDistancePolygonLine(final PlanarPolygon3D poly, final LineString line, final boolean flip) {
    // first test if line intersects polygon
    final Point intPt = intersection(poly, line);
    if (intPt != null) {
        updateDistance(0, new GeometryLocation(poly.getPolygon(), 0, intPt), new GeometryLocation(line, 0, intPt), flip);
        return;
    }
    // if no intersection, then compute line distance to polygon rings
    computeMinDistanceLineLine(poly.getPolygon().getShell(), line, flip);
    if (this.isDone) {
        return;
    }
    final int nHole = poly.getPolygon().getHoleCount();
    for (int i = 0; i < nHole; i++) {
        computeMinDistanceLineLine(poly.getPolygon().getHole(i), line, flip);
        if (this.isDone) {
            return;
        }
    }
}
Also used : GeometryLocation(com.revolsys.geometry.operation.distance.GeometryLocation) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Aggregations

Point (com.revolsys.geometry.model.Point)4 GeometryLocation (com.revolsys.geometry.operation.distance.GeometryLocation)4 Segment (com.revolsys.geometry.model.segment.Segment)2 LineString (com.revolsys.geometry.model.LineString)1