Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a computer code to mesh a N-dimensional space with N-dimensional hypercubes and do some physics in it. I am wondering if I can produce a generic code (with C++ templates, but that is not the subject here) that is ok for N = 2, 3, 4...

My question is about the extraction of the N-M dimensionnal faces of the cubes. These faces are N-M dimensionnal hypercubes in a N dimensionnal space (for exemple the faces of a 3-dimensional hypercubes (a cube) are 2-dimensional hypercubes (squares) in a 3-dimensional space).

Is there a generic way to define the data I need to characterize these N-M faces (different from storing all their vertexes).

To illustrate that here is a example in N=3 dimensions :

  • For the N=3 cube I need at least : a center (3 coordinates) + the side length (1 number)
  • For its N-1=2 dimensional faces (faces) I need at least: a center (3 coordinates) + the side length (1 number) + the plane normal vector (3 coordinates)
  • For its N-2=1 dimensional faces (edges) I need at least : the coordinates of the two points (6 coordinates)
  • For its N-3 = 0 dimensional faces (vertexes) I need a least : 3 coordinates

This way to define the faces is very heterogeneous and not generic at all. What is the most optimal (from a memory point of view) generic way to define a N-M hypercube face in a N dimensional space ?

Thank you very much.

share|cite|improve this question
up vote 2 down vote accepted

The $n-m$ dimensional faces of the $n$-dimensional unit cube are obtained by fixing $m$ of the coordinates each to a fixed value that is either $0$ or $1$. So you need to record an $m$-subset of $[n]$ (your favourite $n$-set), together with a bitvector of size $m$, holding the chosen coordinates (so there are $\binom nm2^m$ such faces). I'll leave it to you to figure out how to parameterise size and position of a scaled, translated copy of the unit cube. If you just want to record the face without associating it to a particular parent $n$-cube, then you must record the $m$-set of coordinates you want to fix, the $m$ coordinate values you want to fix them to, and for the $n-m$ coordinates that vary their minimal value (the maximal value is $1$ more than that, or $\textit{size}$ more if the size is variable).

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.