I am working on a cube/tesseract visualization project and I need help with programmatically finding the faces/sides of a cube/tesseract.
For both n=3 and n=4 I would like a face to be 4 connected vertices, for example:
face[0] = [0, 1, 3, 2]
6 of them for n=3 and 48 for n=4.
Is there an algorithm for finding the faces of an n-dimensional cube?
The vertices are generated by the following code:
function generateVertices() {
const numDimensions = parseInt(document.getElementById('numDimensions').value);
const numVertices = Math.pow(2, numDimensions);
const vertices = [];
for (let i = 0; i < numVertices; i++) {
const vertex = [];
for (let j = 0; j < numDimensions; j++) {
const coord = (i & (1 << j)) === 0 ? 1 : -1;
vertex.push(coord);
}
vertices.push(vertex);
}
console.clear();
console.log(`Number of vertices: ${vertices.length}`);
for (let i = 0; i < vertices.length; i++) {
console.log(`[${vertices[i].join(', ')}]`);
}
}
<label for="numDimensions">Number of dimensions:</label>
<input type="number" id="numDimensions" value="3">
<button onclick="generateVertices()">Generate Vertices</button>