Search in sources :

Example 1 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class Densifier method densifyPoints.

/**
 * Densifies a coordinate sequence.
 *
 * @param pts
 * @param distanceTolerance
 * @return the densified coordinate sequence
 */
private static List<Point> densifyPoints(final LineString line, final double distanceTolerance) {
    final List<Point> points = new ArrayList<>();
    for (final Segment segment : line.segments()) {
        if (points.isEmpty()) {
            points.add(segment.getPoint(0));
        }
        final double length = segment.getLength();
        if (length > 0) {
            final int densifiedSegCount = (int) (length / distanceTolerance) + 1;
            if (densifiedSegCount > 1) {
                final double densifiedSegLen = length / densifiedSegCount;
                for (int j = 1; j < densifiedSegCount; j++) {
                    final double segFract = j * densifiedSegLen / length;
                    final Point point = segment.pointAlong(segFract);
                    if (!segment.isEndPoint(point)) {
                        points.add(point);
                    }
                }
            }
            points.add(segment.getPoint(1));
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment) Point(com.revolsys.geometry.model.Point)

Example 2 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class DistanceWithPoints method computeLinePoint.

private boolean computeLinePoint(final LineString line, final Point point) {
    if (this.minDistance == Double.MAX_VALUE || line.getBoundingBox().distance(point) <= this.minDistance) {
        for (final Segment segment : line.segments()) {
            final double distance = segment.distancePoint(point);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                final Point closestPoint = segment.closestPoint(point);
                this.minDistancePoint1 = closestPoint;
                this.minDistancePoint2 = point;
                if (this.minDistance <= this.terminateDistance) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Example 3 with Segment

use of com.revolsys.geometry.model.segment.Segment 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 4 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class DistanceToPointFinder method computeDistance.

public static void computeDistance(final LineString line, final Point pt, final PointPairDistance ptDist) {
    for (final Segment segment : line.segments()) {
        // this is somewhat inefficient - could do better
        final Point closestPt = segment.closestPoint(pt);
        ptDist.setMinimum(closestPt, pt);
    }
}
Also used : Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Segment(com.revolsys.geometry.model.segment.Segment)

Example 5 with Segment

use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.

the class DistanceWithLocation method computePointLine.

private boolean computePointLine(final Point point, final LineString line) {
    final BoundingBox boundingBox = line.getBoundingBox();
    if (this.minDistance == Double.MAX_VALUE || boundingBox.distance(point) <= this.minDistance) {
        for (final Segment segment : line.segments()) {
            final double distance = segment.distancePoint(point);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                final Point closestPoint = segment.closestPoint(point);
                final int segmentIndex = segment.getSegmentIndex();
                this.minDistanceLocation1 = new GeometryLocation(point, 0, point);
                this.minDistanceLocation2 = new GeometryLocation(line, segmentIndex, closestPoint);
                if (this.minDistance <= this.terminateDistance) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment) Point(com.revolsys.geometry.model.Point)

Aggregations

Segment (com.revolsys.geometry.model.segment.Segment)22 Point (com.revolsys.geometry.model.Point)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 LineSegment (com.revolsys.geometry.model.segment.LineSegment)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)2 LineString (com.revolsys.geometry.model.LineString)2 LineStringSegment (com.revolsys.geometry.model.segment.LineStringSegment)2 AbstractVertex (com.revolsys.geometry.model.vertex.AbstractVertex)2 LineStringVertex (com.revolsys.geometry.model.vertex.LineStringVertex)2 GeometryLocation (com.revolsys.geometry.operation.distance.GeometryLocation)2 Pair (com.revolsys.util.Pair)2 PointPairDistance (com.revolsys.geometry.algorithm.distance.PointPairDistance)1 LineSegmentIndex (com.revolsys.geometry.index.LineSegmentIndex)1 GeometryComponent (com.revolsys.geometry.model.GeometryComponent)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 PointDoubleXYOrientation (com.revolsys.geometry.model.impl.PointDoubleXYOrientation)1 PreparedLineString (com.revolsys.geometry.model.prep.PreparedLineString)1 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)1 DuplicateVertexError (com.revolsys.geometry.operation.simple.DuplicateVertexError)1