Skip to content

Commit 29e4c75

Browse files
Fix 3D rotation precession
1 parent 7f3738d commit 29e4c75

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,10 +1568,11 @@ def _on_move(self, event):
15681568
q = _Quaternion.from_cardan_angles(elev, azim, roll)
15691569

15701570
# Update quaternion - a variation on Ken Shoemake's ARCBALL
1571-
current_vec = self._arcball(self._sx/w, self._sy/h)
1572-
new_vec = self._arcball(x/w, y/h)
1571+
scale = np.sqrt(2)/2 # slow down the rate of rotation
1572+
current_vec = self._arcball(self._sx*scale/w, self._sy*scale/h)
1573+
new_vec = self._arcball(x*scale/w, y*scale/h)
15731574
dq = _Quaternion.rotate_from_to(current_vec, new_vec)
1574-
q = dq * q
1575+
q = dq * dq * q
15751576

15761577
# Convert to elev, azim, roll
15771578
elev, azim, roll = q.as_cardan_angles()

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,8 @@ def test_rotate():
19521952
[30, 0.5, 0, 30, -90, 0],
19531953
[0, 0, 0.5, -90, 0, 0],
19541954
[30, 0, 0.5, -60, -90, 90],
1955-
[0, 0.5, 0.5, -45, -90, 45],
1956-
[30, 0.5, 0.5, -15, -90, 45]]:
1955+
[0, 0.5, 0.5, 0, -180, 90],
1956+
[30, 0.5, 0.5, 0, -180, 60]]:
19571957
fig = plt.figure()
19581958
ax = fig.add_subplot(1, 1, 1, projection='3d')
19591959
ax.view_init(0, 0, roll)
@@ -1967,9 +1967,8 @@ def test_rotate():
19671967
xdata=dx*ax._pseudo_w, ydata=dy*ax._pseudo_h))
19681968
fig.canvas.draw()
19691969

1970-
assert np.isclose(ax.elev, new_elev)
1971-
assert np.isclose(ax.azim, new_azim)
1972-
assert np.isclose(ax.roll, new_roll)
1970+
np.testing.assert_allclose((ax.elev, ax.azim, ax.roll),
1971+
(new_elev, new_azim, new_roll), atol=1e-5)
19731972

19741973

19751974
def test_pan():

0 commit comments

Comments
 (0)