ورود

View Full Version : راهنمایی در فهمیدن کد



sooren_66
سه شنبه 18 مهر 1396, 13:58 عصر
سلام ممکنه راهنمایی کنین ببینین این کد چی کار میکنه؟

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

sooren_66
جمعه 05 آبان 1396, 17:09 عصر
کسی نیست منو راهنمایی کنه

vahid-p
جمعه 05 آبان 1396, 17:23 عصر
توضیحاتش خیلی کامله و خودش گفته که دو نقطه بر حسب مختصات میگیره و فاصله بر حسب متر بر میگردونه. چند تا محاسبه ساده هم داره و از کلاس GeodeticCalculater استفاده کرده و اون چند تا if هم بر اساس زاویه دو نقطه مشخص میکنه در کدوم ناحیه از چهار ناحیه صفحه قرار میگیره و کلا نکته خاص برنامه نویسی نداره.

شما خودتون چه تلاشی برای فهمیدنش کردید و چی رو فهمیدید و دقیقا چی رو نمیدونید؟

sooren_66
دوشنبه 08 آبان 1396, 00:55 صبح
توضیحاتش خیلی کامله و خودش گفته که دو نقطه بر حسب مختصات میگیره و فاصله بر حسب متر بر میگردونه. چند تا محاسبه ساده هم داره و از کلاس GeodeticCalculater استفاده کرده و اون چند تا if هم بر اساس زاویه دو نقطه مشخص میکنه در کدوم ناحیه از چهار ناحیه صفحه قرار میگیره و کلا نکته خاص برنامه نویسی نداره.

شما خودتون چه تلاشی برای فهمیدنش کردید و چی رو فهمیدید و دقیقا چی رو نمیدونید؟
با سلام و تشکر من کار getAzimuth رو متوجه نمی شم و اینکه اگه بخوام این کد رو پیشرفته تر کنم دقیقا" باید کجا هارو دستکاری کنم مثلا" من بخوام این کد قابلیت تشخیص 4راه رو داشته باشه و یا بخوام فرمول شیب خط رو به این کد اضافه کنم دقیقا" نمی دونم کجای برنامه و چطوری باید این کارو بکنم
این برنامه کدهای زیادی داره من فقط تکه ی مربوط به مختصات رو اوردم چون فکر میکنم این فقط باید تغییر داده بشه

vahid-p
دوشنبه 08 آبان 1396, 11:53 صبح
اینجوری که من با سرچ از مستندش فهمیدم، جهت خط بین دو نقطه رو میده که عددی بین -180 تا 180 بر حسب درجه هست.

اینکه چطور 4 راه رو تشخیص بدید رو نمیدونم. در انجمن الگوریتم بپرسید شاید جواب بهتری بگیرید. یا در اینترنت سرج کنید ببینید کاری قبلا انجام شده یا نه.
تازه خیلی به ساختار دادتون بستگی داره و... . مثلا اگر از ساختار گراف استفاده شده باشه خب هر نودی با درجه 4 یک چهار راه میشه چیز خاصی هم نداره.

این سوالات جزئی زیاد جاش تو انجمن جاوا نیست، یعنی مشکل برنامه نویسی جاوا نیست، بحث سر الگوریتمش هست و...