Skip to content

Commit b6060f3

Browse files
committed
Reimplement greatCircleLineAlong using geodesy
1 parent 3ba1622 commit b6060f3

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

shinysdr/i/webstatic/client/map/map-core.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
define([
2121
'require',
22+
'geodesy/latlon-spherical',
2223
'../domtools',
2324
'../events',
2425
'../gltools',
@@ -34,6 +35,7 @@ define([
3435
'text!./curves-f.glsl',
3536
], (
3637
require,
38+
LatLon,
3739
import_domtools,
3840
import_events,
3941
import_gltools,
@@ -100,7 +102,8 @@ define([
100102
// Degree trig functions.
101103
// We use degrees in this module because degrees are standard for latitude and longitude, and are also useful for more exact calculations because 360 is exactly representable as a floating-point number whereas 2π is not.
102104
// TODO: Look at the edge cases and see if it would be useful to have dcos & dsin do modulo 360, so we get that exactness for them.
103-
var RADIANS_PER_DEGREE = Math.PI / 180;
105+
const RADIANS_PER_DEGREE = Math.PI / 180;
106+
const DEGREES_PER_RADIAN = 180 / Math.PI;
104107
function dcos(x) { return cos(RADIANS_PER_DEGREE * x); }
105108
function dsin(x) { return sin(RADIANS_PER_DEGREE * x); }
106109
function dasin(x) { return asin(x)/RADIANS_PER_DEGREE; }
@@ -1692,17 +1695,10 @@ define([
16921695
const smoothStep = 1;
16931696
function greatCircleLineAlong(lat, lon, bearing) {
16941697
const line = [];
1695-
const sinlat = dsin(lat), coslat = dcos(lat);
1696-
const sinazimuth = dsin(bearing), cosazimuth = dcos(bearing);
1698+
const start = new LatLon(lat, lon);
16971699
for (let angle = 0; angle < 180 + smoothStep/2; angle += smoothStep) {
1698-
// Algorithm adapted from https://github.com/chrisveness/geodesy/blob/v1.1.2/latlon-spherical.js#L212
1699-
const targetLat = dasin(
1700-
sinlat*dcos(angle) +
1701-
coslat*dsin(angle)*cosazimuth);
1702-
const targetLon = lon + datan2(
1703-
sinazimuth*dsin(angle)*coslat,
1704-
dcos(angle)-sinlat*dsin(targetLat));
1705-
line.push(Object.freeze({position: Object.freeze([targetLat, targetLon])}));
1700+
const point = start.destinationPoint(angle, bearing, DEGREES_PER_RADIAN);
1701+
line.push(Object.freeze({position: Object.freeze([point.lat, point.lon])}));
17061702
}
17071703
return Object.freeze(line);
17081704
}

0 commit comments

Comments
 (0)