Repository: sympy/sympy

Issue:
Quaternion.to_euler degenerate cases not working when middle angle evaluates to 0.
This example:
```python
from sympy.abc import s, c
sp.Quaternion(c, 0, 0, s).to_euler('zyz')
```
Returns: $\left( \text{NaN}, \  2 \operatorname{atan}_{2}{\left(0,\sqrt{c^{2} + s^{2}} \right)}, \  \text{NaN}\right)$


Discussion:

Patch:
diff --git a/sympy/algebras/quaternion.py b/sympy/algebras/quaternion.py
index d4f1545a52..44bbca520d 100644
--- a/sympy/algebras/quaternion.py
+++ b/sympy/algebras/quaternion.py
@@ -539,13 +539,11 @@ def to_euler(self, seq, angle_addition=True, avoid_square_root=False):
             angles[1] = 2 * atan2(sqrt(c * c + d * d), sqrt(a * a + b * b))
 
         # Check for singularities in numerical cases
-        angle_test = angles[1]
         case = 0
-        if angle_test.is_number:
-            if is_eq(angle_test, S.Zero):
-                case = 1
-            if is_eq(angle_test, S.Pi):
-                case = 2
+        if is_eq(c, S.Zero) and is_eq(d, S.Zero):
+            case = 1
+        if is_eq(a, S.Zero) and is_eq(b, S.Zero):
+            case = 2
 
         if case == 0:
             if angle_addition:


Test patch:
diff --git a/sympy/algebras/tests/test_quaternion.py b/sympy/algebras/tests/test_quaternion.py
index f9439e212a..68b10427e6 100644
--- a/sympy/algebras/tests/test_quaternion.py
+++ b/sympy/algebras/tests/test_quaternion.py
@@ -333,6 +333,16 @@ def test_to_euler():
         assert q_back == q_normalized
 
 
+def test_to_euler_iss24504():
+    """
+    There was a mistake in the degenerate case testing
+    See issue 24504 for reference.
+    """
+    q = Quaternion.from_euler((phi, 0, 0), 'zyz')
+    with warns(UserWarning, match='Singularity', test_stacklevel=False):
+        assert trigsimp(q.to_euler('zyz'), inverse=True) == (phi, 0, 0)
+
+
 def test_to_euler_numerical_singilarities():
 
     def test_one_case(angles, seq):