Demo entry 1487235

java

   

Submitted by anonymous on Apr 18, 2015 at 21:06
Language: Java. Code size: 760 Bytes.

public static GeoCoordinate fromBearingDistance(double lat, double lon, double bearing, double d)
{
	/*
	 * φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )
	 * λ2 = λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2))
	 */
	double lat1 = Math.toRadians(lat);
	double lon1 = Math.toRadians(lon);
	double brng = Math.toRadians(bearing);
	double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS)
			+ Math.cos(lat1) * Math.sin(d / EARTH_RADIUS) * Math.cos(brng));
	double lon2 = lon1
			+ Math.atan2(
					Math.sin(brng) * Math.sin(d / EARTH_RADIUS)
							* Math.cos(lat1), Math.cos(d / EARTH_RADIUS)
							- Math.sin(lat1) * Math.sin(lat2));
	return new GeoCoordinate(Math.toDegrees(lat2), Math.toDegrees(lon2));
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).