private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance) { LineSegment seg = new LineSegment(); seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDist = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { Coordinate midPt = pts[k]; double distance = seg.distance(midPt); if (distance > maxDist) { maxDist = distance; maxIndex = k; } } maxDistance[0] = maxDist; return maxIndex; }
private void simplifySection(int i, int j) { if((i+1) == j) { return; } seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDistance = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { double distance = seg.distance(pts[k]); if (distance > maxDistance) { maxDistance = distance; maxIndex = k; } } if (maxDistance <= distanceTolerance) { for(int k = i + 1; k < j; k++) { usePt[k] = false; } } else { simplifySection(i, maxIndex); simplifySection(maxIndex, j); } }
/** * Tests whether a {@link Coordinate} lies on a {@link QuadEdge}, up to a * tolerance determined by the subdivision tolerance. * * @param e * a QuadEdge * @param p * a point * @return true if the vertex lies on the edge */ public boolean isOnEdge(QuadEdge e, Coordinate p) { seg.setCoordinates(e.orig().getCoordinate(), e.dest().getCoordinate()); double dist = seg.distance(p); // heuristic (hack?) return dist < edgeCoincidenceTolerance; }
private boolean isWithinToleranceOfBoundary(Coordinate pt) { for (int i = 0; i < linework.getNumGeometries(); i++) { LineString line = (LineString) linework.getGeometryN(i); CoordinateSequence seq = line.getCoordinateSequence(); for (int j = 0; j < seq.size() - 1; j++) { seq.getCoordinate(j, seg.p0); seq.getCoordinate(j + 1, seg.p1); double dist = seg.distance(pt); if (dist <= boundaryDistanceTolerance) return true; } } return false; } }
double dist = seg.distance(snapPt); if (dist < snapTolerance && dist < minDist) { minDist = dist;
private double indexOfFromStart(Coordinate inputPt, double minIndex) { double minDistance = Double.MAX_VALUE; double ptMeasure = minIndex; double segmentStartMeasure = 0.0; LineSegment seg = new LineSegment(); LinearIterator it = new LinearIterator(linearGeom); while (it.hasNext()) { if (! it.isEndOfLine()) { seg.p0 = it.getSegmentStart(); seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segMeasureToPt = segmentNearestMeasure(seg, inputPt, segmentStartMeasure); if (segDistance < minDistance && segMeasureToPt > minIndex) { ptMeasure = segMeasureToPt; minDistance = segDistance; } segmentStartMeasure += seg.getLength(); } it.next(); } return ptMeasure; }
/** * Computes the Hausdorff distance between two LineSegments. * * To compute the Hausdorff distance, the distances from one segment's endpoints to the other segment are * computed and the maximum chosen. * * @param seg0 * @param seg1 * @return the Hausdorff distance between the segments */ public static double hausdorffDistance(LineSegment seg0, LineSegment seg1) { double hausdorffDist = seg0.distance(seg1.p0); double dist; dist = seg0.distance(seg1.p1); if (dist > hausdorffDist) { hausdorffDist = dist; } dist = seg1.distance(seg0.p0); if (dist > hausdorffDist) { hausdorffDist = dist; } dist = seg1.distance(seg0.p1); if (dist > hausdorffDist) { hausdorffDist = dist; } return hausdorffDist; }
// create Line LineSegment ls = new LineSegment(p1.getX(), p1.getY(), p2.getX(), p2.getY()); //calculate distance between Line and Point double distanceLinePoint = ls.distance(new Coordinate(p3.getX(), p3.getY())); // calculate distance between Points (p1 - p3) double distanceBetweenPoints = new Coordinate(p1.getX(), p1.getY()).distance(new Coordinate(p3.getX(), p3.getY()));
seg.p0 = it.getSegmentStart(); seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segFrac = seg.segmentFraction(inputPt);
private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance) { LineSegment seg = new LineSegment(); seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDist = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { Coordinate midPt = pts[k]; double distance = seg.distance(midPt); if (distance > maxDist) { maxDist = distance; maxIndex = k; } } maxDistance[0] = maxDist; return maxIndex; }
private void simplifySection(int i, int j) { if((i+1) == j) { return; } seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDistance = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { double distance = seg.distance(pts[k]); if (distance > maxDistance) { maxDistance = distance; maxIndex = k; } } if (maxDistance <= distanceTolerance) { for(int k = i + 1; k < j; k++) { usePt[k] = false; } } else { simplifySection(i, maxIndex); simplifySection(maxIndex, j); } }
private void updateLength(LineSegment seg, Coordinate inputPt, double segStartLocationDistance) { double dist = seg.distance(inputPt); if (dist > minDistanceToPoint) return; minDistanceToPoint = dist; // found new minimum, so compute location distance of point double projFactor = seg.projectionFactor(inputPt); if (projFactor <= 0.0) locationLength = segStartLocationDistance; else if (projFactor <= 1.0) locationLength = segStartLocationDistance + projFactor * seg.getLength(); else locationLength = segStartLocationDistance + seg.getLength(); } }
/** * Tests whether a {@link Coordinate} lies on a {@link QuadEdge}, up to a * tolerance determined by the subdivision tolerance. * * @param e * a QuadEdge * @param p * a point * @return true if the vertex lies on the edge */ public boolean isOnEdge(QuadEdge e, Coordinate p) { seg.setCoordinates(e.orig().getCoordinate(), e.dest().getCoordinate()); double dist = seg.distance(p); // heuristic (hack?) return dist < edgeCoincidenceTolerance; }
private boolean isWithinToleranceOfBoundary(Coordinate pt) { for (int i = 0; i < linework.getNumGeometries(); i++) { LineString line = (LineString) linework.getGeometryN(i); CoordinateSequence seq = line.getCoordinateSequence(); for (int j = 0; j < seq.size() - 1; j++) { seq.getCoordinate(j, seg.p0); seq.getCoordinate(j + 1, seg.p1); double dist = seg.distance(pt); if (dist <= boundaryDistanceTolerance) return true; } } return false; } }
double dist = seg.distance(snapPt); if (dist < snapTolerance && dist < minDist) { minDist = dist;
private double indexOfFromStart(Coordinate inputPt, double minIndex) { double minDistance = Double.MAX_VALUE; double ptMeasure = minIndex; double segmentStartMeasure = 0.0; LineSegment seg = new LineSegment(); LinearIterator it = new LinearIterator(linearGeom); while (it.hasNext()) { if (! it.isEndOfLine()) { seg.p0 = it.getSegmentStart(); seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segMeasureToPt = segmentNearestMeasure(seg, inputPt, segmentStartMeasure); if (segDistance < minDistance && segMeasureToPt > minIndex) { ptMeasure = segMeasureToPt; minDistance = segDistance; } segmentStartMeasure += seg.getLength(); } it.next(); } return ptMeasure; }
Coordinate intersection = CoordinateUtils.vectorIntersection(inCenter, vector, side.p0, new Vector3D(side.p0,side.p1).normalize()); double distInters = intersection == null ? Double.MAX_VALUE : side.distance(intersection); if(intersection != null && distInters < nearestIntersection) { pointIntersection = new Coordinate(intersection.x, intersection.y,
Coordinate intersection = CoordinateUtils.vectorIntersection(inCenter, vector, side.p0, new Vector3D(side.p0,side.p1).normalize()); double distInters = intersection == null ? Double.MAX_VALUE : side.distance(intersection); if(intersection != null && distInters < nearestIntersection) { pointIntersection = new Coordinate(intersection.x, intersection.y,
seg.p0 = it.getSegmentStart(); seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segFrac = seg.segmentFraction(inputPt);