|
Last change
on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
914 bytes
|
| Line | |
|---|
| 1 | import {asin, atan2, cos, degrees, haversin, radians, sin, sqrt} from "./math.js";
|
|---|
| 2 |
|
|---|
| 3 | export default function(a, b) {
|
|---|
| 4 | var x0 = a[0] * radians,
|
|---|
| 5 | y0 = a[1] * radians,
|
|---|
| 6 | x1 = b[0] * radians,
|
|---|
| 7 | y1 = b[1] * radians,
|
|---|
| 8 | cy0 = cos(y0),
|
|---|
| 9 | sy0 = sin(y0),
|
|---|
| 10 | cy1 = cos(y1),
|
|---|
| 11 | sy1 = sin(y1),
|
|---|
| 12 | kx0 = cy0 * cos(x0),
|
|---|
| 13 | ky0 = cy0 * sin(x0),
|
|---|
| 14 | kx1 = cy1 * cos(x1),
|
|---|
| 15 | ky1 = cy1 * sin(x1),
|
|---|
| 16 | d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
|
|---|
| 17 | k = sin(d);
|
|---|
| 18 |
|
|---|
| 19 | var interpolate = d ? function(t) {
|
|---|
| 20 | var B = sin(t *= d) / k,
|
|---|
| 21 | A = sin(d - t) / k,
|
|---|
| 22 | x = A * kx0 + B * kx1,
|
|---|
| 23 | y = A * ky0 + B * ky1,
|
|---|
| 24 | z = A * sy0 + B * sy1;
|
|---|
| 25 | return [
|
|---|
| 26 | atan2(y, x) * degrees,
|
|---|
| 27 | atan2(z, sqrt(x * x + y * y)) * degrees
|
|---|
| 28 | ];
|
|---|
| 29 | } : function() {
|
|---|
| 30 | return [x0 * degrees, y0 * degrees];
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | interpolate.distance = d;
|
|---|
| 34 |
|
|---|
| 35 | return interpolate;
|
|---|
| 36 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.