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.

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 8, vnum = 8;
double uinc = 1.0/unum, vinc = 1.0/vnum;

for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt11 = surf.pt( i*uinc, j*vinc );
IVec pt21 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt12 = surf.pt( i*uinc, (j+1)*vinc );
IVec pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc );
new 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.

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 8, vnum = 8;
double uinc = 1.0/unum, vinc = 1.0/vnum;

for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt11 = surf.pt( i*uinc, j*vinc );
IVec pt21 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt12 = surf.pt( i*uinc, (j+1)*vinc );
IVec pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc );
new ISurface(pt11, pt21, pt22).clr(i*uinc,0,j*vinc);
new 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.

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 8, vnum = 8;
double uinc = 1.0/unum, vinc = 1.0/vnum;

for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt11 = surf.pt( i*uinc, j*vinc );
IVec pt21 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt12 = surf.pt( i*uinc, (j+1)*vinc );
IVec pt22 = surf.pt( (i+1)*uinc, (j+1)*vinc );
new ISurface(pt11, pt21, pt12).clr(0,i*uinc,j*vinc);
new 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 ).

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 8, vnum = 8;
double uinc = 1.0/unum, vinc = 1.0/vnum;

for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
if( (i+j)%2 == 0 ){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, (j-1)*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
new ISurface(pt1, pt2, pt3).clr(0,i*uinc,j*vinc);
}
else{
IVec pt1 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt2 = surf.pt( i*uinc, (j+1)*vinc );
IVec pt3 = surf.pt( i*uinc, (j-1)*vinc );
new 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.

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();
for( ISurface surf : surfs ){

int unum = 8, vnum = 8;
double uinc = 1.0/unum, vinc = 1.0/vnum;
IVec pt1, pt2, pt3;
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
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 );
}
new 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 );
}
new 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 ).

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 10, vnum = 10;
double uinc = 1.0/unum, vinc = 1.0/vnum;

for(int i=0; i <= unum; i++){
for(int j=0; j < vnum; j++){
if( (i+j)%2 == 0 ){
IVec pt1 = surf.pt( (i-1)*uinc, j*vinc );
IVec pt2 = surf.pt( i*uinc, (j-1)*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
new 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.

```import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

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

ISurface[] surfs = IG.surfaces();

for( ISurface surf : surfs ){

int unum = 10, vnum = 10;
double uinc = 1.0/unum, vinc = 1.0/vnum;
IVec pt1, pt2, pt3, pt4;
for(int i=0; i <= unum; i++){
for(int j=0; j < vnum; j++){
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 );
}
new ISurface(pt1, pt2, pt3, pt4).clr(i*uinc,j*vinc,.5);
}
}
}
surf.del();
}
```

(back to the list of tutorials)