Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 148f1b7

Browse files
committed
Convert axes3D to use transforms
1 parent d85f75d commit 148f1b7

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from . import art3d
3636
from . import proj3d
3737
from . import axis3d
38+
from . import transform3d
3839

3940

4041
@_docstring.interpd
@@ -236,7 +237,7 @@ def _transformed_cube(self, vals):
236237
(maxx, miny, maxz),
237238
(maxx, maxy, maxz),
238239
(minx, maxy, maxz)]
239-
return proj3d._proj_points(xyzs, self.M)
240+
return self.M.transform(xyzs)
240241

241242
def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
242243
"""
@@ -423,7 +424,7 @@ def draw(self, renderer):
423424

424425
# add the projection matrix to the renderer
425426
self.M = self.get_proj()
426-
self.invM = np.linalg.inv(self.M)
427+
self.invM = self.M.inverted()
427428

428429
collections_and_patches = (
429430
artist for artist in self._children
@@ -1200,12 +1201,8 @@ def get_proj(self):
12001201

12011202
# Transform to uniform world coordinates 0-1, 0-1, 0-1
12021203
box_aspect = self._roll_to_vertical(self._box_aspect)
1203-
worldM = proj3d.world_transformation(
1204-
*self.get_xlim3d(),
1205-
*self.get_ylim3d(),
1206-
*self.get_zlim3d(),
1207-
pb_aspect=box_aspect,
1208-
)
1204+
worldM = transform3d.WorldTransform(*self.get_xlim3d(), *self.get_ylim3d(),
1205+
*self.get_zlim3d(), pb_aspect=box_aspect)
12091206

12101207
# Look into the middle of the world coordinates:
12111208
R = 0.5 * box_aspect
@@ -1238,21 +1235,18 @@ def get_proj(self):
12381235
# Generate the view and projection transformation matrices
12391236
if self._focal_length == np.inf:
12401237
# Orthographic projection
1241-
viewM = proj3d._view_transformation_uvw(u, v, w, eye)
1242-
projM = proj3d._ortho_transformation(-self._dist, self._dist)
1238+
viewM = transform3d.ViewTransform(u, v, w, eye)
1239+
projM = transform3d.OrthographicTransform(-self._dist, self._dist)
12431240
else:
12441241
# Perspective projection
12451242
# Scale the eye dist to compensate for the focal length zoom effect
12461243
eye_focal = R + self._dist * ps * self._focal_length
1247-
viewM = proj3d._view_transformation_uvw(u, v, w, eye_focal)
1248-
projM = proj3d._persp_transformation(-self._dist,
1249-
self._dist,
1250-
self._focal_length)
1244+
viewM = transform3d.ViewTransform(u, v, w, eye_focal)
1245+
projM = transform3d.PerspectiveTransform(-self._dist, self._dist,
1246+
self._focal_length)
12511247

12521248
# Combine all the transformation matrices to get the final projection
1253-
M0 = np.dot(viewM, worldM)
1254-
M = np.dot(projM, M0)
1255-
return M
1249+
return worldM + viewM + projM
12561250

12571251
def mouse_init(self, rotate_btn=1, pan_btn=2, zoom_btn=3):
12581252
"""
@@ -1459,7 +1453,7 @@ def _calc_coord(self, xv, yv, renderer=None):
14591453
zv = -1 / self._focal_length
14601454

14611455
# Convert point on view plane to data coordinates
1462-
p1 = np.array(proj3d.inv_transform(xv, yv, zv, self.invM)).ravel()
1456+
p1 = self.invM.transform([xv, yv, zv])
14631457

14641458
# Get the vector from the camera to the point on the view plane
14651459
vec = self._get_camera_loc() - p1

0 commit comments

Comments
 (0)