سلام ممکنه راهنمایی کنین ببینین این کد چی کار میکنه؟
public static synchronized double distance(Coordinate c1, Coordinate c2, double[] returnVals) {
// TODO check this now, might be different way of getting distance in new Simphony
GeodeticCalculator calculator = new GeodeticCalculator(ContextManager.roadProjection.g etCRS());
calculator.setStartingGeographicPoint(c1.x, c1.y);
calculator.setDestinationGeographicPoint(c2.x, c2.y);
double distance = calculator.getOrthodromicDistance();
if (returnVals != null && returnVals.length == 2) {
returnVals[0] = distance;
double angle = Math.toRadians(calculator.getAzimuth()); // Angle in range -PI to PI
// Need to transform azimuth (in range -180 -> 180 and where 0 points north)
// to standard mathematical (range 0 -> 360 and 90 points north)
if (angle > 0 && angle < 0.5 * Math.PI) { // NE Quadrant
angle = 0.5 * Math.PI - angle;
} else if (angle >= 0.5 * Math.PI) { // SE Quadrant
angle = (-angle) + 2.5 * Math.PI;
} else if (angle < 0 && angle > -0.5 * Math.PI) { // NW Quadrant
angle = (-1 * angle) + 0.5 * Math.PI;
} else { // SW Quadrant
angle = -angle + 0.5 * Math.PI;
}
returnVals[1] = angle;
}
return distance;
}
/**
* Converts a distance lat/long distance (e.g. returned by DistanceOp) to meters. The calculation isn't very
* accurate because (probably) it assumes that the distance is between two points that lie exactly on a line of
* longitude (i.e. one is exactly due north of the other). For this reason the value shouldn't be used in any
* calculations which is why it's returned as a String.
*
* @param dist
* The distance (as returned by DistanceOp) to convert to meters
* @return The approximate distance in meters as a String (to discourage using this approximate value in
* calculations).
* @throws Exception
* @see com.vividsolutions.jts.operation.distance.Distance Op
*/
public static synchronized String distanceToMeters(double dist) throws Exception {
// Works by creating two coords (close to a randomly chosen object) which are a certain distance apart
// then using similar method as other distance() function
GeodeticCalculator calculator = new GeodeticCalculator(ContextManager.roadProjection.g etCRS());
Coordinate c1 = ContextManager.buildingContext.getRandomObject().g etCoords();
calculator.setStartingGeographicPoint(c1.x, c1.y);
calculator.setDestinationGeographicPoint(c1.x, c1.y + dist);
return String.valueOf(calculator.getOrthodromicDistance() );
}