forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotation.js
More file actions
72 lines (61 loc) · 2.18 KB
/
Copy pathrotation.js
File metadata and controls
72 lines (61 loc) · 2.18 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import "../math/trigonometry";
import "equirectangular";
import "geo";
d3.geo.rotation = function(rotate) {
rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
function forward(coordinates) {
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
}
forward.invert = function(coordinates) {
coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
};
return forward;
};
// Note: |δλ| must be < 2π
function d3_geo_rotation(δλ, δφ, δγ) {
return δλ ? (δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ))
: d3_geo_rotationλ(δλ))
: (δφ || δγ ? d3_geo_rotationφγ(δφ, δγ)
: d3_geo_equirectangular);
}
function d3_geo_forwardRotationλ(δλ) {
return function(λ, φ) {
return λ += δλ, [λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ];
};
}
function d3_geo_rotationλ(δλ) {
var rotation = d3_geo_forwardRotationλ(δλ);
rotation.invert = d3_geo_forwardRotationλ(-δλ);
return rotation;
}
function d3_geo_rotationφγ(δφ, δγ) {
var cosδφ = Math.cos(δφ),
sinδφ = Math.sin(δφ),
cosδγ = Math.cos(δγ),
sinδγ = Math.sin(δγ);
function rotation(λ, φ) {
var cosφ = Math.cos(φ),
x = Math.cos(λ) * cosφ,
y = Math.sin(λ) * cosφ,
z = Math.sin(φ),
k = z * cosδφ + x * sinδφ;
return [
Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ),
Math.asin(Math.max(-1, Math.min(1, k * cosδγ + y * sinδγ)))
];
}
rotation.invert = function(λ, φ) {
var cosφ = Math.cos(φ),
x = Math.cos(λ) * cosφ,
y = Math.sin(λ) * cosφ,
z = Math.sin(φ),
k = z * cosδγ - y * sinδγ;
return [
Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ),
Math.asin(Math.max(-1, Math.min(1, k * cosδφ - x * sinδφ)))
];
};
return rotation;
}