UNPKG

2.2 kBJavaScriptView Raw
1/*
2 * Icosahedral map
3 *
4 * Implemented for D3.js by Jason Davies (2013),
5 * Enrico Spinielli (2017) and Philippe Rivière (2017, 2018)
6 *
7 */
8import { atan, degrees } from "./math.js";
9import voronoi from "./polyhedral/voronoi.js";
10
11
12export default function() {
13 var theta = atan(0.5) * degrees;
14
15 // construction inspired by
16 // https://en.wikipedia.org/wiki/Regular_icosahedron#Spherical_coordinates
17 var vertices = [[0, 90], [0, -90]].concat(
18 [0,1,2,3,4,5,6,7,8,9].map(function(i) {
19 var phi = (i * 36 + 180) % 360 - 180;
20 return [phi, i & 1 ? theta : -theta];
21 })
22 );
23
24 // icosahedron
25 var polyhedron = [
26 [0, 3, 11],
27 [0, 5, 3],
28 [0, 7, 5],
29 [0, 9, 7],
30 [0, 11, 9], // North
31 [2, 11, 3],
32 [3, 4, 2],
33 [4, 3, 5],
34 [5, 6, 4],
35 [6, 5, 7],
36 [7, 8, 6],
37 [8, 7, 9],
38 [9, 10, 8],
39 [10, 9, 11],
40 [11, 2, 10], // Equator
41 [1, 2, 4],
42 [1, 4, 6],
43 [1, 6, 8],
44 [1, 8, 10],
45 [1, 10, 2] // South
46 ].map(function(face) {
47 return face.map(function(i) {
48 return vertices[i];
49 });
50 });
51
52 var polygons = {
53 type: "FeatureCollection",
54 features: polyhedron.map(function(face) {
55 face.push(face[0]);
56 return {
57 geometry: {
58 type: "Polygon",
59 coordinates: [ face ]
60 }
61 };
62 })
63 };
64
65var parents = [
66 // N
67 -1, // 0
68 7, // 1
69 9, // 2
70 11, // 3
71 13, // 4
72
73 // Eq
74 0, // 5
75 5, // 6
76 6, // 7
77 7, // 8
78 8, // 9
79
80 9, // 10
81 10, // 11
82 11, // 12
83 12, // 13
84 13, // 14
85
86 // S
87 6, // 15
88 8, // 16
89 10, // 17
90 12, // 18
91 14, // 19
92 ];
93
94 return voronoi()
95 .parents(parents)
96 .angle(0)
97 .polygons(polygons)
98 .rotate([108,0])
99 .scale(131.777)
100 .center([162, 0]);
101 }
102
103
104/*
105 // Jarke J. van Wijk, "Unfolding the Earth: Myriahedral Projections",
106 // The Cartographic Journal Vol. 45 No. 1 pp. 32–42 February 2008, fig. 8
107 // https://bl.ocks.org/espinielli/475f5fde42a5513ab7eba3f53033ea9e
108 d3.geoIcosahedral().parents([-1,0,1,11,3,0,7,1,7,8,9,10,11,12,13,6,8,10,19,15])
109 .angle(-60)
110 .rotate([-83.65929, 25.44458, -87.45184])
111*/
\No newline at end of file