-
Notifications
You must be signed in to change notification settings - Fork 201
/
foucautSinusoidal.js
49 lines (40 loc) · 1.15 KB
/
foucautSinusoidal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {geoProjectionMutator as projectionMutator} from "d3-geo";
import {cos, halfPi, pi, sin, sqrt} from "./math.js";
import {solve} from "./newton.js";
export function foucautSinusoidalRaw(alpha) {
var beta = 1 - alpha,
equatorial = raw(pi, 0)[0] - raw(-pi, 0)[0],
polar = raw(0, halfPi)[1] - raw(0, -halfPi)[1],
ratio = sqrt(2 * polar / equatorial);
function raw(lambda, phi) {
var cosphi = cos(phi),
sinphi = sin(phi);
return [
cosphi / (beta + alpha * cosphi) * lambda,
beta * phi + alpha * sinphi
];
}
function forward(lambda, phi) {
var p = raw(lambda, phi);
return [p[0] * ratio, p[1] / ratio];
}
function forwardMeridian(phi) {
return forward(0, phi)[1];
}
forward.invert = function(x, y) {
var phi = solve(forwardMeridian, y),
lambda = x / ratio * (alpha + beta / cos(phi));
return [lambda, phi];
};
return forward;
}
export default function() {
var alpha = 0.5,
m = projectionMutator(foucautSinusoidalRaw),
p = m(alpha);
p.alpha = function(_) {
return arguments.length ? m(alpha = +_) : alpha;
};
return p
.scale(168.725);
}