Skip to content

Instantly share code, notes, and snippets.

@nknize
Created March 30, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nknize/384a60df159159c5a7b7b3657a12b385 to your computer and use it in GitHub Desktop.
Save nknize/384a60df159159c5a7b7b3657a12b385 to your computer and use it in GitHub Desktop.
/**
* Finds a point along a bearing from a given lon,lat geolocation using great circle arc
*
* @param lon origin longitude in degrees
* @param lat origin latitude in degrees
* @param bearing azimuthal bearing in degrees
* @param dist distance in meters
* @param pt resulting point
* @return the point along a bearing at a given distance in meters
*/
public static final double[] pointFromLonLatBearingGreatCircle(double lon, double lat, double bearing, double dist, double[] pt) {
if (pt == null) {
pt = new double[2];
}
lon *= TO_RADIANS;
lat *= TO_RADIANS;
bearing *= TO_RADIANS;
final double cLat = SloppyMath.cos(lat);
final double sLat = SloppyMath.sin(lat);
final double sinDoR = SloppyMath.sin(dist / GeoProjectionUtils.SEMIMAJOR_AXIS);
final double cosDoR = SloppyMath.cos(dist / GeoProjectionUtils.SEMIMAJOR_AXIS);
pt[1] = SloppyMath.asin(sLat*cosDoR + cLat * sinDoR * SloppyMath.cos(bearing));
pt[0] = TO_DEGREES * (lon + Math.atan2(SloppyMath.sin(bearing) * sinDoR * cLat, cosDoR - sLat * SloppyMath.sin(pt[1])));
pt[1] *= TO_DEGREES;
return pt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment