1
\$\begingroup\$

I'm currently generating tetrahedron meshes in Unity

Mesh

When a player clicks the side of a mesh, a new one spawns aligned with it, like this.

Alignment

I'm not sure how nor can I find any information on implementing a tetra hedron grid. I tried playing around with the vertices until I realized I need to adjust position & rotation. Any ideas?

EDIT: To be clear, the second image was manually placed objects in the Unity Editor. I'm looking to make an algorithm that places the meshes correctly.

\$\endgroup\$
4
  • \$\begingroup\$ Exactly what part are you having a problem with? Is it creating an algorithm to position the new vertices, or something else? \$\endgroup\$ Aug 19, 2014 at 19:17
  • \$\begingroup\$ The second picture was me manually placing the object there, so creating an algorithm to place it. \$\endgroup\$ Aug 19, 2014 at 19:27
  • \$\begingroup\$ Just for info: there is no such thing as a tetrahedron grid. Normal 3-space can't be filled densely by regular tetrahedrons. \$\endgroup\$
    – cobbal
    Aug 21, 2014 at 15:10
  • \$\begingroup\$ @cobbal yep, learned that the hard way... For some reason I figured you could because you can tile triangles in 2D. \$\endgroup\$ Aug 21, 2014 at 19:36

1 Answer 1

3
\$\begingroup\$

Three vertices are easy. Just place them in the same location as the three vertices of the clicked face. For the rest of this answer, we'll call these vertices v1, v2, and v3.

To position the 4th vertex, first take the cross product of v1 → v2 and v1→ v3. (If this returns a vector pointing backward, just swap v2 and v3.)

vUp = normalize(cross(v2 - v1, v3 - v1))

Then average the position of the three vertices.

vBaseCenter = (v1 + v2 + v3) / 3

Add these together and you have the 4th vertex position. If the height of this shape is 1, you can remove tetrahedronHeight from this equation.

v4 = vUp * tetrahedronHeight + vBaseCenter

Finally, to get that gap between the tetrahedrons, just move all four vertices a small amount in the direction of vUp.

v1 += vUp * gapSize
v2 += vUp * gapSize
v3 += vUp * gapSize
v4 += vUp * gapSize

This isn't the only solution. The alternative is creating a new copy of an already existing tetrahedron model and positioning that. I do think this method is easier, though.

\$\endgroup\$
1
  • \$\begingroup\$ Mostly works from this solution, playing around with it now. Thanks! \$\endgroup\$ Aug 19, 2014 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .