|
!'ボクセル表現(VOXEL)
OPTION BASE 0
DIM ZZ(3),Z0(3),Z1(3),Z2(3),TZ(3)
READ XS,XE,YS,YE,ZS,ZE,N,NN,MAXITER,EPS
DATA -1.5,1.5,-1.5,1.5,-1.5,1.5,80,3,30,0.0005 !'(要)調整
FILE GETSAVENAME F$,"dxfファイル|*.dxf"
IF F$="" THEN STOP
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"
FOR Y=YS TO YE STEP (YE-YS)/N
FOR X=XS TO XE STEP (XE-XS)/N
FOR Z=ZS TO ZE STEP (ZE-ZS)/N
WHEN EXCEPTION IN
LET ZZ(0)=X !'初期値
LET ZZ(1)=Y
LET ZZ(2)=Z
LET ZZ(3)=0
FOR I=1 TO MAXITER
CALL POW(Z1,ZZ,NN)
LET Z1(0)=Z1(0)-1 !'Z^NN-1
CALL POW(Z2,ZZ,NN-1)
MAT Z2=NN*Z2 !'NN*Z^(NN-1)
CALL DIV(Z0,Z1,Z2)
MAT Z0=(-1)*Z0
CALL ADD(ZZ,ZZ,Z0) !' Z=Z-(Z^NN-1)/(NN*Z^(NN-1)) ニュートン法(クォータニオン演算)
IF ABS(ZZ(0)-TZ(0))<EPS AND ABS(ZZ(1)-TZ(1))<EPS AND ABS(ZZ(2)-TZ(2))<EPS AND ABS(ZZ(3)-TZ(3))<EPS THEN EXIT FOR
MAT TZ=ZZ
NEXT I
IF I>MAXITER THEN CALL RECT(#1,X,Y,Z,(XE-XS)/N,(YE-YS)/N,(ZE-ZS)/N) !'収束しなかったら記録
USE
END WHEN
NEXT Z
NEXT X
NEXT Y
PRINT #1:"0"
PRINT #1:"ENDSEC"
PRINT #1:"0"
PRINT #1:"EOF"
CLOSE #1
END
EXTERNAL SUB MUL(S(),A(),B()) !'クォータニオン(4元数)掛算
OPTION BASE 0
DIM SS(3)
LET SS(0)=A(0)*B(0)-A(1)*B(1)-A(2)*B(2)-A(3)*B(3)
LET SS(1)=A(0)*B(1)+A(1)*B(0)+A(2)*B(3)-A(3)*B(2)
LET SS(2)=A(0)*B(2)-A(1)*B(3)+A(2)*B(0)+A(3)*B(1)
LET SS(3)=A(0)*B(3)+A(1)*B(2)-A(2)*B(1)+A(3)*B(0)
MAT S=SS
END SUB
EXTERNAL SUB ADD(S(),A(),B())
OPTION BASE 0
DIM SS(3)
MAT SS=A+B
MAT S=SS
END SUB
EXTERNAL SUB POW(S(),A(),N)
OPTION BASE 0
DIM SS(3)
MAT SS=A
FOR I=2 TO N
CALL MUL(SS,SS,A)
NEXT I
MAT S=SS
END SUB
EXTERNAL SUB DIV(S(),A(),B())
OPTION BASE 0
DIM BB(3)
LET BB(0)=B(0)
LET BB(1)=-B(1)
LET BB(2)=-B(2)
LET BB(3)=-B(3)
CALL MUL(S,A,BB)
MAT S=(1/(B(0)^2+B(1)^2+B(2)^2+B(3)^2))*S
END SUB
以下省略
EXTERNAL SUB RECT(#1,XX,YY,ZZ,XL,YL,ZL)
END SUB
|
|