Skip to content

Commit 272c728

Browse files
committed
Numpified transforms.py, fixed bug in invert_vec6
svn path=/trunk/matplotlib/; revision=3408
1 parent 816f4b0 commit 272c728

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

lib/matplotlib/transforms.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@
126126
c = sy*sin(alpha);
127127
d = sy*cos(alpha);
128128
129+
The affine transformation can be accomplished for row vectors with a
130+
single matrix multiplication
131+
X_new = X_old * M
132+
where
133+
M = [ a b 0
134+
c d 0
135+
tx ty 1]
136+
and each X is the row vector [x, y, 1]. Hence M is
137+
the transpose of the matrix representation given in
138+
http://en.wikipedia.org/wiki/Affine_transformation,
139+
which is for the more usual column-vector representation
140+
of the position.)
141+
142+
143+
129144
From a user perspective, the most important Tranformation methods are
130145
131146
All transformations
@@ -233,13 +248,13 @@
233248
and attributes to Bbox and/or putting them elsewhere in this module.
234249
"""
235250
from __future__ import division
236-
237251
import math
238-
from _transforms import Value, Point, Interval, Bbox, Affine
239-
from _transforms import IDENTITY, LOG10, POLAR, Func, FuncXY
240-
from _transforms import SeparableTransformation, NonseparableTransformation
241-
from matplotlib.numerix import array, Float
242-
from matplotlib.numerix.linear_algebra import inverse
252+
import numpy as npy
253+
254+
from matplotlib._transforms import Value, Point, Interval, Bbox, Affine
255+
from matplotlib._transforms import IDENTITY, LOG10, POLAR, Func, FuncXY
256+
from matplotlib._transforms import SeparableTransformation
257+
from matplotlib._transforms import NonseparableTransformation
243258

244259
def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
245260
'''
@@ -249,7 +264,8 @@ def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
249264
the maximum absolute value.
250265
251266
If they are too close, each will be moved by the 'expander'.
252-
If 'increasing' is True and vmin > vmax, they will be swapped.
267+
If 'increasing' is True and vmin > vmax, they will be swapped,
268+
regardless of whether they are too close.
253269
'''
254270
swapped = False
255271
if vmax < vmin:
@@ -372,19 +388,13 @@ def lbwh_to_bbox(l,b,w,h):
372388

373389
def invert_vec6(v):
374390
"""
375-
v is a,b,c,d,tx,ty vec6 repr of a matrix
376-
[ a b 0
377-
c d 0
378-
tx ty 1]
379-
391+
v is a,b,c,d,tx,ty vec6 repr of an affine transformation.
380392
Return the inverse of v as a vec6
381393
"""
382-
M = array([ [a,b,0], [c,d,0], [tx,ty,1]], typecode=Float)
383-
Mi = inverse(M)
384-
a, b = M[0,0:2]
385-
c, d = M[1,0:2]
386-
tx, ty = M[2,0:2]
387-
return a,b,c,d,tx,ty
394+
a,b,c,d,tx,ty = v
395+
M = npy.array([ [a,b,0], [c,d,0], [tx,ty,1]], dtype=npy.float64)
396+
Mi = npy.linalg.inv(M)
397+
return Mi[:,:2].ravel()
388398

389399
def multiply_affines( v1, v2):
390400
"""

0 commit comments

Comments
 (0)