Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20de36e

Browse filesBrowse files
committed
Fix bugs in 3D rotation and _affine_transform_3d
1 parent b7f455d commit 20de36e
Copy full SHA for 20de36e

File tree

Expand file treeCollapse file tree

1 file changed

+14
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-9
lines changed

‎lib/matplotlib/transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/transforms.py
+14-9Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,16 +1867,21 @@ def to_values(self):
18671867
mtx = self.get_matrix()
18681868
return tuple(mtx[:self.input_dims].swapaxes(0, 1).flat)
18691869

1870-
def _affine_transform_3d(vertices, trans):
1870+
def _affine_transform_3d(self, vertices, mtx):
18711871
"""
18721872
The 1d/2d versions of this are written in _path.h, and use agg. This is a
18731873
temporary implementation for this proof of concept
18741874
"""
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]
18771883

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")
18801885

18811886
@_api.rename_parameter("3.8", "points", "values")
18821887
def transform_affine(self, values):
@@ -2300,7 +2305,7 @@ def rotate(self, theta, dim=0):
23002305
mtx[1, 0] = (b * xx) + (a * yx)
23012306
mtx[1, 1] = (b * xy) + (a * yy)
23022307
mtx[1, 2] = (b * xz) + (a * yz)
2303-
mtx[1, 2] = (b * x0) + (a * y0)
2308+
mtx[1, 3] = (b * x0) + (a * y0)
23042309

23052310
self.invalidate()
23062311
return self
@@ -2348,9 +2353,9 @@ def translate(self, tx, ty, tz):
23482353
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
23492354
and :meth:`scale`.
23502355
"""
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
23542359
self.invalidate()
23552360
return self
23562361

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.