Created
May 4, 2016 17:58
-
-
Save tobyprivett/e5d7d229dcfebe22a702a3dc408d5b35 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // from: http://www.movable-type.co.uk/scripts/latlong-vincenty.html | |
| var sinα1 = Math.sin(α1); | |
| var cosα1 = Math.cos(α1); | |
| var tanU1 = (1-f) * Math.tan(φ1), cosU1 = 1 / Math.sqrt((1 + tanU1*tanU1)), sinU1 = tanU1 * cosU1; | |
| var σ1 = Math.atan2(tanU1, cosα1); | |
| var sinα = cosU1 * sinα1; | |
| var cosSqα = 1 - sinα*sinα; | |
| var uSq = cosSqα * (a*a - b*b) / (b*b); | |
| var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); | |
| var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); | |
| var σ = s / (b*A), σʹ; | |
| do { | |
| var cos2σM = Math.cos(2*σ1 + σ); | |
| var sinσ = Math.sin(σ); | |
| var cosσ = Math.cos(σ); | |
| var Δσ = B*sinσ*(cos2σM+B/4*(cosσ*(-1+2*cos2σM*cos2σM)- | |
| B/6*cos2σM*(-3+4*sinσ*sinσ)*(-3+4*cos2σM*cos2σM))); | |
| σʹ = σ; | |
| σ = s / (b*A) + Δσ; | |
| } while (Math.abs(σ-σʹ) > 1e-12); | |
| var tmp = sinU1*sinσ - cosU1*cosσ*cosα1; | |
| var φ2 = Math.atan2(sinU1*cosσ + cosU1*sinσ*cosα1, (1-f)*Math.sqrt(sinα*sinα + tmp*tmp)); | |
| var λ = Math.atan2(sinσ*sinα1, cosU1*cosσ - sinU1*sinσ*cosα1); | |
| var C = f/16*cosSqα*(4+f*(4-3*cosSqα)); | |
| var L = λ - (1-C) * f * sinα * | |
| (σ + C*sinσ*(cos2σM+C*cosσ*(-1+2*cos2σM*cos2σM))); | |
| var λ2 = (λ1+L+3*Math.PI)%(2*Math.PI) - Math.PI; // normalise to -180...+180 | |
| var revAz = Math.atan2(sinα, -tmp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment