private boolean isShallow(Coordinate p0, Coordinate p1, Coordinate p2, double distanceTol) { double dist = Distance.pointToSegment(p1, p0, p2); return dist < distanceTol; }
/** * Computes the perpendicular distance between the (infinite) line defined * by this line segment and a point. * * @return the perpendicular distance between the defined line and the given point */ public double distancePerpendicular(Coordinate p) { return Distance.pointToLinePerpendicular(p, p0, p1); }
/** * Computes the distance between this line segment and another segment. * * @return the distance to the other segment */ public double distance(LineSegment ls) { return Distance.segmentToSegment(p0, p1, ls.p0, ls.p1); }
/** * Computes the distance between this line segment and a given point. * * @return the distance from this segment to the given point */ public double distance(Coordinate p) { return Distance.pointToSegment(p, p0, p1); }
public void testRandomDisjointCollinearSegments() throws Exception { int n = 1000000; int failCount = 0; for (int i = 0; i < n; i++) { //System.out.println(i); Coordinate[] seg = randomDisjointCollinearSegments(); if (0 == Distance.segmentToSegment(seg[0], seg[1], seg[2], seg[3])) { /* System.out.println("FAILED! - " + WKTWriter.toLineString(seg[0], seg[1]) + " - " + WKTWriter.toLineString(seg[2], seg[3])); */ failCount++; } } System.out.println("# failed = " + failCount + " out of " + n); }
public void testDistancePointLinePerpendicular() { assertEquals(0.5, Distance.pointToLinePerpendicular( new Coordinate(0.5, 0.5), new Coordinate(0,0), new Coordinate(1,0)), 0.000001); assertEquals(0.5, Distance.pointToLinePerpendicular( new Coordinate(3.5, 0.5), new Coordinate(0,0), new Coordinate(1,0)), 0.000001); assertEquals(0.707106, Distance.pointToLinePerpendicular( new Coordinate(1,0), new Coordinate(0,0), new Coordinate(1,1)), 0.000001); }
double minDist = Distance.pointToSegment(p1, q1, q2); double dist = Distance.pointToSegment(p2, q1, q2); if (dist < minDist) { minDist = dist; nearestPt = p2; dist = Distance.pointToSegment(q1, p1, p2); if (dist < minDist) { minDist = dist; nearestPt = q1; dist = Distance.pointToSegment(q2, p1, p2); if (dist < minDist) { minDist = dist;
private double computeDistanceLineLine(FacetSequence facetSeq, GeometryLocation[] locs) { // both linear - compute minimum segment-segment distance double minDistance = Double.MAX_VALUE; for (int i = start; i < end - 1; i++) { Coordinate p0 = pts.getCoordinate(i); Coordinate p1 = pts.getCoordinate(i + 1); for (int j = facetSeq.start; j < facetSeq.end - 1; j++) { Coordinate q0 = facetSeq.pts.getCoordinate(j); Coordinate q1 = facetSeq.pts.getCoordinate(j + 1); double dist = Distance.segmentToSegment(p0, p1, q0, q1); if (dist < minDistance) { minDistance = dist; if (locs != null) updateNearestLocationsLineLine(i, p0, p1, facetSeq, j, q0, q1, locs); if (minDistance <= 0.0) return minDistance; } } } return minDistance; }
private boolean isShallowConcavity(Coordinate p0, Coordinate p1, Coordinate p2, double distanceTol) { int orientation = Orientation.index(p0, p1, p2); boolean isAngleToSimplify = (orientation == angleOrientation); if (! isAngleToSimplify) return false; double dist = Distance.pointToSegment(p1, p0, p2); return dist < distanceTol; }
public void testDistanceLineLineDisjointCollinear() { assertEquals(1.999699, Distance.segmentToSegment( new Coordinate(0,0), new Coordinate(9.9, 1.4), new Coordinate(11.88, 1.68), new Coordinate(21.78, 3.08)), 0.000001); } }
private static boolean isFlat(Coordinate p, Coordinate p1, Coordinate p2) { double dist = Distance.pointToSegment(p, p1, p2); double len = p1.distance(p2); if (dist/len < POINT_LINE_FLATNESS_RATIO) return true; return false; }
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 = Distance.segmentToSegment( 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; } } }
/** * Computes the distance from a point to a sequence of line segments. * * @param p * a point * @param line * a sequence of contiguous line segments defined by their vertices * @return the minimum distance between the point and the line segments */ public static double pointToSegmentString(Coordinate p, Coordinate[] line) { if (line.length == 0) throw new IllegalArgumentException( "Line array must contain at least one vertex"); // this handles the case of length = 1 double minDistance = p.distance(line[0]); for (int i = 0; i < line.length - 1; i++) { double dist = Distance.pointToSegment(p, line[i], line[i + 1]); if (dist < minDistance) { minDistance = dist; } } return minDistance; }
private void checkSegmentDistance(Coordinate seg0, Coordinate seg1) { if (queryPt.equals2D(seg0) || queryPt.equals2D(seg1)) return; double segDist = Distance.pointToSegment(queryPt, seg1, seg0); if (segDist > 0) smc.updateClearance(segDist, queryPt, seg1, seg0); }
return Distance.pointToSegment(A, C, D); if (C.equals(D)) return Distance.pointToSegment(D, A, B); Distance.pointToSegment(A, C, D), Distance.pointToSegment(B, C, D), Distance.pointToSegment(C, A, B), Distance.pointToSegment(D, A, B));
/** * Tests whether a triangular ring would be eroded completely by the given * buffer distance. * This is a precise test. It uses the fact that the inner buffer of a * triangle converges on the inCentre of the triangle (the point * equidistant from all sides). If the buffer distance is greater than the * distance of the inCentre from a side, the triangle will be eroded completely. * * This test is important, since it removes a problematic case where * the buffer distance is slightly larger than the inCentre distance. * In this case the triangle buffer curve "inverts" with incorrect topology, * producing an incorrect hole in the buffer. * * @param triangleCoord * @param bufferDistance * @return */ private boolean isTriangleErodedCompletely( Coordinate[] triangleCoord, double bufferDistance) { Triangle tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]); Coordinate inCentre = tri.inCentre(); double distToCentre = Distance.pointToSegment(inCentre, tri.p0, tri.p1); return distToCentre < Math.abs(bufferDistance); }
private double computeDistancePointLine(Coordinate pt, FacetSequence facetSeq, GeometryLocation[] locs) { double minDistance = Double.MAX_VALUE; for (int i = facetSeq.start; i < facetSeq.end - 1; i++) { Coordinate q0 = facetSeq.pts.getCoordinate(i); Coordinate q1 = facetSeq.pts.getCoordinate(i + 1); double dist = Distance.pointToSegment(pt, q0, q1); if (dist < minDistance) { minDistance = dist; if (locs != null) updateNearestLocationsPointLine(pt, facetSeq, i, q0, q1, locs); if (minDistance <= 0.0) return minDistance; } } return minDistance; }
return Distance.pointToSegment(A, C, D); if (C.equals(D)) return Distance.pointToSegment(D, A, B); return Math .min( Distance.pointToSegment(A, C, D), Math.min( Distance.pointToSegment(B, C, D), Math.min(Distance.pointToSegment(C, A, B), Distance.pointToSegment(D, A, B)))); Distance.pointToSegment(A, C, D), Math.min( Distance.pointToSegment(B, C, D), Math.min(Distance.pointToSegment(C, A, B), Distance.pointToSegment(D, A, B))));
public void testDistancePointLine() { assertEquals(0.5, Distance.pointToSegment( new Coordinate(0.5, 0.5), new Coordinate(0,0), new Coordinate(1,0)), 0.000001); assertEquals(1.0, Distance.pointToSegment( new Coordinate(2, 0), new Coordinate(0,0), new Coordinate(1,0)), 0.000001); }
private double segmentDistance(FacetSequence fs1, FacetSequence fs2) { for (int i1 = 0; i1 < fs1.size(); i1++) { for (int i2 = 1; i2 < fs2.size(); i2++) { Coordinate p = fs1.getCoordinate(i1); Coordinate seg0 = fs2.getCoordinate(i2-1); Coordinate seg1 = fs2.getCoordinate(i2); if (! (p.equals2D(seg0) || p.equals2D(seg1))) { double d = Distance.pointToSegment(p, seg0, seg1); if (d < minDist) { minDist = d; updatePts(p, seg0, seg1); if (d == 0.0) return d; } } } } return minDist; }