# New Year, new tools – OpenScad Tetrahedron

**Posted:**January 2, 2016

**Filed under:**3D Modeling, 3D Models, OpenScad Tutorial, Uncategorized |

**Tags:**openscad, platonic solid, tetrahedron 1 Comment

I fired up OpenScad, and created a new tetrahedron model using it. I’ve done tons with platonic solids in OpenScad in the past. This time around though, I figured I’d create the simplest tetrahedron I know. Here’s the OpenScad code for the same:

hull(){ translate([0,0,0]) sphere(4); translate([100,100,0]) sphere(4); translate([0, 100, 100]) sphere(4); translate([100, 0, 100]) sphere(4); }

The trick here is in the fact of the special relationship between a tetrahedron and a cube. The cube has 8 vertices, and you can create a tetrahedron by using 4 of those vertices. You just have to pick the right ones. You can easily choose the right ones by picking a set at opposite corners of any face (cutting a diagonal across that face). Then, choose the face exactly opposite, and select the two corners that are different from the ones you picked on the first face. Now you have these 4 vertices.

OpenScad has had the ‘hull()’ module since forever, but it didn’t always work so well. In this modern OpenScad, and for this particular case, it works extremely well. Just take the 4 vertices, throw them into a hull(), and out comes a nice tetrahedron!

This is the tetrahedron for the masses. No math required, except to know the vertices of a unit cube. And of course you can scale it up to any size you please.

If you want to do anything tricky with it though, like subtract some holes and the like, you’ll have to know the math again. But, there you have it, tetrahedron solid in a few lines of OpenScad.

For all who care about 3D printing. For having a nice stand, you can rotate the tetrahedron around (1,1,0) by ArcCos(1/\sqrt(3)), which translates to:

//variables

radius = 2.;

edgeLength = 100.;

$fn = 30;

// build tetrahedron by corners of cube

//

rotate(a=54.7356,v=1/sqrt(2)*[1.,1.,0])

hull(){

translate(edgeLength/sqrt(2)*[0,0,0]) sphere(r=radius);

translate(edgeLength/sqrt(2)*[1,1,0]) sphere(r=radius);

translate(edgeLength/sqrt(2)*[1,0,1]) sphere(r=radius);

translate(edgeLength/sqrt(2)*[0,1,1]) sphere(r=radius);

};