Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning for equatorial calculations above 89.99999 #10

Open
taldcroft opened this issue Sep 11, 2019 · 1 comment
Open

Warning for equatorial calculations above 89.99999 #10

taldcroft opened this issue Sep 11, 2019 · 1 comment

Comments

@taldcroft
Copy link
Member

We should include warnings for any attempt to initialize a quaternion, or compute equatorial, for abs(dec) > 89.99999. Below that it seems to be numerically stable.

The transforms to and from equatorial are numerically unstable for abs(dec) very near 90:

>>> q_bad = normalize([0.24184476, -0.66446302,  0.24184476,  0.66446302])
>>> q4 = Quat(q=q_bad)
>>> q4.equatorial
array([  0.        ,  89.99999915,   0.        ])

>>> q5 = Quat(equatorial=q4.equatorial)
>>> q5.q
array([ 0.        , -0.70710678,  0.        ,  0.70710679])

Teasing out the exact numerical problem is a little tricky, but for the q4.equatorial statement I include debug print statements in _quat2equatorial and got:

        xa = q2[0] - q2[1] - q2[2] + q2[3]
        xb = 2 * (q[0] * q[1] + q[2] * q[3])
        xn = 2 * (q[0] * q[2] - q[1] * q[3])
        yn = 2 * (q[1] * q[2] + q[0] * q[3])
        zn = q2[3] + q2[2] - q2[0] - q2[1]
...
        print(xn, yn, zn, one_minus_xn2)                                                                            
        print(xa, xb)                                                                                               
        ra = degrees(atan2(xb, xa))
        dec = degrees(atan2(xn, sqrt(one_minus_xn2)))
        roll = degrees(atan2(yn, zn))

[ 1.] [ 0.] [ 0.] [  2.22044605e-16]
[ 0.] [ 0.]

So basically ra = atan2(0, 0) and roll = atan2(0, 0).

@taldcroft taldcroft mentioned this issue Sep 11, 2019
@jeanconn
Copy link
Contributor

jeanconn commented Feb 7, 2020

Do we still want/need to do this? I'm concerned it has been so long we will misremember and think there's a warning in 3.5.0 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants