Results 1 to 8 of 8

Thread: converting multidimensional arrays

  1. #1

    Thread Starter
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124

    converting multidimensional arrays

    ok, now that i have my question about defining multidimensional arrays, how do i convert them. i really just want to know how to convert a 3d array into 2d, as well as a 2d array into a 1d. (im not going to bother converting 3d to 1d, b/c that would be too long of an array when i would rather deal with it in 2d)

    example

    2d to 1d
    VB Code:
    1. dim MyArray(2,2)
    2. dim MyOneDArray(8)
    3. MyOneDArray(0) = MyArray(0,0)
    4. MyOneDArray(1) = MyArray(1,0)
    5. MyOneDArray(2) = MyArray(2,0)
    6. MyOneDArray(3) = MyArray(0,1)
    7. MyOneDArray(4) = MyArray(1,1)
    8. MyOneDArray(5) = MyArray(2,1)
    9. MyOneDArray(6) = MyArray(0,2)
    10. MyOneDArray(7) = MyArray(1,2)
    11. MyOneDArray(8) = MyArray(2,2)

    but, ya know, i want to work with a much larger array conversion, and id dont want to have to type all that out...
    Last edited by Liquid Pennies; Jul 14th, 2002 at 07:50 PM.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    what happens when you convert 2d to 1d
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124
    i updated my post and gave an example, look at that B/P

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What would you expect to happen here:
    VB Code:
    1. MyOneDArray(0) = MyArray(0,0)
    2. MyOneDArray(0) = MyArray(2,2)

    As you have it you'd be overwriting the (0,0) value with the (2,2) one. Are they numbers to be added? Strings to be appended? What?

  5. #5
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    VB Code:
    1. Dim MyArray(2,2)
    2. Dim MyOneDArray(8)
    3. Dim i as Long, j as Long, ctr As Long
    4.  
    5. For i = 0 To UBound(MyArray, 1)
    6.     For j = 0 To UBound(MyArray, 2)
    7.         MyOneDArray(ctr) = MyArray(i, j)
    8.         ctr = ctr + 1
    9.     Next
    10. Next


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  6. #6

    Thread Starter
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124
    i fixed my typo

    and thanks microbasic, but id also like to conver 3d to 2d...how would you do that...?
    Last edited by Liquid Pennies; Jul 14th, 2002 at 08:09 PM.

  7. #7
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    There are too many ways to split 3D into 2...can't help you there. For example, a 3x5x9 arrray can be converted into a 27x5 array, a 15x9 array, a 3x45 array, a 9x15 array, a 45x3 aray, or a 5x27 array.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  8. #8

    Thread Starter
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124
    really, all im trying to figure out, is i want to make a 3d, wireframe cube in a picturebox and i want to increment the x and z coordinates of each point and decrement the y coordnate so that the cube moves. ya know?

    really, i just want to know howd you convert your 3d coordanites to 2d coordanites so that i can display them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width