NB. Some simple functions to illustrate 2D linear transformations NB. Some verb definitions mp =: mat_product =: +/ . * NB. A square data object square =: 5 2 reshape 0 0 10 0 10 10 0 10 0 0 NB. The scaling transformation scale =: monad def '2 2 reshape (0 from y.),0,0,(1 from y.)' scale 2 3 square mat_product scale 2 3 NB. The rotation transformation rotate =: monad def '2 2 reshape 1 1 _1 1 * 2 1 1 2 o. (o. y.) % 180' rotate 90 rotate 360 square mat_product rotate 90 NB. The translation transformation NB. We need to use homogeneous representation translate =: monad def '3 3 reshape 1 0 0 0 1 0 , y. , 1' translate 10 _10 (square,.1) mat_product translate 10 _10 NB. Don't do unnecessary multiplications (square,.1) mat_product 3 2 take translate 10 _10 NB. The homogeneous representation of scale scale =: monad def '3 3 reshape (0 from y.), 0 0 0 , (1 from y.), 0 0 0 1' scale 2 3 (square,.1) mat_product 3 2 take scale 2 3 NB. The homogeneous representation of rotate rotate =: monad def '((2 2 reshape 1 1 _1 1 * 2 1 1 2 o. (o. y.) % 180),.0),0 0 1' rotate 180 (square,.1) mat_product 3 2 take rotate 180 NB. Form a new square new_square =: (square,.1) mat_product 3 2 take translate 10 10 NB. Rotate this square 90 degrees about the point 10 10 translate _10 _10 rotate 90 translate 10 10 (translate _10 _10)mat_product (rotate 90) mat_product translate 10 10 xform =: (translate _10 _10)mat_product (rotate 90) mat_product translate 10 10 (new_square,. 1) mat_product 3 2 take xform