2D array
From GeoMod
Many geoscience applications, particularly involving GIS, require working with 2-dimensional arrays. In this example we create a 2-D array of tiles.
from visual import *
from random import uniform
# define parameters
nx = 5
lx = 4.0
nz= 4
lz=4.0
# initialize variables
dx = lx/nx
dz= lz/nz
# create tiles (top left at 0,0,0)
tiles=[]
for i in range (nx):
for j in range (nz):
tiles.append(box(length=dx,
width=dz,
height=.5,
color=(uniform(0.5,1),0,0) ))
tiles[-1].pos.x = 0+i*dx
tiles[-1].pos.z = 0+j*dz
#print i,j, tiles[-1].pos
#translate tiles so center of grid is 0,0,0
for i in tiles:
i.pos.x=i.pos.x-(nx-1)*dx/2.0
i.pos.z=i.pos.z-(nz-1)*dz/2.0
print (nx-1)/2.0, (nz-1)/2.0, i.pos
#create axes
xaxis= cylinder(axis=(4,0,0), color=color.red, radius=.05)
yaxis= cylinder(axis=(0,4,0), color=color.blue, radius=.05)
zaxis= cylinder(axis=(0,0,4), color=color.yellow, radius=.05)
The tiles are first laid out with the top left tile at position (0,0,0),
the tiles are numbered from 0 to 19. We then translate the tiles to where we want them to be, centered at (0,0,0).
The final result looks like this:
- Here's a link about how to make a checkerboard set of tiles. A Chess Board.
- Lurbano 10:48, 22 Sep 2005 (CDT)
Great notes! Jianchen


