8000 Update axes3d.py's arcball · matplotlib/matplotlib@a0c22ed · GitHub
[go: up one dir, main page]

Skip to content

Commit a0c22ed

Browse files
committed
Update axes3d.py's arcball
- change argument from 2 element numpy array to x, y - add type hints
1 parent 41e3fb0 commit a0c22ed

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,21 +1503,22 @@ def _calc_coord(self, xv, yv, renderer=None):
15031503
p2 = p1 - scale*vec
15041504
return p2, pane_idx
15051505

1506-
def _arcball(self, p):
1506+
def _arcball(self, x: float, y: float) -> np.ndarray:
15071507
"""
1508-
Convert a point p = [x, y] to a point on a virtual trackball
1508+
Convert a point (x, y) to a point on a virtual trackball
15091509
This is Ken Shoemake's arcball
15101510
See: Ken Shoemake, "ARCBALL: A user interface for specifying
15111511
three-dimensional rotation using a mouse." in
15121512
Proceedings of Graphics Interface '92, 1992, pp. 151-156,
15131513
https://doi.org/10.20380/GI1992.18
15141514
"""
1515-
p = 2 * p
1516-
r = p[0]**2 + p[1]**2
1517-
if r > 1:
1518-
p = np.concatenate(([0], p/math.sqrt(r)))
1515+
x *= 2
1516+
y *= 2
1517+
r2 = x*x + y*y
1518+
if r2 > 1:
1519+
p = np.array([0, x/math.sqrt(r2), y/math.sqrt(r2)])
15191520
else:
1520-
p = np.concatenate(([math.sqrt(1-r)], p))
1521+
p = np.array([math.sqrt(1-r2), x, y])
15211522
return p
15221523

15231524
def _on_move(self, event):
@@ -1562,12 +1563,10 @@ def _on_move(self, event):
15621563
q = _Quaternion.from_cardan_angles(elev, azim, roll)
15631564

15641565
# Update quaternion - a variation on Ken Shoemake's ARCBALL
1565-
current_point = np.array([self._sx/w, self._sy/h])
1566-
new_point = np.array([x/w, y/h])
1567-
current_vec = self._arcball(current_point)
1568-
new_vec = self._arcball(new_point)
1566+
current_vec = self._arcball(self._sx/w, self._sy/h)
1567+
new_vec = self._arcball(x/w, y/h)
15691568
dq = _Quaternion.rotate_from_to(current_vec, new_vec)
1570-
q = dq*q
1569+
q = dq * q
15711570

15721571
# Convert to elev, azim, roll
15731572
elev, azim, roll = q.as_cardan_angles()

0 commit comments

Comments
 (0)
0