d3 / d3-geo-polygon

Clipping and geometric operations for spherical polygons.
https://d3.observablehq.cloud/d3-geo-polygon/
Other
113 stars 22 forks source link

deltoidal hexecontahedron projection #57

Closed bathoorn closed 5 months ago

bathoorn commented 5 months ago

Hi,

i created a deltoidal hexecontahedron projection which can be seen here.

https://observablehq.com/d/881a8431e638b408

would this be a welcome addition to the project? I based it on d3.geoPolyhedralVoronoi()

Fil commented 5 months ago

This is so beautiful! I tried to see if anyone had already made this projection before (in the history of map projections), and the only reference I found is … your recent printable: https://www.printables.com/fr/model/847944-deltoidal-hexecontahedron-star-map

bathoorn commented 5 months ago

thanks. i had a wonderful time playing with you code although i do net yet fully understand how it works.

Here i just took the icosahedron and created a centroid on the faces and subdivided every face in 3 new ones. Below code produces this projection. If you like it, maybe we can add it to the repo.

deltoidal_f = {
    var degrees = 180 / Math.PI;
    var theta = Math.atan(0.5) * degrees;

  // construction inspired by
  // https://en.wikipedia.org/wiki/Regular_icosahedron#Spherical_coordinates
  var vertices = [[0, 90], [0, -90]].concat(
    [0,1,2,3,4,5,6,7,8,9].map(function(i) {
      var phi = (i * 36 + 180) % 360 - 180;
      return [phi, i & 1 ? theta : -theta];
    })
  );

  // icosahedron
  var polyhedron = [
    [0, 3, 11],
    [0, 5, 3],
    [0, 7, 5],
    [0, 9, 7],
    [0, 11, 9], // North
    [2, 11, 3],
    [3, 4, 2],
    [4, 3, 5],
    [5, 6, 4],
    [6, 5, 7],
    [7, 8, 6],
    [8, 7, 9],
    [9, 10, 8],
    [10, 9, 11],
    [11, 2, 10], // Equator
    [1, 2, 4],
    [1, 4, 6],
    [1, 6, 8],
    [1, 8, 10],
    [1, 10, 2] // South
  ].map(function(face) {
    var t = face.map(function(i) {
      return vertices[i];
    });
    // create 3 polygons from these using centroid and midpoints
    var f1 = [
      t[0], 
      d3.geoInterpolate(t[0],t[1])(0.5), 
      d3.geoCentroid({type:"MultiPoint", coordinates:t}), 
      d3.geoInterpolate(t[0],t[2])(0.5)
    ];
    var f2 = [
      t[1], 
      d3.geoInterpolate(t[1],t[2])(0.5), 
      d3.geoCentroid({type:"MultiPoint", coordinates:t}), 
      d3.geoInterpolate(t[1],t[0])(0.5)
    ];
    var f3 = [
      t[2], 
      d3.geoInterpolate(t[2],t[0])(0.5), 
      d3.geoCentroid({type:"MultiPoint", coordinates:t}), 
      d3.geoInterpolate(t[2],t[1])(0.5)
    ];
    return [f1, f2, f3];
  });

  var polygons = {
    type: "FeatureCollection",
    features: polyhedron.flat().map(function(face) {
      face.push(face[0]);
      return {
        properties: { sitecoordinates: d3.geoCentroid({type:"MultiPoint", coordinates: face}) },
        geometry: {
          type: "Polygon",
          coordinates: [ face ]
        }
      };
    })
  };

var parents = [
      -1, // 0
      2, // 1
      0, // 2
      5, // 3
      5, // 4
      22, // 5
      8, // 6
      8, // 7
      28, // 8
      11, // 9
      11, // 10
      34, // 11
      14, // 12
      14, // 13
      40, // 14
      16, // 15
      2, // 16
      16, // 17
      17, // 18
      18, // 19
      18, // 20
      19, // 21
      21, // 22
      21, // 23
      23, // 24
      24, // 25
      24, // 26
      25, // 27
      27, // 28
      27, // 29
      29, // 30
      30, // 31
      30, // 32
      31, // 33
      33, // 34
      33, // 35
      35, // 36
      36, // 37
      36, // 38
      37, // 39
      39, // 40
      39, // 41
      41, // 42
      42, // 43
      42, // 44
      46, // 45
      20, // 46
      46, // 47
      49, // 48
      26, // 49
      49, // 50
      52, // 51
      32, // 52
      52, // 53
      55, // 54
      38, // 55
      55, // 56
      58, // 57
      44, // 58
      58, // 59
    ];

  //return polygons;
  return d3.geoPolyhedralVoronoi()
   .parents(parents)
   .angle(0)
   .polygons(polygons)
   .rotate([108,0])
   .scale(131.777)
   .center([162, 0]);
};
Fil commented 5 months ago

I absolutely love it! Yes let's add that to the repo, as well as #58

bathoorn commented 5 months ago

shall i create a merge request later tonight?

Fil commented 5 months ago

Sure! I'll also want to spend a bit more time reviewing the current code base… besides this bug, it has aged a bit. Not sure when I'll find time to do that though. Possibly next week.

bathoorn commented 5 months ago

i had some time in my lunch break so i already created a pull request. Then you can have a look when you get to it. For now with the workaround i can already use it. Maybe i will laser cut an rhombic dodecahedron star map then as well.