Identifiying the next point on the surface of a cube ( or 3D object )

280 Views Asked by At

I have a cube of unit length. Each face of the cube is divided into 10 x 10 equal segments. Consider an object of size equal to that of a segment moving through the surface of the cube ( or any 3D object ).

I need to mathematically compute an equation through which I can get the next segment in the cube given the direction of the object.

EDIT:

I agree with the comments that this problem can be approached progammatically. I was looking for a way to do it in a generic way ( maybe like a parametric surface ) where you specify a domain (u, v) and a range of values (x,y,z) for a 3D Object.

An example would be like this - http://chimera.labs.oreilly.com/books/1234000001814/ch03.html#ch03_id36001767 . Can we define one such mathematical function for a cube?

To put in simple words, can a function be defined for the domain f(u, v) which will give a range of (x, y, z) values for a cube?

2

There are 2 best solutions below

0
On

The game of Snake in $3$D is really just a game of Snake in $2$D with slightly different boundary conditions on the box. One can unfold a cube like this. On the inner squares, the place that the snake will go next is obvious, it's the same as it would be for the $2$D case. However, at the edge squares of the cube, you'll just have to look at the sides and see which ones correspond to which; I've drawn some examples there for reference. This is for the case of a $2\times 2$ grid, but it should be easy to generalize to $10\times 10$.

0
On

I think this should really be moved to stack overflow. At any rate, as one of the commenters mentioned, how you do this really depends on how you store the position of the object. You could just store the coordinate position inside the object and increment the coordinate in the correct direction...