Python Tutorials (back to the list of tutorials)

## Creating Geometry with Arrays

### Creating Curves with Arrays

With an array of IVec, you can create ICurve easily.

```add_library('igeo')

size( 480, 360, IG.GL )

cpts1 = []

cpts1.append(IVec(-30, 10, 0))
cpts1.append(IVec(-10, 10, 0))
cpts1.append(IVec(-10, 30, 0))
cpts1.append(IVec(-30, 30, 0))
# curve 1 (red)
ICurve(cpts1, 3).clr(1.,0,0)

cpts2 = []
for i in range(10) :
if i%2==0 :
cpts2.append(IVec(i*10, 0, 0))
else :
cpts2.append(IVec(i*10, 10, 0))
# curve 2 (blue)
ICurve(cpts2, 1).clr(0,0,1.)

cpts3 = []
for i in range(16) :
if i%4==0 :
cpts3.append(IVec(-30, -10, i*5))
elif i%4==1 :
cpts3.append(IVec(-10, -10, i*5))
elif i%4==2 :
cpts3.append(IVec(-10, -30, i*5))
else :
cpts3.append(IVec(-30, -30, i*5)) # same with i%4==3
# curve 3 (cyan)
ICurve(cpts3, 3).clr(0,1.,1.)
```

### Creating Surfaces with Arrays

2 dimensional array of IVec is convenient to create ISurface.

```add_library('igeo')

size( 480, 360, IG.GL )

cpts1 = []
cpts1.append([])
cpts1[0].append(IVec( 0, 0, 0))
cpts1[0].append(IVec( 0,-30, 0))
cpts1.append([])
cpts1[1].append(IVec(-30, 0, 0))
cpts1[1].append(IVec(-30,-30, 0))
# surface 1 (gray)
ISurface(cpts1)

cpts2 = []
for i in range(10) :
cpts2.append([])
if i%2==0 :
cpts2[i].append(IVec(i*10,0,0))
cpts2[i].append(IVec(i*10,0,20))
else :
cpts2[i].append(IVec(i*10,-10,0))
cpts2[i].append(IVec(i*10,10,10))
# surface 2 (purple)
ISurface(cpts2).clr(.5,0,1)

cpts3 = []
for i in range(4) :
cpts3.append([])
for j in range(4) :
if (i==0 or i==3) and (j==1 or j==2) :
cpts3[i].append(IVec(-i*10, j*10, 20))
else :
cpts3[i].append(IVec(-i*10, j*10, 0))
# surface 3 (pink)
ISurface(cpts3,3,3).clr(1,.5,1)
```

### Creating Polygon Mesh with Arrays

One of ways to create a polygon mesh is to provide a matrix of IVec in 2 dimensional array.

```add_library('igeo')

size( 480, 360, IG.GL )

cpts1 = []

for i in range(10) :
cpts1.append([])
for j in range(10) :
if (i+j)%2==0 :
cpts1[i].append(IVec(i*5, -j*5-30, (i+j)*2))
else :
cpts1[i].append(IVec(i*5, -j*5-30, (i+j-1)*2))
# mesh 1 (cyan)
IMesh(cpts1).clr(0,1.,1.)

divNum=30
cpts2 = []
for i in range(10) :
cpts2.append([])
for j in range(divNum+1) :