126
126
c = sy*sin(alpha);
127
127
d = sy*cos(alpha);
128
128
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
+
129
144
From a user perspective, the most important Tranformation methods are
130
145
131
146
All transformations
233
248
and attributes to Bbox and/or putting them elsewhere in this module.
234
249
"""
235
250
from __future__ import division
236
-
237
251
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
243
258
244
259
def nonsingular (vmin , vmax , expander = 0.001 , tiny = 1e-15 , increasing = True ):
245
260
'''
@@ -249,7 +264,8 @@ def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
249
264
the maximum absolute value.
250
265
251
266
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.
253
269
'''
254
270
swapped = False
255
271
if vmax < vmin :
@@ -372,19 +388,13 @@ def lbwh_to_bbox(l,b,w,h):
372
388
373
389
def invert_vec6 (v ):
374
390
"""
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.
380
392
Return the inverse of v as a vec6
381
393
"""
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 ()
388
398
389
399
def multiply_affines ( v1 , v2 ):
390
400
"""
0 commit comments