Git Product home page Git Product logo

Comments (1)

moble avatar moble commented on July 29, 2024

The short answer to your question is: the two functions as_spherical_coords and from_spherical_coords are not inverses, so you can't expect to get the same thing out as you put in. Only one scheme is used for spherical coordinates, and what you're seeing is consistent with what I expect.

First, I should point out that I use the physics convention for the coordinates (theta, phi):

In particular, both (0, pi) and (0, pi/2) represent the north pole. In this sense, the result you're seeing is correct.

More precisely, if you do help(quaternion.as_spherical_coords) you'll see that as_spherical_coords returns coordinates to "the point on the sphere to which the input quaternion rotates the z axis", which is indeed what you're getting β€” it's just that spherical coordinates are singular at that point. Alternatively, you could note that the Returns section of the docstring says that the returned (theta, phi) coordinates give the input rotation up to an arbitrary initial rotation about z β€”Β which is needed because spherical coordinates simply cannot represent an arbitrary rotation.

FYI: The implementation of as_spherical_coords is here. You will see that I define the spherical coordinates as just a subset of the Euler angles. And if you then read the docstring for as_euler_angles, you will get an idea of what I think of Euler angles.

I could have made a different choice that would have been better for precisely the north and south poles, but I don't know that it actually matters. If it matters to you, I suggest redefining the function along these lines:

def as_spherical_coords(q):
    alpha, beta, gamma = as_euler_angles(q)
    if beta < 1e-15:
        return beta, alpha+gamma
    elif pi-beta < 1e-15:
        return beta, alpha-gamma
    else:
        return beta, alpha

You would need to test that because I may have gotten some signs wrong. You might also want to make it work with general arrays of quaternions like the original function. But this is complicated enough that I don't know any case where it would be worth the trouble.

from quaternion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.