Quaternion rotation problem

Posted on 2011-10-27
Last Modified: 2013-12-26

I am trying to determine Eular angles [roll, yaw, pitch] from Quaternions [w, x, y, z] which are being streamed to me from a PS3 Move controller. If I don't rotate the controller and just move it then the eular angles I derive from the quaternions match the controller position. e.g If the quaternions I get back are [w = 0.89, x = 0.37, y = 0.23, z = -0.09] the Eular angles I derive are [roll = 0, yaw = 28, pitch = 46], which is what I expect. Now if I dont move the controller just rotate it around it's own axis then the Eular's I derive from the quaternions suggest that my pitch and yaw have changed. e.g. If I dont move the controller from the earlier mentioned position and just rotate it 35 degress then the quaternions I get back are [w = 0.83, x = 0.29, y = 0.33, z = -0.34] which map out to Eular angles [roll = -20, yaw = 50, pitch = 50]. The answer I am looking for is [roll = 35, yaw = 28, pitch = 46].

The formulas I have tried for conversion from Quaternion to Eular are

yaw = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
roll = asin(2*qx*qy + 2*qz*qw)
pitch = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

and the one's mentioned on wikipedia

but I have not had any luck.

Any ideas, suggestions or formula's will be highly appreciated.

Question by:rpotash
    LVL 12

    Expert Comment

    I don't think there's anything wrong with the formula.  My guess is that the values are returned in the order, x-y-z-w rather than w-x-y-z as you have described them.
    LVL 12

    Expert Comment

    Notice that what you have as the z-value changes most as you change the angle of the controller.

    Accepted Solution

    I think the values are fine because the yaw pitch numbers come back correct as long as I dont rotate the controller. I found a solution that works for me at The guy takes the quternion and applies a transformation to a unit vector. The dot product between the transformed vector and the original give me angles I need.

    Thanks for your help
    LVL 12

    Expert Comment

    The yaw and pitch might be OK because the middle two of the values in x-y-z-w and w-x-y-z would be used correctly by the algorithm.  They may end up in the wrong axis, but that depends on the coordinate system in use.  Still, you have an answer that works, problem solved.

    Author Closing Comment

    The link works for me, but might not work for everyone. It was not easy to find the solution to this problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Preface ====== What is a video game console? Wikitionary, the free online dictionary sponsored by Wikipedia states that a video game console is "A dedicated electronic device that is designed to play video games, especially in accompaniment with a…
    Whether you're new to the game or an experienced player, you can never get enough help trying to have the best Pokémon. This guide will do its best to serve and be a living document.  It will evolve as I have more things to add or change.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now