Repository navigation
Description
Problem
In mplot3d, the plot currently reacts differently to dragging the mouse, depending on the orientation of the axes. In the default orientation, moving the mouse left/right or up/down tilts the plot left/right or up/down correspondingly, which is quite natural and intuitive. However, when the plot is rotated so that we are looking down the z-axis, then moving the mouse up/down does not tilt the plot up/down as expected, but rotates it around the z-axis. The situation reminds of gimball lock. It is clumsy and annoying.
Additionally, the 'roll' angle currently cannot be controlled with the mouse (issue #14451 and PR #21426 mention this) - at present, the two degrees of freedom of the mouse (left-right and up-down) correspond directly to two of the rotational degrees of freedom of the plot (azimuth and elevation), whereas there are in fact three (i.e., azimuth, elevation, and roll; or heading, tilt, and bank, if you will). Rotations around three cartesian axes do look essentially different (one can turn up/down, turn left/right, or twist left/right-handed). Controlling only two limits the accessible orientations.
Proposed solution
For a natural interaction with the mouse, it is desirable that the figure reacts in the same way to mouse movements, regardless of orientation: there should be no difference between "poles" and "equator" of the figure, and no 'gimbal lock'.
Of course this problem is not new - satisfying solutions have been devised in the nineties of the last century, e.g., Ken Shoemake's 'arcball' [1]. All that is needed to implement this in mplot3d is a small change to axes3d._onmove(), together with a minimal quaternion class - this avoids an additional dependency on a large package like numpy-quaternion.
The quaternion class can be made internal, to hide it; or it can be exposed since it can be more generally useful.
- [Ken Shoemake, "ARCBALL: A user interface for specifying three-dimensional rotation using a mouse." in Proceedings of Graphics Interface '92, 1992, pp. 151-156, https://doi.org/10.20380/GI1992.18]
Activity
[-][ENH]: natural 3D rotation with mouse[/-][+][ENH]: Natural 3D rotation with mouse[/+]Natural 3D rotation with mouse
Natural 3D rotation with mouse
MischaMegens2 commentedon May 26, 2024
This what the mouse rotation looks like on the
surface3d.pyexample, before the pull request #28290(play the movie):
elev_azim.mov
(you can see the figure sometimes rotates, when you'd think it should tilt; or it moves in the opposite direction as the mouse).
After the patch:
arcball.mov
(Now the movement is much more consistent: the figure tilts up/down, left/right if you move the mouse up/down, left/right near the center; near the edge, the mouse rotates the figure).
Natural 3D rotation with mouse
Natural 3D rotation with mouse
Introduce natural 3D rotation with mouse (#28290)
Introduce natural 3D rotation with mouse (matplotlib#28290)