Background
A 3D cube has 12
edges and 8
corners.
Corner indexing
8
corners are already indexed 0
to 7
.
7---------6
/| /|
/ | / |
4---------5 |
| | | |
| 3------|--2
| / | /
|/ |/
0---------1
Edge indexing
11
edges are already indexed from 0
to 11
.
// These are the corner pairs for the edges:
var mcPairTable = [12][2]int{
{0, 1}, // Edge 0
{1, 2}, // Edge 1
{2, 3}, // Edge 2
{3, 0}, // Edge 3
{4, 5}, // Edge 4
{5, 6}, // Edge 5
{6, 7}, // Edge 6
{7, 4}, // Edge 7
{0, 4}, // Edge 8
{1, 5}, // Edge 9
{2, 6}, // Edge 10
{3, 7}, // Edge 11
}
Combining two index numberings
I want to draw tetrahedra inside the 3D cube. To describe a tetrahedra, I can use the indices of edges and corners. For example, a tetrahedron would consist of Corner 0
, Edge 0
, Edge 3
, and Edge 8
.
Problem
My problem is index numbering. I don't know how to combine the index of edges with those of corners. I have two options for index numbering.
Option 1: string
One option is to use strings to compose a tetrahedron. For example I use the C
prefix for corner indices and the E
prefix for edge indices:
var tehtrahedron = [4]string{"C0", "E0", "E3", "E8"}
But working with strings is not as easy as simple integer indices.
Option 2: shifting indices
The other option is to keep the index from 0
to 11
for edges, but shift the index for corners. So, corners would be indexed from 0+12
to 7+12
i.e. from 12
to 19
. Using this option, the same tetrahedron would be like:
var tehtrahedron = [4]int{0+12, 0, 3, 8}
Or:
var tehtrahedron = [4]int{12, 0, 3, 8}
But this option would mess up the rest of my code and would make my code hard to read.
Notes
- A tetrahedron doesn't consist of
1
corner and3
edges all the time. The combination is arbitrary. But the total count of corners and edges is always4
. - The order of indices for tetrahedron matters.
Question
Is there a convenient way to keep the original index numbering for edges and corners? And at the same time be able to represent the tetrahedra by index of edges and corners?
Looking for some ideas...