DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D

Home Page:http://www.reactphysics3d.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get axis angles?

TheBoneJarmer opened this issue · comments

Hey

How can I get the axis angles from a quaternion? I read the docs but they made no sense to me at all. All I want is a Vector3 object with the axis angle degrees as values. Any help would be greatly appreciated!

I also happen to notice I am not the first one to ask this. Its a piece of cake to get the position from a RidigBody from example but retrieving the axis angles should not be this difficult. Maybe an idea to add a method to the Quaternion class like Vector3 Quaternion::getAxisAngles() for example? Heck, I'm happy to send in a PR myself once I figure it out. lol

That said, I delved into the subject a bit further but I fail to hack through it. I am not interested in getting too involved with math although I feel like I am not having that much of a choice. From what I understand so far is that a quaternion can be created from euler angles. But so far I thought euler angles were just axis angles in radians. But that seems not to be the case. Google results make me more confused than wiser in that regard despite I feel like I am close to a solution.

With kind regards,
TheBoneJarmer

Hello.

The library does not offer a way to get Euler angles from a quaternion. You can get the axis of rotation and angle around this axis using the Quaternion::getRotationAngleAxis() method.

Note that you should really try to work with quaternions for orientation instead of Euler angles but if you really want to extract Euler angles from the quaternion, you need to it yourself. For instance, you might try to use this.

Could you please post your questions in the Discussions section instead of opening an issue.

Thanks a lot for your reply and my apologies for not using the discussions section. Should I have any questions in the future, I will use the discussions section.

I gave that method a try but the values make no sense to me. I expected a vec3 containing the yaw, pitch, roll values in radians. Which in turn I could translate to a degree between 0 and 360. However, what I get instead is an angle and an axis. How can I convert that angle and axis to yaw, pitch and roll?

That said, I also would like to share that since I opened up this issue I decided to invest more time in learning more about quaternions and euler angles. And so far I have to admit I became more confused than wiser. I thought euler angles were the yaw, pitch and roll I talked about in my last paragraph but I have seen SO articles and blog posts that made me believe otherwise. On top of that when I make a quaternion using the values 45, 270 and 180 (in radians obviously) respectively I don't get the desired result. So it only confirms my expectation that euler angles are not the same as yaw, pitch and roll.

Note that you should really try to work with quaternions for orientation instead

This I learned as well. It seems more clear to make that using quaternions instead of euler angles is the best decision. I kept reading over and over that using euler angles could result in a so called Gimbal lock right? I have yet to learn the subject. Speaking of, if that is okay with you I like to ask some questions here related to quaternions. You are definitely the expect on the subject here and like I mentioned, researching it myself made me more confused. I am not a math expert and I like to stick to the upmost basics. I am willing to learn however what I must but I learn best by example and not so much from a book. So please, do not refer me to a complicated wiki page. I have seen those enough by now. lol

  • Are euler angles the same as yaw, pitch and roll? If not, how can I convert yaw, pitch and roll to euler?
  • If possible to explain briefly, what is the Gimbal lock?
  • Is the order of axis angles relevent in a quaternion and if so, are you using the XYZ standard?

I am cool with opening up an discussions thread as well with the above questions if you desire so. But I figured since I already (wrongly) opened this issue here, I might as well use this thread.

So hey, as a follow up. I still have not figured out how to convert a quaternion to euler angles and after days of research I decided to give up the idea of easing euler angles at all. Henceforth I decided to throw out that part and convert every rotation in my library from Vector3 to Quaternion. And this solved my problem too.

Also, I was able to use GLM to construct a model matrix from your Quaternion class resulting in cubes that now rotate very fluently and correctly. And thanks to your Quaternion::fromEulerAngles method I was able to construct quaternions as well. So my needs are covered.

Hi, I am glad that you figured something out. You will see that working with quaternions is much better for computer graphics even if it seems difficult to directly see what this mathematical object represent in 3D.

Here are some articles that can be useful to learn about quaternions: