[Matrix-SIG] matrix transformations on vector graphics

David Ascher da@skivs.ski.org
Wed, 15 Apr 1998 10:48:51 -0700 (PDT)

On Wed, 15 Apr 1998, Just van Rossum wrote:

> I am very new to NumPy, and I would like some tips on how to efficiently do
> transformations for vector graphics (I mean, NumPy just screams "use me!"
> to me for this kind of stuff ;-).

Indeed -- there was a discussion on similar topics a few months back --
check the findmail archives re: use of complex numbers for graphics.

> Say, I have an array of 2D coordinates:
> v = Numeric.array([(0.0, 0.0), (10.0, 0.0), (100.0, 75.0), etc...])
> and a simple transformation matrix (this one should flip the y coordinate):
> tm = Numeric.array([[1.0, 0, 0], [0, -1.0, 0], [0, 0, 1.0]])
> Is there a convenient way to apply the matrix to the vector array?

Why do you define a 3x3 array if you're just using 2d coordinates?  

I'd say 
	tm = Numeric.array([[1,0],[0,-1]], Float)

is closer to what you want.

And then, you can just use the 'dot()' function:

	>>> Numeric.dot(v, tm)
	array([[   0.,    0.],
	       [  10.,    0.],
	       [ 100.,  -75.]])

> But if I in general would prefer xy pairs, I would have to do
> Numeric.transpose() before and after I do this. Or is transpose()
> relatively cheap? Did I just answer my own question?

transpose is very cheap, since it doesn't move any of the data, just the
description of the data.

> What more introduction material is there besides David Ascher's wonderful
> pages and the stuff that comes with NumPy?

Nothing yet -- actually, that's not true -- I have an HTML version of my
SPAM-6 tutorial, which I keep meaning to put on the web.  It's not great
(after all, you don't get my wonderful presentation, just the supporting
material), but it is more up to date than the tutorial.  I'll try and do
that sometime soon...