I have a four dimensional array which I am trying to flatten into a single
dimension array:

Dim Array4D(10,10,10,10) as Single

I can create my one dimensional array to be big enough to contain teh data
from the 4D array:

Dim Array2D(Array4D.Length - 1) As Single

Then I populate it like so:

Dim intArray2dIndex As Integer
For t As Integer = 0 To Array4D.GetUpperBound(0)
For x As Integer = 0 To Array4D.GetUpperBound(1)
For y As Integer = 0 To Array4D.GetUpperBound(2)
For z As Integer = 0 To Array4D.GetUpperBound(3)
Array2D(intArray2dIndex) = Array4D(t, x, y, z)
intArray2dIndex += 1
Next
Next
Next
Next

But once I have my 1D array how do I retrieve a value from it using the
original t,x,y,z values? In other words, given a t, x, z and y value that
would describe a position in the 4D array I need to translate that to a
single value that describes the position in the one dimensional array.

Any help on this one?

TIA

Re: Converting a 4D array to a 1D array and addressing it by Robin

Robin
Fri Jun 24 10:13:48 CDT 2005

Just out of interest, if you are trying to represent homogenous coordinates,
why not create a single Vertex class and have an array of Vertices?

public class Vertex

public x, y, z, t as single

end class

Dim myArray(1) as Vertex

for each theVertex as Vertex in myArray
theVertex.x = 10.0
next


"elziko" <elziko@yahoo.co.uk> wrote in message
news:OAFRkxMeFHA.3032@TK2MSFTNGP10.phx.gbl...
>I have a four dimensional array which I am trying to flatten into a single
> dimension array:
>
> Dim Array4D(10,10,10,10) as Single
>
> I can create my one dimensional array to be big enough to contain teh data
> from the 4D array:
>
> Dim Array2D(Array4D.Length - 1) As Single
>
> Then I populate it like so:
>
> Dim intArray2dIndex As Integer
> For t As Integer = 0 To Array4D.GetUpperBound(0)
> For x As Integer = 0 To Array4D.GetUpperBound(1)
> For y As Integer = 0 To Array4D.GetUpperBound(2)
> For z As Integer = 0 To Array4D.GetUpperBound(3)
> Array2D(intArray2dIndex) = Array4D(t, x, y, z)
> intArray2dIndex += 1
> Next
> Next
> Next
> Next
>
> But once I have my 1D array how do I retrieve a value from it using the
> original t,x,y,z values? In other words, given a t, x, z and y value that
> would describe a position in the 4D array I need to translate that to a
> single value that describes the position in the one dimensional array.
>
> Any help on this one?
>
> TIA
>



Re: Converting a 4D array to a 1D array and addressing it by rossum

rossum
Fri Jun 24 16:25:28 CDT 2005

On Fri, 24 Jun 2005 15:52:47 +0100, "elziko" <elziko@yahoo.co.uk>
wrote:

>I have a four dimensional array which I am trying to flatten into a single
>dimension array:
>
>Dim Array4D(10,10,10,10) as Single
>
>I can create my one dimensional array to be big enough to contain teh data
>from the 4D array:
>
>Dim Array2D(Array4D.Length - 1) As Single
>
>Then I populate it like so:
>
>Dim intArray2dIndex As Integer
>For t As Integer = 0 To Array4D.GetUpperBound(0)
> For x As Integer = 0 To Array4D.GetUpperBound(1)
> For y As Integer = 0 To Array4D.GetUpperBound(2)
> For z As Integer = 0 To Array4D.GetUpperBound(3)
> Array2D(intArray2dIndex) = Array4D(t, x, y, z)
> intArray2dIndex += 1
> Next
> Next
> Next
>Next
>
>But once I have my 1D array how do I retrieve a value from it using the
>original t,x,y,z values? In other words, given a t, x, z and y value that
>would describe a position in the 4D array I need to translate that to a
>single value that describes the position in the one dimensional array.
>
>Any help on this one?
>
>TIA
>

First work out out on paper how you would flatten a 2D array into a 1D
array, and how you would retrieve the array entries given the two
indices. Program your solution and test it.

Next do the same for flattening a 3D array. Test your solution so you
are sure that it works.

After doing that you should be in a position to solve your problem
with a 4D array.

rossum





The ultimate truth is that there is no ultimate truth

Re: Converting a 4D array to a 1D array and addressing it by Jason

Jason
Sat Jun 25 06:55:59 CDT 2005

A simplified piece of code would be:

offset1 = Array4D.GetUpperBound(1) * Array4D.GetUpperBound(2) * _
Array4D.GetUpperBound(3)
offset2 = Array4D.GetUpperBound(2) * Array4D.GetUpperBound(3)
offset3 = Array4D.GetUpperBound(3)

Each element would be at

value = Array2D((t*offset1) + (x*offset2) +(y*offset3) + z)

Cheers,
Jason

On Fri, 24 Jun 2005 15:52:47 +0100, elziko wrote:

> I have a four dimensional array which I am trying to flatten into a single
> dimension array:
>
> Dim Array4D(10,10,10,10) as Single
>
> I can create my one dimensional array to be big enough to contain teh data
> from the 4D array:
>
> Dim Array2D(Array4D.Length - 1) As Single
>
> Then I populate it like so:
>
> Dim intArray2dIndex As Integer
> For t As Integer = 0 To Array4D.GetUpperBound(0)
> For x As Integer = 0 To Array4D.GetUpperBound(1)
> For y As Integer = 0 To Array4D.GetUpperBound(2)
> For z As Integer = 0 To Array4D.GetUpperBound(3)
> Array2D(intArray2dIndex) = Array4D(t, x, y, z)
> intArray2dIndex += 1
> Next
> Next
> Next
> Next
>
> But once I have my 1D array how do I retrieve a value from it using the
> original t,x,y,z values? In other words, given a t, x, z and y value that
> would describe a position in the 4D array I need to translate that to a
> single value that describes the position in the one dimensional array.
>
> Any help on this one?
>
> TIA

Re: Converting a 4D array to a 1D array and addressing it by elziko

elziko
Mon Jun 27 03:11:51 CDT 2005

> Just out of interest, if you are trying to represent homogenous
> coordinates, why not create a single Vertex class and have an array of
> Vertices?

I cannot do this because I am writing to a propriety file format using a 3rd
party DLL requiring me to start with a 1D array of singles.