[Matrix-SIG] matrix transformations on vector graphics

Charles G Waldman cgw@pgt.com
Wed, 15 Apr 1998 16:01:39 -0400 (EDT)

 > >And then, you can just use the 'dot()' function:
 > >
 > >	>>> Numeric.dot(v, tm)
 > >	array([[   0.,    0.],
 > >	       [  10.,    0.],
 > >	       [ 100.,  -75.]])
 > That's cool. I see that perhaps I'd better stick with 2x2 and do the
 > translation separate: that should easy enough.

There's no reason that the translations have to be handled separately.
You just encode the point (x,y) as (x,y,1) and use matrices of the

  a b e
  c d f
  0 0 1

The a,b,c,d part is a normal 2x2 matrix and e,f is the offset.

This is an old trick called "projective coordinates".  You can still
use the "dot" function as David suggests.

This is superior because you can use matrix multiplication to
generate matrices representing composite transformations - this
way all of your manipulations are matrix multiplies, rather than
multiplies and adds.

If you do this, make sure to use the matrix_multiply, rather than the
default "elementwise" multiplication of arrays, (a NumPy pitfall
that's too easy to fall into).