Quaternion to Euler angle converter?
pmazzoni
Sat, 10/07/2023 - 01:05 pm
I would like to write a conversion function from (unnormalized) quaternions to Euler angles representing a 3D rotation (from accelerometer data). Does anyone have such a routine already written and is willing to share it? I know I am being lazy but I am new to quaternions and my head is already spinning (pun intended).
I wrote this some time ago, maybe it is of some use?
https://quantixed.org/2019/10/08/rotation-using-quaternions-in-igor-pro/
October 7, 2023 at 01:57 pm - Permalink
Thank you! I was looking for the inverse of your function, to convert quaternions back to angles, but I see that it's not that difficult to write, and the explanations on your post were very helpful.
October 7, 2023 at 03:12 pm - Permalink
It is not clear how you want to actually use or calculate the Quat-->Euler transformation. There is a method which avoids all calculation; simply use Igor's built in Gizmo operations. If you setup a dummy Gizmo, then (as an example)
•GetGizmo curRotation;print GizmoEulerA,GizmoEulerB,GizmoEulerC
32.6847 -36.4821 -11.8307
From this example, you should be able to write a simple wrapper function for the Quaternion input, that returns the global Euler angle outputs.
October 9, 2023 at 05:48 am - Permalink
First note that I do not recommend using Euler angles. There is a fair amount of literature that explains why using Euler angles is usually not a good idea.
However, if you need to convert from a quaternion to Euler angles and you have decided which formats you are using I'd get there in two steps:
1. Convert your quaternion to a rotation matrix. This is described e.g., here: https://automaticaddison.com/how-to-convert-a-quaternion-to-a-rotation-…
2. Convert the rotation matrix to Euler angles. This is described e.g., here:
http://eecs.qmul.ac.uk/~gslabaugh/publications/euler.pdf
Also, check out MatrixOP functions for quaternions: quatToEuler(qIn,mode) and quatToMatrix(qIn).
October 9, 2023 at 05:07 pm - Permalink
Thank you both to s.r.chinn and Igor.
s.r.chinn: I was not familiar with the capabilities of gizmo that you pointed out. Those are exactly the operations I was looking for. Thank you!
Igor: I think I am aware of the reasons not to use Euler angles in general. My purpose is to extract quaternion data into a form that I can use to create a plot. The links you provided will help me better understand quaternions and decide whether my intuition about how to visualize the rotations they represent is incorrect. Thanks!
October 18, 2023 at 07:58 pm - Permalink