@@ -1867,16 +1867,21 @@ def to_values(self):
1867
1867
mtx = self .get_matrix ()
1868
1868
return tuple (mtx [:self .input_dims ].swapaxes (0 , 1 ).flat )
1869
1869
1870
- def _affine_transform_3d (vertices , trans ):
1870
+ def _affine_transform_3d (self , vertices , mtx ):
1871
1871
"""
1872
1872
The 1d/2d versions of this are written in _path.h, and use agg. This is a
1873
1873
temporary implementation for this proof of concept
1874
1874
"""
1875
- if vertices .shape [1 ] != 3 or trans .shape [0 ] != 4 or trans .shape [1 ] != 4 :
1876
- raise TypeError ("Not working for anything other than 3D" )
1875
+ values = np .asanyarray (vertices )
1876
+ # single point
1877
+ if (values .shape == (3 ,)):
1878
+ return mtx .dot (vertices + [1 ]).tolist ()[:3 ]
1879
+ # multiple points
1880
+ if (values .shape [1 ] == 3 ):
1881
+ homogeneous = np .hstack ((values , np .ones ((values .shape [0 ], 1 ))))
1882
+ return np .dot (mtx , homogeneous .T ).T [:, :- 1 ]
1877
1883
1878
- return [[np .vdot (trans [row , :3 ], vertex ) + trans [row , 3 ]
1879
- for row in range (3 )]for vertex in vertices ]
1884
+ raise TypeError ("Must be 3D" )
1880
1885
1881
1886
@_api .rename_parameter ("3.8" , "points" , "values" )
1882
1887
def transform_affine (self , values ):
@@ -2300,7 +2305,7 @@ def rotate(self, theta, dim=0):
2300
2305
mtx [1 , 0 ] = (b * xx ) + (a * yx )
2301
2306
mtx [1 , 1 ] = (b * xy ) + (a * yy )
2302
2307
mtx [1 , 2 ] = (b * xz ) + (a * yz )
2303
- mtx [1 , 2 ] = (b * x0 ) + (a * y0 )
2308
+ mtx [1 , 3 ] = (b * x0 ) + (a * y0 )
2304
2309
2305
2310
self .invalidate ()
2306
2311
return self
@@ -2348,9 +2353,9 @@ def translate(self, tx, ty, tz):
2348
2353
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
2349
2354
and :meth:`scale`.
2350
2355
"""
2351
- self ._mtx [0 , 2 ] += tx
2352
- self ._mtx [1 , 2 ] += ty
2353
- self ._mtx [2 , 2 ] += tz
2356
+ self ._mtx [0 , 3 ] += tx
2357
+ self ._mtx [1 , 3 ] += ty
2358
+ self ._mtx [2 , 3 ] += tz
2354
2359
self .invalidate ()
2355
2360
return self
2356
2361
0 commit comments