Python Tutorials (back to the list of tutorials)

## Simple Panelization

### Rectangular Panelization

You can panelize a surface with rectangular surfaces with simple for loop like the following.

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj")  #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 8
vnum = 8
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum) :
for j in range(vnum) :
pt11 = surf.pt( i*uinc, j*vinc )
pt21 = surf.pt( (i+1)*uinc, j*vinc )
pt12 = surf.pt( i*uinc, (j+1)*vinc )
pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc )
ISurface(pt11, pt21, pt22, pt12).clr(i*uinc,j*vinc,0)
surf.del()
```

### Triangulation

The simplest way to triangulate a surface is to put two triangles at the rectangular area dividing it at the diagonal line.

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 8
vnum = 8
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum) :
for j in range(vnum) :
pt11 = surf.pt( i*uinc, j*vinc )
pt21 = surf.pt( (i+1)*uinc, j*vinc )
pt12 = surf.pt( i*uinc, (j+1)*vinc )
pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc )
ISurface(pt11, pt21, pt22).clr(i*uinc,0,j*vinc)
ISurface(pt22, pt12, pt11).clr(1-i*uinc)
surf.del()
```

You can alternate the diagonal line by changing the sequence of points to create triangular surfaces.

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 8
vnum = 8
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum) :
for j in range(vnum) :
pt11 = surf.pt( i*uinc, j*vinc )
pt21 = surf.pt( (i+1)*uinc, j*vinc )
pt12 = surf.pt( i*uinc, (j+1)*vinc )
pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc )
ISurface(pt11, pt21, pt12).clr(0,i*uinc,j*vinc)
ISurface(pt12, pt21, pt22).clr(1-i*uinc)
surf.del()
```

### Diagrid Triangulation

Another way to triangulate a surface is to apply the diagrid logic using the if condition if( (i+j)%2 == 0 ).

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 8
vnum = 8
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum) :
for j in range(vnum) :
if (i+j)%2 == 0 :
pt1 = surf.pt( i*uinc, j*vinc )
pt2 = surf.pt( (i+1)*uinc, (j-1)*vinc )
pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc )
ISurface(pt1, pt2, pt3).clr(0,i*uinc,j*vinc)
else :
pt1 = surf.pt( (i+1)*uinc, j*vinc )
pt2 = surf.pt( i*uinc, (j+1)*vinc )
pt3 = surf.pt( i*uinc, (j-1)*vinc )
ISurface(pt1, pt2, pt3).clr(1-i*uinc)
surf.del()
```

To have clear edge and corner condition to fill the original rectangular area of the input surface, you use if conditions to create filling geometries at the corners and the edges.

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()
for surf in surfs :
unum = 8
vnum = 8
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum) :
for j in range(vnum) :
if (i+j)%2 == 0 :
pt1 = surf.pt( i*uinc, j*vinc )
if j > 0 :
pt2 = surf.pt( (i+1)*uinc, (j-1)*vinc )
else :
pt2 = surf.pt( (i+1)*uinc, j*vinc )
if j < vnum-1 :
pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc )
else :
pt3 = surf.pt( (i+1)*uinc, j*vinc )
ISurface(pt1, pt2, pt3).clr(1,i*uinc,j*vinc)
else :
pt1 = surf.pt( (i+1)*uinc, j*vinc )
if j < vnum-1 :
pt2 = surf.pt( i*uinc, (j+1)*vinc )
else :
pt2 = surf.pt( i*uinc, j*vinc )
if j > 0 :
pt3 = surf.pt( i*uinc, (j-1)*vinc )
else :
pt3 = surf.pt( i*uinc, j*vinc )
ISurface(pt1, pt2, pt3).clr(1-i*uinc)
surf.del()
```

### Diamond Panelization

You can create diamond panels using the diagrid logic with the if condition of if( (i+j)%2 == 0 ).

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 10
vnum = 10
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum+1) :
for j in range(vnum) :
if (i+j)%2 == 0 :
pt1 = surf.pt( (i-1)*uinc, j*vinc )
pt2 = surf.pt( i*uinc, (j-1)*vinc )
pt3 = surf.pt( (i+1)*uinc, j*vinc )
pt4 = surf.pt( i*uinc, (j+1)*vinc )
ISurface(pt1, pt2, pt3, pt4).clr(.5,i*uinc,j*vinc)
surf.del()
```

To have rectangular corners and edges, you use if conditions to create filling triangular surfaces.

```add_library('igeo')

size( 480, 360, IG.GL )

#IG.open("surface1.3dm")  #input geometry from 3dm file
IG.open("surface1.obj") #input geometry from OBJ file

surfs = IG.surfaces()

for surf in surfs :
unum = 10
vnum = 10
uinc = 1.0/unum
vinc = 1.0/vnum
for i in range(unum+1) :
for j in range(vnum) :
if (i+j)%2 == 0 :
if i > 0 :
pt1 = surf.pt( (i-1)*uinc, j*vinc )
else :
pt1 = surf.pt( i*uinc, j*vinc )
if i < unum :
pt3 = surf.pt( (i+1)*uinc, j*vinc )
else :
pt3 = surf.pt( i*uinc, j*vinc )
if j > 0 :
pt2 = surf.pt( i*uinc, (j-1)*vinc )
else :
pt2 = surf.pt( i*uinc, j*vinc )
if j< vnum-1 :
pt4 = surf.pt( i*uinc, (j+1)*vinc )
else :
pt4 = surf.pt( i*uinc, j*vinc )
ISurface(pt1, pt2, pt3, pt4).clr(i*uinc,j*vinc,.5)
surf.del()
```

(back to the list of tutorials)