0

I want to simulate the 3D configuration of a real die. I know the sum of opposite faces equals 7 (top: 1 + bottom:6 = 7). Let's say the top face is 1, front is 5, right is 4, back is 2, left is 3 and bottom is 6, as this image suggests.

The real position matters for my code, so how do I randomize a die correctly? For example, if the randomized result top is 1 and the front is 5, then the right side has to be 4. It can't be 3, because in a real die, the 3 would be in the left. The program have to randomize 2 adjacent faces, the others must be placed according to the 2 randomized adjacent faces.

Pseudocode is just fine, but if you can explain me just with text, I appreciate it too.

xickoh
  • 304
  • 3
  • 10

1 Answers1

0

It's probably easiest to think in terms of the eight corners of the cube. Most of the time, there will be one corner closest to the viewer, and therefore the three faces around that corner will show. Occasionally two corners will be equally distant, so only two faces will show. Rarely (probably never if your viewing angle is not flat with the table) four corners will be equally distant and only one face will show.

Keep a pre-computed list indexed by cube vertex containing, for each, which three faces surround it, and which corner of each face. Then to roll, randomize the upper face, then randomize a rotation, and look up the faces in your table.

American dice have the ace, deuce, and trey clockwise around one corner with the line of the pips not pointing to that corner (so the pips kind of form a triangle around the corner). I don't know if the orientation of the six is standardized. Oriental dice are different.

Lee Daniel Crocker
  • 12,927
  • 3
  • 29
  • 55