PDA

View Full Version : سوال: کار این قطعه کد جاوا



sooren_66
یک شنبه 23 آبان 1395, 20:23 عصر
سلام دوستان کسی میتونه بگه این کد دقیقا" چه کاری رو انجام میده؟


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;
}

vahid-p
دوشنبه 24 آبان 1395, 11:05 صبح
این یه الگوریتمه که نباید انتظار داشته باشید از روی این کد کسی بگه چیکار میکنه. خب یه چیزهایی رو حساب کرده ولی دقیقا به چه دردی میخوره باید ببینید از کجا آوردینش و چرا اصلا این کد رو انتخاب کردید

اگر الگوریتم خاصی در زمینه خاصی هست که باید همونجا مطرح بشه و ربطی نداره به زبان جاوا نوشته شده یا هر زبان دیگری.

ولی در کل الگوریتمیه که داره یه فاصله ای رو حساب میکنه و خب زاویه و اینا هم دخیله. کلاس GeodeticCalculator هم که کدش اصلا مشخص نیست چیه ولی از اسمش به نظر میاد کوتاهترین مسیر رو براتون محاسبه می کنه.