What is the radius of a polyhedron ? (PolyhedronGeometry)

Hello,

I want to reproduce this animation with three.js:

gfycat

So I need some tetrahedra. I saw the PolyhedronGeometry which allows to set vertices, but there is a parameter radius. What is it? A polyhedron is entirely defined by its vertices and its faces so I don’t see what is the radius. Is it a scaling?

If this is not adapted I’ll use a BufferGeometry to do the tetrahedra.

Ỳ̶̺ḙ̷̎ś̴̱.

1 Like

I’ve been able to reproduce the picture except the tetrahedra (i.e. I got the edges fine).

I do:

......
    // an empty tetrahedron
    const fourVertices = [
      0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0
    ];
    const faces = [
      2, 1, 0,
      0, 3, 2,
      1, 3, 0,
      2, 3, 1
    ];
    let cell = new THREE.PolyhedronGeometry(fourVertices, faces);
    cell.setAttribute(
      "position",
      new THREE.Float32BufferAttribute(fourVertices, 3)
    );

......

and:

......
    for(let i = 0; i < ntetrahedra; i++) {
      let mesh = new THREE.Mesh(cell, cellMaterial);
      mesh.geometry.attributes.position.needsUpdate = true;
      Meshes_tetrahedra[i] = mesh;
      group.add(mesh);
    }
......

and in the animate function:

......
    for(let t = 0; t < ntetrahedra; t++) {
      let mesh = Meshes_tetrahedra[t];
      let tetrahedron = tetrahedra[t];
      let cellVertices = new Array(0);
      for(let i = 0; i < 4; i++) {
        let vi = vertices3d[tetrahedron[i]];
        cellVertices.push(vi.x, vi.y, vi.z);
      }
      mesh.geometry.setAttribute(
        "position", new THREE.Float32BufferAttribute(cellVertices, 3)
      );
      mesh.geometry.computeBoundingBox();
      mesh.geometry.computeBoundingSphere();
    }

Only one face of one tetrahedron appears. What am I missing?

I think I have to update the vertices, not the position. But how to do that?

I finally switched to BufferGeometry, it works now.

Here is the result.

1 Like

yes, the idea of PolyhedronGeometry is to help you, but in your case it seems like it was in the way, so there’s no reason to stick with it then