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

Skip to content

Commit 695fd50

Browse files
Save some calculation by saving view axes
1 parent da4fccc commit 695fd50

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,17 +864,21 @@ def get_proj(self):
864864
eye = R + self._dist * ps
865865
self.eye = eye
866866

867+
# Calculate the viewing axes for the eye position
868+
u, v, n = self._calc_view_axes(eye)
869+
self._view_u = u
870+
self._view_v = v
871+
self._view_n = n
872+
867873
# Generate the view and projection transformation matrices
868874
if self._focal_length == np.inf:
869875
# Orthographic projection
870-
u, v, n = self._get_view_axes(eye)
871876
viewM = proj3d.view_transformation(u, v, n, eye)
872877
projM = proj3d.ortho_transformation(-self._dist, self._dist)
873878
else:
874879
# Perspective projection
875880
# Scale the eye dist to compensate for the focal length zoom effect
876881
eye_focal = R + self._dist * ps * self._focal_length
877-
u, v, n = self._get_view_axes(eye_focal)
878882
viewM = proj3d.view_transformation(u, v, n, eye_focal)
879883
projM = proj3d.persp_transformation(-self._dist,
880884
self._dist,
@@ -1110,8 +1114,8 @@ def drag_pan(self, button, key, x, y):
11101114
return
11111115

11121116
# Transform the pan from the view axes to the data axees
1113-
u, v, n = self._get_view_axes(self.eye)
1114-
R = -np.array([u, v, n]) / self._box_aspect * self._dist
1117+
R = np.array([self._view_u, self._view_v, self._view_n])
1118+
R = -R / self._box_aspect * self._dist
11151119
dxyz_projected = R.T @ np.array([dx, dy, dz])
11161120

11171121
# Calculate pan distance
@@ -1125,7 +1129,7 @@ def drag_pan(self, button, key, x, y):
11251129
self.set_ylim3d(miny + dyy, maxy + dyy)
11261130
self.set_zlim3d(minz + dzz, maxz + dzz)
11271131

1128-
def _get_view_axes(self, eye):
1132+
def _calc_view_axes(self, eye):
11291133
"""
11301134
Get the unit viewing axes in data coordinates.
11311135
`u` is towards the right of the screen
@@ -1237,8 +1241,7 @@ def _zoom_data_limits(self, scale_x, scale_y, scale_z):
12371241
angles. A scale factor > 1 zooms out and a scale factor < 1 zooms in.
12381242
"""
12391243
# Convert from the scale factors in the view frame to the data frame
1240-
u, v, n = self._get_view_axes(self.eye)
1241-
R = np.array([u, v, n])
1244+
R = np.array([self._view_u, self._view_v, self._view_n])
12421245
S = np.array([scale_x, scale_y, scale_z])
12431246
scale = np.linalg.norm(R.T@(np.eye(3)*S), axis=1)
12441247

0 commit comments

Comments
 (0)