Thread: 3d array of cubes?

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    20

    3d array of cubes?

    Is this possible?

    What I want to do is have a large cube composed of 27 smaller cubes (3 x 3 x 3, the same as a Rubik's cube). I want the cube to be fixed, so logically we would only see it from one angle (so we only need to be concerned with 3 sides of the cube). I want to have a string be on each showing face of the smaller cubes.

    Essentially the question I'm interested in is: can I have a 3d array of cubes? And by cubes, I mean actual cubes which have 6 faces.

    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It is certainly possible to physically construct the same. You can model it however you want.

    If you just want a static image, then some sort of image editor is probably what you want. Even if you want things that move, you probably want modeling software unless you are planning to tie it into a C project.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    One of the beautiful things about programming, is that the computer becomes your universe. If you can imagine it, and define it in some concrete way, (and have the system resources of course), then you can do it. (may be some exceptions to this, but I can't think of any atm).

    3D arrays are no problem: myArray[1D][2D][3D]. Which I visualize as rows, columns, and which sheet of paper from the stack of papers - for you, it would be different, I'm sure.

    I have run across a program that creates hundreds of dimensions to try and solve a sudoku program, etc., so it's very possible. Be aware that 3D arrays can eat up a good deal of memory, so you do have to watch that, but your needs should be small, anyway.

    Enjoy!

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    cube of cube, something like this would do:
    Code:
     
    typedef int small_cube[3][3][3];
    small_cube large_cube[3][3][3];
    "All that we see or seem
    Is but a dream within a dream." - Poe

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    20
    @tabstop

    I actually don't want graphics (I should of stated that), at least not yet. I just want to have the logical representation in my code. The goal is to be able to put the strings together to form words.

    @nimitzhunter

    That sounds pretty good, I'll give it a try

    Quote Originally Posted by Adak View Post
    One of the beautiful things about programming, is that the computer becomes your universe. If you can imagine it, and define it in some concrete way, (and have the system resources of course), then you can do it. (may be some exceptions to this, but I can't think of any atm).

    3D arrays are no problem: myArray[1D][2D][3D]. Which I visualize as rows, columns, and which sheet of paper from the stack of papers - for you, it would be different, I'm sure.

    I have run across a program that creates hundreds of dimensions to try and solve a sudoku program, etc., so it's very possible. Be aware that 3D arrays can eat up a good deal of memory, so you do have to watch that, but your needs should be small, anyway.

    Enjoy!
    Thanks!
    Last edited by porstart; 01-09-2011 at 07:53 PM.

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    20
    Quote Originally Posted by nimitzhunter View Post
    cube of cube, something like this would do:
    Code:
     
    typedef int small_cube[3][3][3];
    small_cube large_cube[3][3][3];
    How would I assign values into large_cube[3][3][3]?

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You wouldn't. Array indexes in C go from zero to the dimension - 1.

    However, for valid indices you might do;
    Code:
    large_cube a_big_one;
    small_cube a_small_one;
    
    /*   place a value into one of the elements of a_small_one  */
    
    a_small_one[2][2][2] = 42;
    
    a_big_one[1][1][1]  = a_small_one;  /*  note this copies the elements of a_small_one into a_big_one[1][1][1]  */
    
    a_big_one[1][1][1][2][2][2]  = 42;   /*   This sets the same element to 42 as would be set by the previous assignment  */
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing 3D array to a linked list.
    By satty in forum C Programming
    Replies: 8
    Last Post: 08-21-2010, 09:36 AM
  2. how to pass a 2d array to a 3d array
    By satty in forum C Programming
    Replies: 3
    Last Post: 08-18-2010, 05:13 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. 3D array
    By GSLR in forum C Programming
    Replies: 2
    Last Post: 05-12-2002, 04:00 PM
  5. 3D Array
    By Alextrons in forum Windows Programming
    Replies: 4
    Last Post: 01-11-2002, 01:39 AM