4
$\begingroup$

I am working on a game program. I have an array of 8 points in 3d space $(X,Y,Z)$ that are the 8 corners of a cube whose $W=H=D$. The 8 points are listed in no particular order. For the sake of determining this algorithm, The cube's center is at the world origin, $(0,0,0)$ but the cube's orientation is not aligned with the Cartesian axis (it's arbitrarily rotated). I'd like to create 6 sets of $4$ points each that represent the faces of the cube but I'm stumped as to how to proceed

Any idea of an algorithm that would help me?

1 Answers 1

6

Pick a point $p$, calculate the distance from that point to all the others, three will be the same length and smaller than the other lengths. Call these three points $x_1$, $x_2$, $x_3$. Do the same for $x_1$, $x_2$, $x_3$. Each pair of those will share two points, one will be $p$ the other will be $y_{12}$, $y_{13}$, $y_{23}$ respectively. You just defined three sides by points. Now, pick the only remaining point that hasn't been named. Call it $q$. Run the above algorithm. Done.

  • 0
    @Rahul, yes you are correct, nice adaption for a slightly harder case.2010-10-28