public static double distance(Coordinate[] c, int i, int j) { if (i > j) { int tmp = i; i = j; j = tmp; } double dist = 0d; for (int k = i; k < j; k++) { dist += c[k].distance(c[k + 1]); } return (dist); } }
/** * @param p A point in space * @return The distance the point is from the center of the circle */ public double distanceFromCenter(Coordinate p) { return Math.abs(this.center.distance(p)); }
/** * Picks the location as the point which is nearest to the center of the cell. In addition, * the nearest location is averaged with the cell center. This gives the best chance of * avoiding conflicts. * * @param pt */ private void pickNearestLocation(Coordinate pt) { // strategy - pick most central point if (location == null) { location = average(centerPt, pt); return; } if (pt.distance(centerPt) < location.distance(centerPt)) { location = average(centerPt, pt); } }
private Node findClosestNodeWithinTolerance(Coordinate inCoord) { double closestDistance = Double.MAX_VALUE; Coordinate closestCoordinate = null; List<Coordinate> list = spatialIndex.query(new Interval(inCoord.y - tolerance, inCoord.y + tolerance)); for (Coordinate c : list) { double distance = inCoord.distance(c); if (distance < closestDistance) { closestDistance = distance; closestCoordinate = c; } } if (closestCoordinate != null && closestCoordinate.distance(inCoord) < tolerance) { return m_coord2node.get(closestCoordinate); } return null; } }
private double weight(double dist, double lengthScale, double convergenceFactor) { /** * MD - using an effective radius is problematic. * * <p>The effective radius grows as a log function of the cutoff weight, so even for very * small cutoff weight values, the effective radius is only a few times the size of the * influence radius. * * <p>Also, dropping observation terms from the estimate results in very drastic * (discontinuous) changes at distances around the effective radius. (Probably because * beyond that distance there are very few terms (maybe only 2) contributing to the * estimate, so there is no smoothing effect from incorporating many estimates) * * <p>So - don't use effectiveRadius. * * <p>Or, maybe it's ok as long as a observation mask is used as well, since the effect only * occurs at large distances from observation points? */ /* * if (dist > effectiveRadius) return INTERNAL_NO_DATA; // */ double dr = dist / lengthScale; double w = Math.exp(-(dr * dr / convergenceFactor)); // if (dist > cutoffRadius) System.out.println(w); return w; } }
double calcPolygonAlignMBRAngle(Geometry geometry) { // use JTS MinimumDiameter class to calc MBR Geometry mbr = new MinimumDiameter(geometry).getMinimumRectangle(); // calc angle from the longest side of the MBR Coordinate[] coordinates = mbr.getCoordinates(); double dx, dy; if (coordinates[0].distance(coordinates[1]) > coordinates[1].distance(coordinates[2])) { dx = coordinates[1].x - coordinates[0].x; dy = coordinates[1].y - coordinates[0].y; } else { dx = coordinates[2].x - coordinates[1].x; dy = coordinates[2].y - coordinates[1].y; } double angle = Math.atan(dy / dx); // make sure we turn PI/2 into -PI/2, we don't want some labels looking straight up // and some others straight down, when almost vertical they should all be oriented // on the same side if (Math.abs(angle - Math.PI / 2) < Math.PI / 180.0) { angle = -Math.PI / 2 + Math.abs(angle - Math.PI / 2); } return angle; } }
/** * Returns the perimeter of a LineString. * * @param lineString the LineString for which the perimeter is calculated. * @return the perimeter (length) of the lineString. */ protected double getPerimeter(LineString lineString) { double perimeter = 0.0d; int numberOfPoints = lineString.getNumPoints(); Coordinate[] coordinates = lineString.getCoordinates(); for (int i = 0; i < (numberOfPoints - 1); i++) { perimeter += coordinates[i].distance(coordinates[i + 1]); } return perimeter; } }
public double getEuclideanDistance() { return ((XYNode) this.getNodeA()) .getCoordinate() .distance(((XYNode) this.getNodeB()).getCoordinate()); }
double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i + 1]); if (dist < control.getMinLength()) {
int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) {
private void checkVertexDistance(Coordinate vertex) { double vertexDist = vertex.distance(queryPt); if (vertexDist > 0) { smc.updateClearance(vertexDist, queryPt, vertex); } }
/** * Computes the length of the line segment. * @return the length of the line segment */ public double getLength() { return p0.distance(p1); }
c2.y = coords.getY(i); final double distance = c1.distance(c2); segmentLenghts[i - 1] = distance; if (i < coords.size() - 1)
public void filter(CoordinateSequence seq, int i) { Coordinate p = seq.getCoordinate(i); double dist = p.distance(basePt); if (dist > tolerance) return; nearestPt = p; vertexIndex = i; }
private void checkVertex(LineString lineStr, CoordinateSequence seq, int i) { Coordinate p0 = seq.getCoordinate(i); double dist0 = p0.distance(testPt); if (dist0 < tolerance) { nearestPt = p0; segIndex = i; isVertex = true; } }
private void populateChildren(Coordinate[] pt) { Envelope env = line.getEnvelopeInternal(); for (int i = 0; i < pt.length; i++) { double dist = Double.NaN; if (i < pt.length - 1) dist = pt[i].distance(pt[i + 1]); GeometricObjectNode node = CoordinateNode.create(pt[i], i, dist); children.add(node); } } }
public static double distance(Coordinate p0, Coordinate p1) { // default to 2D distance if either Z is not set if (Double.isNaN(p0.getZ()) || Double.isNaN(p1.getZ())) return p0.distance(p1); double dx = p0.x - p1.x; double dy = p0.y - p1.y; double dz = p0.getZ() - p1.getZ(); return Math.sqrt(dx * dx + dy * dy + dz * dz); }
private void doNearestPointsTest(String wkt0, String wkt1, double distance, Coordinate p0, Coordinate p1) throws ParseException { DistanceOp op = new DistanceOp(new WKTReader().read(wkt0), new WKTReader().read(wkt1)); double tolerance = 1E-10; assertEquals(distance, op.nearestPoints()[0].distance(op.nearestPoints()[1]), tolerance); assertEquals(p0.x, op.nearestPoints()[0].x, tolerance); assertEquals(p0.y, op.nearestPoints()[0].y, tolerance); assertEquals(p1.x, op.nearestPoints()[1].x, tolerance); assertEquals(p1.y, op.nearestPoints()[1].y, tolerance); } }