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

Skip to content

Commit e497c77

Browse files
Fix arcsin domain error
1 parent 343b3dc commit e497c77

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,9 +4023,10 @@ def as_cardan_angles(self):
40234023
The inverse of `from_cardan_angles()`.
40244024
Note that the angles returned are in radians, not degrees.
40254025
"""
4026-
qw = self.scalar
4027-
qx, qy, qz = self.vector[..., :]
4026+
n = np.sqrt(self.norm)
4027+
qw = self.scalar / n
4028+
qx, qy, qz = self.vector[..., :] / n
40284029
azim = np.arctan2(2*(-qw*qz+qx*qy), qw*qw+qx*qx-qy*qy-qz*qz)
4029-
elev = np.arcsin( 2*( qw*qy+qz*qx)/(qw*qw+qx*qx+qy*qy+qz*qz)) # noqa E201
4030+
elev = np.arcsin(np.clip(2*(qx*qz + qw*qy), -1, 1))
40304031
roll = np.arctan2(2*( qw*qx-qy*qz), qw*qw-qx*qx-qy*qy+qz*qz) # noqa E201
40314032
return elev, azim, roll

0 commit comments

Comments
 (0)