Created
November 19, 2013 08:23
-
-
Save eventomer/7542065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the destination point from this point having travelled the given distance (in km) on the | |
* given initial bearing (bearing may vary before destination is reached) | |
* | |
* see http://williams.best.vwh.net/avform.htm#LL | |
* | |
* @param {Number} brng: Initial bearing in degrees | |
* @param {Number} dist: Distance in km | |
* @returns {LatLon} Destination point | |
*/ | |
LatLon.prototype.destinationPoint = function(brng, dist) { | |
dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN; | |
dist = dist/this._radius; // convert dist to angular distance in radians | |
brng = brng.toRad(); // | |
var lat1 = this._lat.toRad(), lon1 = this._lon.toRad(); | |
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + | |
Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) ); | |
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), | |
Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2)); | |
lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI; // normalise to -180..+180º | |
return new LatLon(lat2.toDeg(), lon2.toDeg()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment