シェルピンスキー

 投稿者:しばっち  投稿日:2011年 8月14日(日)23時34分19秒
  INPUT  PROMPT "LEVEL=":N
LET L=500
FILE GETSAVENAME F$,"dxfファイル|*.dxf"
IF F$="" THEN STOP
IF RIGHT$(F$,1)="!" THEN LET F$=F$(1:LEN(F$)-1) & "シェルピンスキー" & STR$(N)
IF POS(UCASE$(F$),".DXF")=0 THEN LET F$=F$ & ".dxf"
OPEN #1:NAME F$
ERASE #1
PRINT #1:"0"
PRINT #1:"SECTION"
PRINT #1:"2"
PRINT #1:"ENTITIES"
CALL SIERPINSKI(N,0,0,0,L,#1)
PRINT #1:"0"
PRINT #1:"ENDSEC"
PRINT #1:"0"
PRINT #1:"EOF"
CLOSE #1
END

EXTERNAL  SUB SIERPINSKI(N,X,Y,Z,L,#1)
IF N=0 THEN
   CALL OBJ(#1,X,Y,Z,L)
ELSE
   CALL SIERPINSKI(N-1,X,Y,Z,L/2,#1)
   CALL SIERPINSKI(N-1,X+L/2,Y,Z,L/2,#1)
   CALL SIERPINSKI(N-1,X-L/2,Y,Z,L/2,#1)
   CALL SIERPINSKI(N-1,X,Y+L/2,Z,L/2,#1)
   CALL SIERPINSKI(N-1,X,Y-L/2,Z,L/2,#1)
   CALL SIERPINSKI(N-1,X,Y,Z+L/2,L/2,#1)
   CALL SIERPINSKI(N-1,X,Y,Z-L/2,L/2,#1)
END IF
END SUB

EXTERNAL  SUB OCTAHEDRON(#1,X,Y,Z,XL,YL,ZL) !'8面体
LET X0=X
LET Y0=Y+YL/2
LET Z0=Z
LET X1=X+XL/2
LET Y1=Y
LET Z1=Z
LET X2=X
LET Y2=Y
LET Z2=Z+ZL/2
LET X3=X-XL/2
LET Y3=Y
LET Z3=Z
LET X4=X
LET Y4=Y
LET Z4=Z-ZL/2
LET X5=X
LET Y5=Y-YL/2
LET Z5=Z
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X0
PRINT #1:"20"
PRINT #1:Y0
PRINT #1:"30"
PRINT #1:Z0
PRINT #1:"11"
PRINT #1:X1
PRINT #1:"21"
PRINT #1:Y1
PRINT #1:"31"
PRINT #1:Z1
PRINT #1:"12"
PRINT #1:X2
PRINT #1:"22"
PRINT #1:Y2
PRINT #1:"32"
PRINT #1:Z2
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X0
PRINT #1:"20"
PRINT #1:Y0
PRINT #1:"30"
PRINT #1:Z0
PRINT #1:"11"
PRINT #1:X2
PRINT #1:"21"
PRINT #1:Y2
PRINT #1:"31"
PRINT #1:Z2
PRINT #1:"12"
PRINT #1:X3
PRINT #1:"22"
PRINT #1:Y3
PRINT #1:"32"
PRINT #1:Z3
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X0
PRINT #1:"20"
PRINT #1:Y0
PRINT #1:"30"
PRINT #1:Z0
PRINT #1:"11"
PRINT #1:X3
PRINT #1:"21"
PRINT #1:Y3
PRINT #1:"31"
PRINT #1:Z3
PRINT #1:"12"
PRINT #1:X4
PRINT #1:"22"
PRINT #1:Y4
PRINT #1:"32"
PRINT #1:Z4
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X0
PRINT #1:"20"
PRINT #1:Y0
PRINT #1:"30"
PRINT #1:Z0
PRINT #1:"11"
PRINT #1:X4
PRINT #1:"21"
PRINT #1:Y4
PRINT #1:"31"
PRINT #1:Z4
PRINT #1:"12"
PRINT #1:X1
PRINT #1:"22"
PRINT #1:Y1
PRINT #1:"32"
PRINT #1:Z1
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X5
PRINT #1:"20"
PRINT #1:Y5
PRINT #1:"30"
PRINT #1:Z5
PRINT #1:"11"
PRINT #1:X2
PRINT #1:"21"
PRINT #1:Y2
PRINT #1:"31"
PRINT #1:Z2
PRINT #1:"12"
PRINT #1:X1
PRINT #1:"22"
PRINT #1:Y1
PRINT #1:"32"
PRINT #1:Z1
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X5
PRINT #1:"20"
PRINT #1:Y5
PRINT #1:"30"
PRINT #1:Z5
PRINT #1:"11"
PRINT #1:X3
PRINT #1:"21"
PRINT #1:Y3
PRINT #1:"31"
PRINT #1:Z3
PRINT #1:"12"
PRINT #1:X2
PRINT #1:"22"
PRINT #1:Y2
PRINT #1:"32"
PRINT #1:Z2
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X5
PRINT #1:"20"
PRINT #1:Y5
PRINT #1:"30"
PRINT #1:Z5
PRINT #1:"11"
PRINT #1:X4
PRINT #1:"21"
PRINT #1:Y4
PRINT #1:"31"
PRINT #1:Z4
PRINT #1:"12"
PRINT #1:X3
PRINT #1:"22"
PRINT #1:Y3
PRINT #1:"32"
PRINT #1:Z3
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:X5
PRINT #1:"20"
PRINT #1:Y5
PRINT #1:"30"
PRINT #1:Z5
PRINT #1:"11"
PRINT #1:X1
PRINT #1:"21"
PRINT #1:Y1
PRINT #1:"31"
PRINT #1:Z1
PRINT #1:"12"
PRINT #1:X4
PRINT #1:"22"
PRINT #1:Y4
PRINT #1:"32"
PRINT #1:Z4
END SUB
 

Re: シェルピンスキー

 投稿者:しばっち  投稿日:2011年 8月14日(日)23時35分10秒
  > No.1643[元記事へ]

続き

EXTERNAL  SUB OBJ(#1,X,Y,Z,L)
CALL TUBE(#1,X-L/2,Y,Z,X+L/2,Y,Z,L/4)
CALL TUBE(#1,X,Y+L/2,Z,X,Y-L/2,Z,L/4)
CALL TUBE(#1,X,Y,Z-L/2,X,Y,Z+L/2,L/4)
CALL OCTAHEDRON(#1,X,Y,Z,L,L,L)
END SUB

EXTERNAL  SUB TUBE(#1,X0,Y0,Z0,X1,Y1,Z1,LL) !'角柱(蓋あり)
DIM XX(4),YY(4),ZZ(4)
LET X=X1-X0 !'線分(X0,Y0,Z0)-(X1,Y1,Z1)に垂直な適当なベクトル(A,B,C)
LET Y=Y1-Y0
LET Z=Z1-Z0
LET A=1
LET B=1
LET C=1
IF X<>0 THEN !'内積0よりX*A+Y*B+Z*C=0
   LET A=(-B*Y-C*Z)/X
ELSEIF Y<>0 THEN
   LET B=(-A*X-C*Z)/Y
ELSEIF Z<>0 THEN
   LET C=(-A*X-B*Y)/Z
END IF
LET SS=SQR(A*A+B*B+C*C)
LET A=A/SS !'単位ベクトル
LET B=B/SS
LET C=C/SS
LET  TX=A*LL
LET  TY=B*LL
LET  TZ=C*LL
FOR K=0 TO 3
   CALL ROTATE(TX,TY,TZ,X,Y,Z,K*90,XA,YA,ZA)
   CALL ROTATE(TX,TY,TZ,X,Y,Z,(K+1)*90,XB,YB,ZB)
   PRINT #1:"0"
   PRINT #1:"3DFACE"
   PRINT #1:"8"
   PRINT #1:"LAYER1"
   PRINT #1:"62"
   PRINT #1:"1"
   PRINT #1:"10"
   PRINT #1:XA+X0
   PRINT #1:"20"
   PRINT #1:YA+Y0
   PRINT #1:"30"
   PRINT #1:ZA+Z0
   PRINT #1:"11"
   PRINT #1:XB+X0
   PRINT #1:"21"
   PRINT #1:YB+Y0
   PRINT #1:"31"
   PRINT #1:ZB+Z0
   PRINT #1:"12"
   PRINT #1:XB+X1
   PRINT #1:"22"
   PRINT #1:YB+Y1
   PRINT #1:"32"
   PRINT #1:ZB+Z1
   PRINT #1:"13"
   PRINT #1:XA+X1
   PRINT #1:"23"
   PRINT #1:YA+Y1
   PRINT #1:"33"
   PRINT #1:ZA+Z1
   LET XX(K+1)=XA !'(追加部分)
   LET YY(K+1)=YA
   LET ZZ(K+1)=ZA
NEXT  K
PRINT #1:"0" !'蓋(追加部分)
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:XX(1)+X1
PRINT #1:"20"
PRINT #1:YY(1)+Y1
PRINT #1:"30"
PRINT #1:ZZ(1)+Z1
PRINT #1:"11"
PRINT #1:XX(2)+X1
PRINT #1:"21"
PRINT #1:YY(2)+Y1
PRINT #1:"31"
PRINT #1:ZZ(2)+Z1
PRINT #1:"12"
PRINT #1:XX(3)+X1
PRINT #1:"22"
PRINT #1:YY(3)+Y1
PRINT #1:"32"
PRINT #1:ZZ(3)+Z1
PRINT #1:"13"
PRINT #1:XX(4)+X1
PRINT #1:"23"
PRINT #1:YY(4)+Y1
PRINT #1:"33"
PRINT #1:ZZ(4)+Z1
PRINT #1:"0"
PRINT #1:"3DFACE"
PRINT #1:"8"
PRINT #1:"LAYER1"
PRINT #1:"62"
PRINT #1:"1"
PRINT #1:"10"
PRINT #1:XX(4)+X0
PRINT #1:"20"
PRINT #1:YY(4)+Y0
PRINT #1:"30"
PRINT #1:ZZ(4)+Z0
PRINT #1:"11"
PRINT #1:XX(3)+X0
PRINT #1:"21"
PRINT #1:YY(3)+Y0
PRINT #1:"31"
PRINT #1:ZZ(3)+Z0
PRINT #1:"12"
PRINT #1:XX(2)+X0
PRINT #1:"22"
PRINT #1:YY(2)+Y0
PRINT #1:"32"
PRINT #1:ZZ(2)+Z0
PRINT #1:"13"
PRINT #1:XX(1)+X0
PRINT #1:"23"
PRINT #1:YY(1)+Y0
PRINT #1:"33"
PRINT #1:ZZ(1)+Z0
END SUB

以下省略
EXTERNAL  SUB ROTATE(XX,YY,ZZ,X0,Y0,Z0,TH,NX,NY,NZ) !'任意軸回転(ロドリグの公式)
END SUB
 

戻る