diff options
author | Pirate Praveen <praveen@debian.org> | 2017-10-09 11:57:35 +0530 |
---|---|---|
committer | Pirate Praveen <praveen@debian.org> | 2017-10-09 11:57:35 +0530 |
commit | 3db5c79f87119a5b46ab63cbfa6050700a978117 (patch) | |
tree | ce0bc40cb6a86a7c0e20c6c9cbde83e18b1d9c44 /src/interpolate.js |
Import Upstream version 1.9.0
Diffstat (limited to 'src/interpolate.js')
-rw-r--r-- | src/interpolate.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/interpolate.js b/src/interpolate.js new file mode 100644 index 0000000..748ff3d --- /dev/null +++ b/src/interpolate.js @@ -0,0 +1,36 @@ +import {asin, atan2, cos, degrees, haversin, radians, sin, sqrt} from "./math"; + +export default function(a, b) { + var x0 = a[0] * radians, + y0 = a[1] * radians, + x1 = b[0] * radians, + y1 = b[1] * radians, + cy0 = cos(y0), + sy0 = sin(y0), + cy1 = cos(y1), + sy1 = sin(y1), + kx0 = cy0 * cos(x0), + ky0 = cy0 * sin(x0), + kx1 = cy1 * cos(x1), + ky1 = cy1 * sin(x1), + d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))), + k = sin(d); + + var interpolate = d ? function(t) { + var B = sin(t *= d) / k, + A = sin(d - t) / k, + x = A * kx0 + B * kx1, + y = A * ky0 + B * ky1, + z = A * sy0 + B * sy1; + return [ + atan2(y, x) * degrees, + atan2(z, sqrt(x * x + y * y)) * degrees + ]; + } : function() { + return [x0 * degrees, y0 * degrees]; + }; + + interpolate.distance = d; + + return interpolate; +} |