How to generate an ordered list of vertices of a cube from a face and a normal vector

2.5k Views Asked by At

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:

Axes

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:

{1,0,0},
{1,1,0},
{1,1,1},
{1,0,1},

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

{0,0,0},
{0,0,1},
{0,1,1},
{0,1,0},

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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$.