``

prev Menu next

Transformation with arrays☆
Transformation can be assigned with a 4×4 matrix instead of transform functions.
LET A be a 4×4 matrix defined by DIM A(4,4).
If (x y 0 1)A = (x' y' z' c),
a point (x, y) is transformed to (x' / c, y' / c).
Especially, if the 4-th column is 0, 0, 0, 1,
DRAW a_pict WITH A
makes x, y transformed
A(1,1)*x + A(2,1)*y + A(4,1)
A(1,2)*x + A(2,2)*y + A(4,2)
respectively.
Example

    100 DECLARE EXTERNAL PICTURE a_pict
    110 DIM A(4,4)
    120 MAT READ A
    130 DATA   1,   2,  0,  0
    140 DATA 0.8, 0.5,  0,  0
    150 DATA   0,   0,  1,  0
    160 DATA   1,  -2,  0,  1
    170 SET WINDOW -4,4,-4,4
    180 DRAW a_pict WITH A
    190 END
    200 EXTERNAL PICTURE a_pict
    210 PLOT AREA : 0,0; 1,0; 1,1; 0,0
    220 END PICTURE

Transform functions and 4×4 matrices can be mixed.
Example
`180 DRAW a_pict WITH SHIFT(-1,1)*a`
Composition of transformations is identical with multiplication of matrices.
Thus composition of transformation can be obtained by multiplication of matrices.
Example. A transformation of A composed n times.

    100 DECLARE EXTERNAL PICTURE circle
    110 DIM A(4,4),B(4,4)
    120 MAT READ A
    130 DATA   1,   2,  0,  0
    140 DATA 0.8, 0.5,  0,  0
    150 DATA   0,   0,  1,  0
    160 DATA   1,  -2,  0,  1
    170 MAT B=IDN     !identity
    180 INPUT n
    190 FOR i=1 TO n
    200    MAT B=B*A
    210 NEXT i
    220 SET WINDOW -10,10,-10,10
    230 DRAW circle WITH B
    240 END
    900 EXTERNAL PICTURE circle
    910 FOR t=0 TO 2*pi STEP pi/180
    920    PLOT LINES:cos(t),sin(t);
    930 NEXT t
    940 END PICTURE