home processing download documents tutorial python tutorial gallery source about
 チュートリアル (トピック一覧へ戻る)

パネル化アルゴリズム例

     パネル化アルゴリズム例その3

この例ではねじれた曲面パネルを曲面上に生成します。 ねじれた曲面パネルは、曲面生成のための制御点の一部を回転することによって生成されます。
以下が例に用いられる入力ファイルです。

surface4.3dm

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

size(480,360,IG.GL);

IG.open("surface4.3dm");
ISurface[] surfaces = IG.surfaces();

for(ISurface surf : surfaces){
  
  int unum = 20, vnum=20;
  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[][] pts = new IVec[2][4];
        
        pts[0][0] = surf.pt( i*uinc, j*vinc );
        pts[1][0] = surf.pt( (i+1)*uinc, j*vinc );
        pts[0][1] = surf.pt( i*uinc, (j+2.0/3)*vinc );
        pts[1][1] = surf.pt( (i+1)*uinc, (j+2.0/3)*vinc );
        pts[0][2] = surf.pt( i*uinc, (j+4.0/3)*vinc );
        pts[1][2] = surf.pt( (i+1)*uinc, (j+4.0/3)*vinc );
        pts[0][3] = surf.pt( i*uinc, (j+2)*vinc );
        pts[1][3] = surf.pt( (i+1)*uinc, (j+2)*vinc );
        
        IVec rotAxis = pts[1][3].dif(pts[1][2]);
        
        // rotating around the center pts[1][2] and the axis rotAxis
        pts[0][2].rot(pts[1][2],rotAxis,-PI/2);
        // rotating around the center pts[1][3] and the axis rotAxis
        pts[0][3].rot(pts[1][3],rotAxis,-PI/2);
         
        new ISurface(pts, 1, 3);
      }       
    }
  }
  surf.del();  
}

次に以下のコードでは回転角度が乱数によってランダム化されます。

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

size(480,360,IG.GL);

IG.open("surface4.3dm");
ISurface[] surfaces = IG.surfaces();

for(ISurface surf : surfaces){
  
  int unum = 20, vnum=20;
  double uinc = 1.0/unum, vinc = 1.0/vnum;
  for(int i=0; i < unum; i++){
    double maxAngle = IRandom.get(0, PI*2/3);
    for(int j=0; j < vnum; j++){
      if( (i+j)%2== 0 ){
        
        IVec[][] pts = new IVec[2][4];
        
        pts[0][0] = surf.pt( i*uinc, j*vinc );
        pts[1][0] = surf.pt( (i+1)*uinc, j*vinc );
        pts[0][1] = surf.pt( i*uinc, (j+2.0/3)*vinc );
        pts[1][1] = surf.pt( (i+1)*uinc, (j+2.0/3)*vinc );
        pts[0][2] = surf.pt( i*uinc, (j+4.0/3)*vinc );
        pts[1][2] = surf.pt( (i+1)*uinc, (j+4.0/3)*vinc );
        pts[0][3] = surf.pt( i*uinc, (j+2)*vinc );
        pts[1][3] = surf.pt( (i+1)*uinc, (j+2)*vinc );
        
        IVec rotAxis = pts[1][3].dif(pts[1][2]);
        
        // rotating around the center pts[1][2] and the axis rotAxis
        pts[0][2].rot(pts[1][2],rotAxis,-maxAngle*j*vinc);
        // rotating around the center pts[1][3] and the axis rotAxis
        pts[0][3].rot(pts[1][3],rotAxis,-maxAngle*j*vinc);
         
        new ISurface(pts, 1, 3).clr(0,maxAngle/PI,0);
      }       
    }
  }
  surf.del();
}


(トピック一覧へ戻る))

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT