/** * Computes the distance between this line segment and another segment. * * @return the distance to the other segment */ public double distance(LineSegment ls) { return CGAlgorithms.distanceLineLine(p0, p1, ls.p0, ls.p1); }
private double computeLineLineDistance(FacetSequence facetSeq) { // both linear - compute minimum segment-segment distance double minDistance = Double.MAX_VALUE; for (int i = start; i < end - 1; i++) { for (int j = facetSeq.start; j < facetSeq.end - 1; j++) { pts.getCoordinate(i, p0); pts.getCoordinate(i + 1, p1); facetSeq.pts.getCoordinate(j, q0); facetSeq.pts.getCoordinate(j + 1, q1); double dist = CGAlgorithms.distanceLineLine(p0, p1, q0, q1); if (dist == 0.0) return 0.0; if (dist < minDistance) { minDistance = dist; } } } return minDistance; }
/** * Computes the distance between this line segment and another segment. * * @return the distance to the other segment */ public double distance(LineSegment ls) { return CGAlgorithms.distanceLineLine(p0, p1, ls.p0, ls.p1); }
private void computeMinDistance(LineString line0, LineString line1, GeometryLocation[] locGeom) { if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms.distanceLineLine( coord0[i], coord0[i + 1], coord1[j], coord1[j + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); locGeom[0] = new GeometryLocation(line0, i, closestPt[0]); locGeom[1] = new GeometryLocation(line1, j, closestPt[1]); } if (minDistance <= terminateDistance) return; } } }
private double computeLineLineDistance(FacetSequence facetSeq) { // both linear - compute minimum segment-segment distance double minDistance = Double.MAX_VALUE; for (int i = start; i < end - 1; i++) { for (int j = facetSeq.start; j < facetSeq.end - 1; j++) { pts.getCoordinate(i, p0); pts.getCoordinate(i + 1, p1); facetSeq.pts.getCoordinate(j, q0); facetSeq.pts.getCoordinate(j + 1, q1); double dist = CGAlgorithms.distanceLineLine(p0, p1, q0, q1); if (dist == 0.0) return 0.0; if (dist < minDistance) { minDistance = dist; } } } return minDistance; }
private void computeMinDistance(LineString line0, LineString line1, GeometryLocation[] locGeom) { if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms.distanceLineLine( coord0[i], coord0[i + 1], coord1[j], coord1[j + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); locGeom[0] = new GeometryLocation(line0, i, closestPt[0]); locGeom[1] = new GeometryLocation(line1, j, closestPt[1]); } if (minDistance <= terminateDistance) return; } } }