3D回転行列

 投稿者:しばっち  投稿日:2017年 2月26日(日)16時03分20秒
  行列の掛け算として、3次元の回転行列を6通りの順序で求めます

DIM ROTX$(3,3),ROTY$(3,3),ROTZ$(3,3),P$(3,3),PP$(3,3),A$(3)
MAT READ A$
DATA X,Y,Z
RESTORE 2
MAT READ ROTX$,ROTY$,ROTZ$

1 DATA 1,0,0                     !'X軸回転
  DATA 0,"COS(XTH)","SIN(XTH)"
  DATA 0,"{-SIN(XTH)}","COS(XTH)"

  DATA "COS(YTH)",0,"{-SIN(YTH)}" !'Y軸回転
  DATA 0,1,0
  DATA "SIN(YTH)",0,"COS(YTH)"

  DATA "COS(ZTH)","SIN(ZTH)",0    !'Z軸回転
  DATA "{-SIN(ZTH)}","COS(ZTH)",0
  DATA 0,0,1

2 DATA 1,0,0                      !'X軸回転
  DATA 0,"COS(XTH)","{-SIN(XTH)}"
  DATA 0,"SIN(XTH)","COS(XTH)"

  DATA "COS(YTH)",0,"SIN(YTH)"     !'Y軸回転
  DATA 0,1,0
  DATA "{-SIN(YTH)}",0,"COS(YTH)"

  DATA "COS(ZTH)","{-SIN(ZTH)}",0  !'Z軸回転
  DATA "SIN(ZTH)","COS(ZTH)",0
  DATA 0,0,1

  PRINT "X軸,Y軸,Z軸"
  CALL MATRIX(P$,ROTX$,ROTY$,ROTZ$)
  CALL DISPLAY(P$,A$)
  PRINT "X軸,Z軸,Y軸"
  CALL MATRIX(P$,ROTX$,ROTZ$,ROTY$)
  CALL DISPLAY(P$,A$)
  PRINT "Y軸,X軸,Z軸"
  CALL MATRIX(P$,ROTY$,ROTX$,ROTZ$)
  CALL DISPLAY(P$,A$)
  PRINT "Y軸,Z軸,X軸"
  CALL MATRIX(P$,ROTY$,ROTZ$,ROTX$)
  CALL DISPLAY(P$,A$)
  PRINT "Z軸,X軸,Y軸"
  CALL MATRIX(P$,ROTZ$,ROTX$,ROTY$)
  CALL DISPLAY(P$,A$)
  PRINT "Z軸,Y軸,X軸"
  CALL MATRIX(P$,ROTZ$,ROTY$,ROTX$)
  CALL DISPLAY(P$,A$)
END

EXTERNAL  SUB DISPLAY(P$(,),A$())
  FOR I=1 TO 3
     PRINT A$(I);"'=";
     FOR J=1 TO 2
        PRINT A$(J);"*";P$(I,J);"+";
     NEXT J
     PRINT A$(3);"*";P$(I,3)
  NEXT I
  PRINT
END SUB

EXTERNAL  SUB MATRIX(D$(,),A$(,),B$(,),C$(,))
  FOR I=1 TO 3
     FOR J=1 TO 3
        FOR K=1 TO 3
           FOR L=1 TO 3
              IF A$(I,K)<>"0" AND B$(K,L)<>"0" AND C$(L,J)<>"0" THEN
                 LET S$=S$ &"+"& A$(I,K) &"*" &B$(K,L) & "*" & C$(L,J)
              END IF
           NEXT L
        NEXT K
        IF LEFT$(S$,1)="+" THEN LET S$=RIGHT$(S$,LEN(S$)-1)
        LET L=POS(S$,"1*")
        IF L>0 THEN LET S$(L:L+1)=""
        LET L=POS(S$,"*1")
        IF L>0 THEN LET S$(L:L+1)=""
        LET D$(I,J)="["&S$&"]"
        LET S$=""
     NEXT J
  NEXT I
END SUB
 

戻る