Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Method for rotating data points in 3 dimensions

  1. Apr 8, 2010 #1
    My best guess is this fits in algebra, I've been scratching my head with this for a while.

    I have a three dimensional array representing points of certain objects in a game.

    int [5,5,5] currentLocs

    I want to be able to rotate these 3d points around the center in any direction by 90 degrees. So like taking a dice and turning from side to side.

    In doing it on paper I've noticed that often there's a pattern of finding the difference between the current position in relation to one of the axis not being rotated around and the max value of that axis, but nothing that applies to all points and all rotations.

    I want to rotate either direction around any of the three axis and know where each data point should be within the three dimensional array afterwards.


    three objects stored as a column with one in a corner in a 3D array
    y=2 y=1 y=0
    100 000 000
    010 010 010
    000 000 000

    rotated around the X axis would become a horizontal line with the corner object moving to another corner
    y=2 y=1 y=0
    000 010 100
    000 010 000
    000 010 000

    Any ideas? Most rotation stuff I find involves rotating based on the orientation of a center point and doing matrix multiplication. This works great for rotating a model and what not, but I haven't figured out a way to apply this to my desired technique that can be applied to any cubic odd numbered 3D array. Surely there's some simple proof as to how each coordinate moves to another as the grid rotates.

  2. jcsd
  3. Apr 9, 2010 #2
    So these are voxels? Then it would be misleading to say that they represents points of certain objects in a game. If you truly had an array representing points in a game your array would probably look more like:
    int [10,3] currentLocs;
    for 10 objects in 3-dimensional space. If this is really what you wanted, then just calculate the rotation matrix for rotation around the appropriate axis (see http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations").

    If you really wanted the voxel-based data structure (in which case you should use a much larger array than 5x5x5), then the basic idea is that if you want to do a w rad rotation around some axis you just calculate the appropriate rotation matrix, but instead calculate it for a rotation of -w. Then if you apply it to a point (x,y,z) you find from which voxel that point comes from, and therefore what value to assign to it.

    I wouldn't mind providing some more details if you could expand on exactly how your data is represented (are 0 and 1 for instance the only permissible values), and what you're having trouble with.
    Last edited by a moderator: Apr 25, 2017
  4. Apr 9, 2010 #3
    Essentially I have a 5x5x5 grid, either 0 (there is nothing) or 1 (there is a block) present. I want to rotate where these blocks are around the center grid point, and this is all stored in the array as mentioned. Every rotation is 90 degrees, hence why I mention moving from side to side or rolling dice. So if I have a block at x,y,z in the array, I want to know how to find the NEW x,y,z based on rotating any of the six possible directions. (clockwise or counter clockwise around each axis). I hope this clarified what I'm trying to do. Like a rubix cube, if I rotate it, I need to know where to move the colors, but not just on the outer walls, also internally in each grip point withe the exception of the center which of course will not move.
  5. Apr 11, 2010 #4
    Here are some matrix transformations that will rotate the elements 90 degrees.
    For a clockwise rotation:

    [tex]B = A^{T}
    \[ \left[ \begin{array}{ccc}
    0 & 0 & 1 \\\
    0 & 1 & 0 \\\
    1 & 0 & 0 \end{array} \right]\][/tex]

    For a counter clockwise rotation:

    [tex]\medspace B = \[ \left[ \begin{array}{ccc}
    0 & 0 & 1 \\\
    0 & 1 & 0 \\\
    1 & 0 & 0 \end{array} \right]A^{T}[/tex]

    You can extend this to higher dimensions.

    For a 5x5x5 array, you could define 3 axis of rotation i,j,k. A rotation around a line through the center of the array and parallel to the k-axis would need a rotation for each of the five layers of 5x5 matricies ( k = 1,2,...,5 ). Similarily for the rotations around the lines through the center and parallel to the i and j axies.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook