home processing download documents tutorial python tutorial gallery source about
 Tutorials (back to the list of tutorials)

Panelization Examples

     Panelization Example2

The following example shows rectangular panelization with gaps and subdivision techniques of orthogonal grid.
The sample input file used in the example is below.

surface3.3dm

First, the code below shows rectangular panelization with gaps.

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

size(480,360,IG.GL);

IG.open("surface3.3dm");
ISurface[] surfs = IG.surfaces();
ISurface surf = surfs[0];

int unum = 10;
int vnum = 20;
double uinc = 1./unum;
double vinc = 1./vnum;

// gap ratio between rectangular panel
double gap = 0.25;

for(int i=0; i < unum; i++){
  for(int j=0; j < vnum; j++){
    
    IVec pt1 = surf.pt(i*uinc, j*vinc);
    IVec pt2 = surf.pt((i+1-gap)*uinc, j*vinc);
    IVec pt3 = surf.pt((i+1-gap)*uinc, (j+1-gap)*vinc);
    IVec pt4 = surf.pt(i*uinc, (j+1-gap)*vinc);

    new ISurface(pt1,pt2,pt3,pt4);
  }
}
surf.del();

Next, the code below shows the use of IBox providing 8 points as corners of the box.

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

size(480,360,IG.GL);

IG.open("surface3.3dm");
ISurface[] surfs = IG.surfaces();
ISurface surf = surfs[0];

int unum = 20;
int vnum = 40;
double uinc = 1./unum;
double vinc = 1./vnum;
double gap = 0.25;

for(int i=0; i < unum; i++){
  for(int j=0; j < vnum; j++){
    
    IVec pt1 = surf.pt(i*uinc, j*vinc);
    IVec pt2 = surf.pt((i+1-gap)*uinc, j*vinc);
    IVec pt3 = surf.pt((i+1-gap)*uinc, (j+1-gap)*vinc);
    IVec pt4 = surf.pt(i*uinc, (j+1-gap)*vinc);

    // bottom points
    IVec bpt1 = pt1.dup();
    IVec bpt2 = pt2.dup();
    IVec bpt3 = pt3.dup();
    IVec bpt4 = pt4.dup();

    // move bottom points to xy-plane
    bpt1.z=0;
    bpt2.z=0;
    bpt3.z=0;
    bpt4.z=0;

    // create a box randomly 
    if(IRandom.percent(80)){
      new IBox(pt1,pt2,pt3,pt4,bpt1,bpt2,bpt3,bpt4).clr(1-j*vinc);
    }
  }
}
surf.del();

Finally, extra for loops for the subdivision inside existing for loops with random number.

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

size(480,360,IG.GL);

IG.open("surface3.3dm");
ISurface[] surfs = IG.surfaces();
ISurface surf = surfs[0];

int unum = 20;
int vnum = 40;
double uinc = 1./unum;
double vinc = 1./vnum;
double gap = 0.15;

for(int i=0; i < unum; i++){
  for(int j=0; j < vnum; j++){

    // random subdivision
    int udiv=IRandom.getInt(1,2);
    int vdiv=IRandom.getInt(1,4);
    double uinc2 = 1./udiv;
    double vinc2 = 1./vdiv;
    
    for(int k=0; k < udiv; k++){
      for(int l=0; l < vdiv; l++){
    
        IVec pt1 = surf.pt((i + k*uinc2)*uinc,
                           (j + l*vinc2)*vinc);
        IVec pt2 = surf.pt((i+(k+1)*uinc2-gap )*uinc,
                           (j + l*vinc2)*vinc);
        IVec pt3 = surf.pt((i+(k+1)*uinc2-gap)*uinc,
                           (j+(l+1)*vinc2-gap)*vinc);
        IVec pt4 = surf.pt((i+k*uinc2)*uinc,
                           (j+(l+1)*vinc2-gap)*vinc);

        // bottom points
        IVec bpt1 = pt1.dup();
        IVec bpt2 = pt2.dup();
        IVec bpt3 = pt3.dup();
        IVec bpt4 = pt4.dup();

	// move bottom points to xy-plane
        bpt1.z=0;
        bpt2.z=0;
        bpt3.z=0;
        bpt4.z=0;

	// lower the top randomly 
        if(IRandom.percent(20)){
          pt1.z -= 3;
          pt2.z -= 3;
          pt3.z -= 3;
          pt4.z -= 3;
        }

	// create a box randomly 
        if(IRandom.percent(80)){
          new IBox(pt1,pt2,pt3,pt4,bpt1,bpt2,bpt3,bpt4).clr(IRandom.gray());
        }
      }
    }
  }
}
surf.del();


Back to Tutorials

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS
GALLERY
SOURCE CODE(GitHub)
ABOUT