Skip to content

Commit ef8d067

Browse files
Code review updates
1 parent 2e54be2 commit ef8d067

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

doc/users/next_whats_new/3d_plot_tilt_angle.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
3D plots have now have a 3rd "tilt" viewing angle
2-
-------------------------------------------------
1+
3D plots gained a 3rd "tilt" viewing angle
2+
------------------------------------------
33

44
3D plots can now be viewed from any orientation with the addition of a 3rd tilt
55
angle, which rotates the plot about the viewing axis. Interactive rotation

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,9 +1270,10 @@ def _on_move(self, event):
12701270
if self.button_pressed in self._rotate_btn:
12711271
# rotate viewing point
12721272
# get the x and y pixel coords
1273-
tilt = np.deg2rad(self.tilt)
12741273
if dx == 0 and dy == 0:
12751274
return
1275+
1276+
tilt = np.deg2rad(self.tilt)
12761277
delev = -(dy/h)*180*np.cos(tilt) - (dx/w)*180*np.sin(tilt)
12771278
dazim = +(dy/h)*180*np.sin(tilt) - (dx/w)*180*np.cos(tilt)
12781279
self.elev = self.elev + delev

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ def rotation_about_vector(v, angle):
5555
"""
5656
Produce a rotation matrix for an angle in radians about a vector.
5757
"""
58-
v = v/np.linalg.norm(v)
58+
vx, vy, vz = v / np.linalg.norm(v)
5959
s = np.sin(angle)
6060
c = np.cos(angle)
61-
t = 1-c
61+
t = 2*np.sin(angle/2)**2 # more numerically stable than t = 1-c
6262

6363
R = np.array([
64-
[t*v[0]*v[0] + c, t*v[0]*v[1] - v[2]*s, t*v[0]*v[2] + v[1]*s],
65-
[t*v[1]*v[0] + v[2]*s, t*v[1]*v[1] + c, t*v[1]*v[2] - v[0]*s],
66-
[t*v[2]*v[0] - v[1]*s, t*v[2]*v[1] + v[0]*s, t*v[2]*v[2] + c]])
64+
[t*vx*vx + c, t*vx*vy - vz*s, t*vx*vz + vy*s],
65+
[t*vy*vx + vz*s, t*vy*vy + c, t*vy*vz - vx*s],
66+
[t*vz*vx - vy*s, t*vz*vy + vx*s, t*vz*vz + c]])
6767

6868
return R
6969

0 commit comments

Comments
 (0)