Consider a cube with faces we'll call "left", "right", "front", "back", "top" and "bottom".

The cube can be described by $0 \le x,y,z \le 1$.

To name the faces, we'll say $x$ extends to the right, $y$ to the top and $z$ forward:


Given a face/plane (for example, $x=1$ or $y=0$), I want to generate an ordered list of vertices of that face, such that they proceed counter-clockwise around the face of the cube if you were to look at the cube -- that is from some point outside $(0,1)$.

For example, one such ordering for the right face ($x=1$) would be:


while one such ordering for the left face($x=0$) would be:


Note that in the first ordering, we go from $(y,z) = (0,0)$ to $(1,0)$.
While in the second we go from $(y,z) = (0,0)$ to $(0,1)$.
This is because of the counter-clockwise restriction.

I'm fairly certain I can somehow use the normal of the face (in the above case <1,0,0>) to compute these, and I'm thinking it has something to do with a cross product somewhere, but after that I'm lost.

Any guidance would be greatly appreciated. Thanks in advance.


Cross-product is, indeed, the key. I'll assume that the cube is $[-1,1]^3$ rather than $[0,1]^3$ (replacing $-1$'s by $0$'s in the final answer shouldn't be an insurmountable programming challenge) If $e$ is the unit vector in the direction of your face (say $(0,-1,0)$) and $v$ is any vertex on that face (say, $(-1,-1,1$), then the next vertex in the counterclockwise order is given by $e+e\times v$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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