チュートリアル | (トピック一覧へ戻る) |
パネル化アルゴリズム例その4![]()
![]()
![]()
![]()
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++) {
IVec pt1 = surf.pt(i*uinc, j*vinc);
IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);
double depth = 2.0;
IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);
IVec[][] cpts1 = new IVec[3][2];
cpts1[0][0] = pt1;
cpts1[1][0] = pt2;
cpts1[2][0] = pt3;
cpts1[0][1] = pt1d;
cpts1[1][1] = pt2d;
cpts1[2][1] = pt3d;
// u degree 2 (curve), v degree 1 (straight)
// true for closing surface in u direction
new ISurface(cpts1, 2, 1, true, false);
}
}
surf.del();
}
次のコードでは、ひとつのチューブ状のパネルは3つの曲面と一つの三角形で形成され、 突き出た部分の曲線上の辺と、下部の矩形の辺を曲面がつなぐ形になります。
![]()
![]()
![]()
![]()
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++) {
IVec pt1 = surf.pt(i*uinc, j*vinc);
IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);
double depth = -2.0;
IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);
IVec pt1m = pt1d.mid(pt2d);
IVec pt2m = pt2d.mid(pt3d);
IVec pt3m = pt3d.mid(pt1d);
// side surface 1
IVec[][] cpts2 = new IVec[3][2];
cpts2[0][0]=pt1;
cpts2[1][0]=pt1.mid(pt4);
cpts2[2][0]=pt4;
cpts2[0][1] = pt1m;
cpts2[1][1] = pt1d;
cpts2[2][1] = pt3m;
new ISurface(cpts2, 2, 1);
// side surface 2
IVec[][] cpts3 = new IVec[3][2];
cpts3[0][0] = pt3;
cpts3[1][0] = pt3.mid(pt2);
cpts3[2][0] = pt2;
cpts3[0][1] = pt2m;
cpts3[1][1] = pt2d;
cpts3[2][1] = pt1m;
new ISurface(cpts3, 2, 1);
// side surface 3
IVec[][] cpts4 = new IVec[3][2];
cpts4[0][0] = pt4;
cpts4[1][0] = pt4.mid(pt3);
cpts4[2][0] = pt3;
cpts4[0][1] = pt3m;
cpts4[1][1] = pt3d;
cpts4[2][1] = pt2m;
new ISurface(cpts4, 2, 1);
// side filling triangle
new ISurface(pt1m, pt2, pt1);
}
}
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++) {
for (int j=0; j < vnum; j++) {
IVec pt1 = surf.pt(i*uinc, j*vinc);
IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);
double depth = IRandom.get(-5,5);
double dratio = (depth+5)/10;
IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);
IVec pt1m = pt1d.mid(pt2d);
IVec pt2m = pt2d.mid(pt3d);
IVec pt3m = pt3d.mid(pt1d);
IVec[][] cpts2 = new IVec[3][2];
cpts2[0][0] = pt1;
cpts2[1][0] = pt1.mid(pt4);
cpts2[2][0] = pt4;
cpts2[0][1] = pt1m;
cpts2[1][1] = pt1d;
cpts2[2][1] = pt3m;
new ISurface(cpts2, 2, 1).clr(dratio/3+0.1,0.1,0.1);
IVec[][] cpts3 = new IVec[3][2];
cpts3[0][0] = pt3;
cpts3[1][0] = pt3.mid(pt2);
cpts3[2][0] = pt2;
cpts3[0][1] = pt2m;
cpts3[1][1] = pt2d;
cpts3[2][1] = pt1m;
new ISurface(cpts3, 2, 1).clr(dratio/3+0.1,0.1,0.1);
IVec[][] cpts4 = new IVec[3][2];
cpts4[0][0] = pt4;
cpts4[1][0] = pt4.mid(pt3);
cpts4[2][0] = pt3;
cpts4[0][1] = pt3m;
cpts4[1][1] = pt3d;
cpts4[2][1] = pt2m;
new ISurface(cpts4, 2, 1).clr(dratio/3+0.1,0.1,0.1);
new ISurface(pt1m, pt2, pt1).clr(dratio/3+0.1,0.1,0.1);
}
}
surf.del();
}
HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java /
Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT