# Create hundreds of complex geometric shapes with cubes, triangles and tetrahedra

I'm going to investigate the marching cubes algorithm. For that, I have to draw and keep track of `256` - actually `128` due to symmetry - geometric configurations like below. I should be able to assign index/ID to nodes and edges.

# Question

Drawing and keeping track of all the `128` configurations by hand is a daunting task.

What are the best desktop or mobile applications to help me do that? One application in my mind is FreeCAD. But I haven't tried it yet. I'm not sure.

I prefer applications which can be run on Linux. I'm using openSUSE Leap.

# Update

The development is being done here that looks promising: https://github.com/Megidd/tetrahedron-table

One program meeting your Linux requirement is OpenSCAD, which is three dimensional modeling software using text based code.

If your abilities extend to creating such code, you'll find that OpenSCAD supports vectors, arrays, loops, conditionals, etc. in such a manner to facilitate repetitive creation.

As I am not conversant with the information contained in the link regarding marching cubes, I cannot be confident that this is a certain solution.

OpenSCAD primarily creates STL files which are triangular surfaces and may negate your objective. Alternatively, one can define polygons and polyhedral solids by specifying points in three-space. These points can be created in the code in the form of lists and defined as such for easier management.

The shaded/colored areas in your image appear to be triangles of this sort, hence my suggestion.

This OpenSCAD script breaks down a cube into 6 tetrahedra.

This helped: https://cs.stackexchange.com/a/90011/67985

This might be an indication that OpenSCAD might be useful for investigating complex geometric shapes.

``````// Define the size of the cube
size = 50;

// Define the transparency of the tetrahedra
alpha = 0.5;

// Define the colors of the tetrahedra
colors = [
[1, 0, 0, alpha],  // red
[0, 1, 0, alpha],  // green
[0, 0, 1, alpha],  // blue
[1, 1, 0, alpha],  // yellow
[1, 0, 1, alpha],  // magenta
[0, 1, 1, alpha]   // cyan
];

// Define the vertices of the cube
cube_vertices = [
[0, 0, 0],
[size, 0, 0],
[size, size, 0],
[0, size, 0],
[0, 0, size],
[size, 0, size],
[size, size, size],
[0, size, size]
];

tetrahedron_indices = [
[0, 4, 7, 6],
[0, 3, 7, 6],
[0, 4, 5, 6],
[0, 1, 5, 6],
[0, 3, 2, 6],
[0, 1, 2, 6],
];

// Define the tetrahedra by selecting vertices from the cube
for (i = [0:5]) {
// Define the indices of the vertices for the tetrahedron
vertex_indices = tetrahedron_indices[i];

echo("Tetrahedron ", i, ": ", vertex_indices);

// Define the vertices of the tetrahedron
tetrahedron_vertices = [
cube_vertices[vertex_indices[0]],
cube_vertices[vertex_indices[1]],
cube_vertices[vertex_indices[2]],
cube_vertices[vertex_indices[3]]
];

// Color the tetrahedron with the specified color
color(colors[i]) polyhedron(points=tetrahedron_vertices, faces=[[0, 1, 2], [0, 2, 3], [0, 3, 1], [1, 2, 3]]);
}
``````