From 54771112c7f44573bb1cc8657f0fcef8e11915cc Mon Sep 17 00:00:00 2001 From: James Edington Date: Tue, 26 Jan 2021 13:17:52 -0700 Subject: [PATCH 1/4] Add upstream source for ellipsoidal algorithms --- latlon-ellipsoidal-vincenty.js | 1 + 1 file changed, 1 insertion(+) diff --git a/latlon-ellipsoidal-vincenty.js b/latlon-ellipsoidal-vincenty.js index 24082422..bb26d02f 100644 --- a/latlon-ellipsoidal-vincenty.js +++ b/latlon-ellipsoidal-vincenty.js @@ -1,6 +1,7 @@ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Vincenty Direct and Inverse Solution of Geodesics on the Ellipsoid (c) Chris Veness 2002-2020 */ /* MIT Licence */ +/* www.ngs.noaa.gov/PUBS_LIB/inverse.pdf */ /* www.movable-type.co.uk/scripts/latlong-ellipsoidal-vincenty.html */ /* www.movable-type.co.uk/scripts/geodesy-library.html#latlon-ellipsoidal-vincenty */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ From b19b59b2edbcc0ff0b085d114075c144ac97b8e8 Mon Sep 17 00:00:00 2001 From: James Edington Date: Tue, 26 Jan 2021 13:24:39 -0700 Subject: [PATCH 2/4] Refactor eq'n (6) to take full advantage of its performant design From the original paper: The compactness of the recommended solutions is due to the use of nested equations to compute elliptic terms and of only three trigonometric functions: sine, cosine, and arc tangent. Nesting reduces the number of operations involving storage and retrieval of intermediate results (particularly when programming) in assembly language), reduces the length of the program and the time of execution, and minimizes the possibility of underflow. TODO: benchmarking and performance analysis to validate that this change is appropriately taken advantage of by modern engines such as V8 and Spidermonkey --- latlon-ellipsoidal-vincenty.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latlon-ellipsoidal-vincenty.js b/latlon-ellipsoidal-vincenty.js index bb26d02f..fff3627c 100644 --- a/latlon-ellipsoidal-vincenty.js +++ b/latlon-ellipsoidal-vincenty.js @@ -208,8 +208,8 @@ class LatLonEllipsoidal_Vincenty extends LatLonEllipsoidal { const sinα = cosU1 * sinα1; // α = azimuth of the geodesic at the equator const cosSqα = 1 - sinα*sinα; const uSq = cosSqα * (a*a - b*b) / (b*b); - const A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); - const B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); + const A = (((uSq*-175 + 320)*uSq - 768)*uSq + 4096)*uSq/16384 + 1; + const B = (((uSq*-47 + 74)*uSq - 128)*uSq + 256)*uSq/1024 + 1; let σ = s / (b*A), sinσ = null, cosσ = null, Δσ = null; // σ = angular distance P₁ P₂ on the sphere let cos2σₘ = null; // σₘ = angular distance on the sphere from the equator to the midpoint of the line From c844832a0b8804fbe6c312fa84f0944fde874394 Mon Sep 17 00:00:00 2001 From: James Edington Date: Tue, 26 Jan 2021 13:48:12 -0700 Subject: [PATCH 3/4] Fix embarassing typo --- latlon-ellipsoidal-vincenty.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latlon-ellipsoidal-vincenty.js b/latlon-ellipsoidal-vincenty.js index fff3627c..31e204d1 100644 --- a/latlon-ellipsoidal-vincenty.js +++ b/latlon-ellipsoidal-vincenty.js @@ -209,7 +209,7 @@ class LatLonEllipsoidal_Vincenty extends LatLonEllipsoidal { const cosSqα = 1 - sinα*sinα; const uSq = cosSqα * (a*a - b*b) / (b*b); const A = (((uSq*-175 + 320)*uSq - 768)*uSq + 4096)*uSq/16384 + 1; - const B = (((uSq*-47 + 74)*uSq - 128)*uSq + 256)*uSq/1024 + 1; + const B = (((uSq*-47 + 74)*uSq - 128)*uSq + 256)*uSq/1024; let σ = s / (b*A), sinσ = null, cosσ = null, Δσ = null; // σ = angular distance P₁ P₂ on the sphere let cos2σₘ = null; // σₘ = angular distance on the sphere from the equator to the midpoint of the line From c4a3012f6b5d03ad5f6e02cfca18a16b5c3317b4 Mon Sep 17 00:00:00 2001 From: James Edington Date: Wed, 10 Feb 2021 20:11:29 -0700 Subject: [PATCH 4/4] Apply performance changes to the inverse formula, too --- latlon-ellipsoidal-vincenty.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latlon-ellipsoidal-vincenty.js b/latlon-ellipsoidal-vincenty.js index 31e204d1..71853deb 100644 --- a/latlon-ellipsoidal-vincenty.js +++ b/latlon-ellipsoidal-vincenty.js @@ -302,8 +302,8 @@ class LatLonEllipsoidal_Vincenty extends LatLonEllipsoidal { if (iterations >= 1000) throw new EvalError('Vincenty formula failed to converge'); const uSq = cosSqα * (a*a - b*b) / (b*b); - const A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); - const B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); + const A = (((uSq*-175 + 320)*uSq - 768)*uSq + 4096)*uSq/16384 + 1; + const B = (((uSq*-47 + 74)*uSq - 128)*uSq + 256)*uSq/1024; const Δσ = B*sinσ*(cos2σₘ+B/4*(cosσ*(-1+2*cos2σₘ*cos2σₘ)- B/6*cos2σₘ*(-3+4*sinσ*sinσ)*(-3+4*cos2σₘ*cos2σₘ)));