d3-geo-polygon
Version:
Clipping and geometric operations for spherical polygons.
89 lines (81 loc) • 1.75 kB
JavaScript
/*
* Rhombic Dodecahedron map
*
* Implemented for D3.js by Ronnie Bathoorn (2024)
* based on Cubic map by Enrico Spinielli (2017) and Philippe Rivière (2017, 2018)
*
*/
import { atan, degrees } from "./math.js";
import voronoi from "./polyhedral/voronoi.js";
import { geoCentroid } from "d3-geo";
export default function () {
const phi1 = atan(Math.SQRT1_2) * degrees;
const vertices = [
[], // 0
[], // 1
[], // 2
[], // 3
[-90, phi1], // 4
[], // 5
[], // 6
[-135, 0], // 7
[-45, 0], // 8
[], // 9
[], // 10
[], // 11
[-90, -phi1], // 12
[], // 13
];
// rhombic dodecahedron
const polyhedron = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
].map((face) => face.map((i) => vertices[i]));
const polygons = {
type: "FeatureCollection",
features: polyhedron.map((face) => ({
type: "Feature",
properties: {
sitecoordinates: geoCentroid({
type: "MultiPoint",
coordinates: face,
}),
},
geometry: {
type: "Polygon",
coordinates: [[...face, face[0]]],
},
}))
};
const parents = [
-1, // 0
0, // 1
6, // 2
2, // 3
1, // 4
9, // 5
11, // 6
3, // 7
4, // 8
8, // 9
5, // 10
10, // 11
];
return voronoi()
.polygons(polygons)
.parents(parents)
.angle(20)
.rotate([80, 0, -Math.asin(Math.sqrt(3) / 3) * 90])
.translate([213, 252])
.scale(106.48)
}