Print a cube's vertices and its covering triangles
CJam, 35 bytes
YZm*`3{[XY4]m<)\0+_:+1$f-+_@f+W%}%`
Try it online
The output is:
[[0 0 0] [0 0 1] [0 1 0] [0 1 1] [1 0 0] [1 0 1] [1 1 0] [1 1 1]][[1 2 0 2 1 3] [7 5 6 4 6 5] [2 4 0 4 2 6] [7 3 5 1 5 3] [4 1 0 1 4 5] [7 6 3 2 3 6]]
Triangle orientation is clockwise from the outside. I checked this manually, and it looks correct to me.
Explanation:
YZ Push 2 and 3 on stack.
m* Cartesian power, creates the coordinates of the 8 vertices.
` Convert to string for output. Done with vertices.
3{ Start loop over 3 coordinate directions.
[XY4] Push [1 2 4], which are the vertex index offsets for the 3 directions.
m< Rotate by loop counter. So the remaining loop body will be executed once
with [1 2 4], once with [2 4 1], once with [4 1 2].
) Pop off last offset. Will use this as index offset between the two
parallel faces.
\ Swap pair of remaining two offsets to top. These are the index offsets
within the face.
0+ Add a 0 to the list. These 3 indices define the first triangle.
_:+ Calculate the sum. This is the vertex index of the opposite corner.
1$ Copy first triangle to the top.
f- Subtract all indices from the index of the opposite corner, producing
the second triangle of the face.
+ Concatenate the indices of the two triangles, resulting in a list with
the 6 vertex indices for the face.
_ Copy the list.
@ Bring the offset between the two faces to the top.
f+ Add the offset to each index in the copied list.
W% Revert the order, resulting in the properly oriented list of the 6 vertex
indices for the parallel face.
}% End of loop over 3 coordinate directions.
` Convert to string for output. Done with triangles.