d3 / d3-geo-polygon

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

Tried adding parents to TetrahedralLee #70

Closed bathoorn closed 4 months ago

bathoorn commented 4 months ago

Hi,

i made some changes to TetrahedralLee so i can add parents and it also supports setting the root of the tree in other places than faces[0]. I added it to my fork here if you want to see.

Here are some images created whith the snapshot unittests

tetra1 tetra2 tetra3 tetra4

i also tried generating svg's but that is not working flawless yet.

bathoorn commented 4 months ago

And the code of the snapshots

export async function tetra1() {
  return renderWorld(
    geoTetrahedralLee()
      .parents([-1, 3, 1, 2])
      .rotate([115, -54.735610317245346, 90])
      .precision(0.1)
      .fitSize([width, height], { type: "Sphere" })
  );
}

export async function tetra2() {
  return renderWorld(
    geoTetrahedralLee()
      .parents([2, -1, 3, 0])
      .angle(90)
      .rotate([115, -54.735610317245346, 90])
      .precision(0.1)
      .fitSize([width, height], { type: "Sphere" })
  );
}

export async function tetra3() {
  return renderWorld(
    geoTetrahedralLee()
      .parents([3, 0, -1, 1])
      .angle(-30)
      .rotate([115, -54.735610317245346, 90])
      .precision(0.1)
      .fitSize([width, height], { type: "Sphere" })
  );
}

export async function tetra4() {
  return renderWorld(
    geoTetrahedralLee()
      .parents([1, 2, 0, -1])
      .angle(210)
      .rotate([115, -54.735610317245346, 90])
      .precision(0.1)
      .fitSize([width, height], { type: "Sphere" })
  );
}
Fil commented 4 months ago

Are you generating an isolated face? I believe you can solve this with leeRaw directly—without having to go through the polyhedral transform.

However, I do understand adding a parents method if the goal is to detach a side triangle and reattach it to another side, like so:

 ▲
△▽△    =>    △▽△▼
bathoorn commented 4 months ago

Yes i was trying to get isolated faces so i can get them in the laser cutter easier. For most of the other polyhedrons this worked but tetrahedralLee did not support the parents. This indeed also allows different cofigurations which might save on wood when cutting.

I will see if i can also get this to work with leeRaw.

bathoorn commented 4 months ago

that is a nice one recreating it with the voronoi function.

bathoorn commented 4 months ago

works great!

I got some little artifacts in the red lines but that is something i do myself using geoInterpolate to draw all the edges of all the faces.

image
Fil commented 4 months ago

Yes, the raw projection is quite unstable at this vertex — you can use a straight line connecting the projected vertices rather than line interpolation.

bathoorn commented 4 months ago

this is what i used it for :)

IMG20240630155425 IMG20240630155439