## Position item in an array larger than 3D

General FreeBASIC programming questions.
lrcvs
Posts: 569
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

To: Tourist Trap

Position 999 =
blo = 1 row = 10 col = 9 niv = 10

:::::::::::::::::::::::::::::::::::

row = 4
col = 8
level = 2

Position = 138
lrcvs
Posts: 569
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, dodicat:

I'm glad to talk to you again!

dodicat:

24300000 Size of one dimensional array
position required = 21000000
Element 26 28 24 10 30

26*28 = 728 = block
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

lrcvs:

blo = 778 row = 10 col = 30 niv = 24
lrcvs
Posts: 569
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

To dodicat:

What method would you use to get the 5 dimensional co-ordinates
of a given position in the single dimension equivalent array.?

Well, now I do not go into mathematical calculations ...
... But I approach it / I guess as follows:

I have a transparent cube, if type a sphere inside the cube, points (coordinates with integer values) of the sphere, will be within the cube.

In the above example, the vertices (X, Y, Z) of a cube, could be transformed into a value of a position, as showed in the previous example.

If we use the same principle to the field, should work the same, that's my idea, I hope not wrong too.!
lrcvs
Posts: 569
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

To dodicat and fxm:

Both methods are correct.
The important thing is that you can demonstrate that position occupies one element in an array / block / dim ...
lrcvs
Posts: 569
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

My work is more secillo, less showy, but it is also correct.

Calculate position:

Code: Select all

`clsinput "Filas del bloque unidad = ";ro 'rows block unityinput "Columnas del bloque unidad = ";co 'cols block unityinput "Niveles del bloque unidad = ";le 'levels block unityprintinput "Posicion Fila = ";a 'position rowinput "Posicion Columna = ";b 'positiion colinput "Posicion Nivel = ";c 'position levelinput "Numero de Bloque = ";d 'position number blockP = ((a - 1) * co) + b + ((ro * co * (c - 1))) + ((ro * co * le) * (d-1))'positionprint "Position = ";psleepend:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Calculate Dim/block/array..., col, level,rowdim as integer c,co,d,f,h,k,l,p,rclsinput "Numero de filas del bloque unidad (filas <= columnas)  = ";  rinput "Numero de columnas del bloque unidad (columnas >= filas)  = ";cinput "Numero de niveles del bloque unidad =  ";linput "Posicion a buscar = ";ph = l'calculate blockif  p mod  (r*c*l)  <> 0 thend =  int(p/(r*c*l))+1elsed = int(p/(r*c*l))end if':::::::::::::::::::::::::::::::::print "bloque = ";d'calculate  levell =  (int(p/(r*c))+1)if p  mod (r*c)  =  0  then l  =  l-1k = l-((d-1)*h)':::::::::::::::::::::::::::::::::'print "Nivel_1 = ";lprint "Nivel_2 = ";k'calculate colif p  <  c then co = pif p  >= c  then  co =  p mod  cif  p mod c = 0 then  co = c  ':::::::::::::::::::::::::::::::::print "Columna = ";co'calculate rowf =  ((p-co-((r*c)*(l-1)))/c)+1':::::::::::::::::::::::::::::::::print "Fila = ";fprintcolor  12print  "blo = ";d;" fil = ";f; " col = ";co; " niv = ";ksleep end`