Iterated Function Systems
Vector 15:4, page 78
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 78
I read the Reiters’ article on the above topic (Vector vol. 15 no.2 pp.104-120) with great pleasure. However I would like to suggest that greater advantage could have been taken of the J interpreter in using complex numbers to generate rotation matrices, and “amend” to tidy up the programming of homogeneous coordinates. To start with, use verbs id and di to define an identity matrix and the coordinates of its diagonal:
id=: i.=/i. NB. identity matrix of order y.
di=: <"1@(i.,.i.) NB. coordinates of diagonal elements of id y.
id 3
1 0 0
0 1 0
0 0 1
di 3
┌───┬───┬───┐
│0 0│1 1│2 2│
└───┴───┴───┘
Now use the properties of “amend” to make scaling matrices from id 3 :
scale=: 3 : 'y.(di 2)}(id 3)' NB. scaling matrix y.= x,y scale factors
scale 0.1 0.5
0.1 0 0
0 0.5 0
0 0 1
A verb to generate a translation uses a similar technique to generate the indices of the first two items of the third row:
trans=: 3 : '(y.,1)2}id 3' NB. translation matrix y.= x,y shifts
trans 0.4 0.6
1 0 0
0 1 0
0.4 0.6 1
The rotation matrix is generated by using Euler’s formula, followed by +. which generates a 2-item vector from the real and imaginary parts
Now use a gerund, which the Reiters extol in order to generate the 2x2 matrix (c -s, s c):
rot2=: cs`(|.&cs&-)`: 0 NB. 2 dimensional. rotation matrix, y.=angle
pi=: 1p1
rot2 pi%3
0.5 _0.8660254
0.8660254 0.5
(As an aside, the result of rotating a single point with coordinates (x,y) through an angle a is given by xjy*j.a and so the hook r2=: *^@j. describes such a rotation, that is
produces a result equivalent to
)
Finally transform to homogeneous coordinates using amend as before:
rot=: 3 :'((rot2 y.),.0)(0 1)}id 3' NB. rotn.matrix for hom. coords, y.=angle
rot pi%3
0.5 _0.8660254 0
0.8660254 0.5 0
0 0 1
The matrices d, e, and f on p.113 are then simply defined as
The seven lines with comments collectively make up a little package for these transformations.