Talk:Conversion between quaternions and Euler angles

Needs to be explicit that this rotates a body

edit

I was looking for the euler 123 to quaternion conversion that will rotate from one frame to another. The euler to quaternion conversion shown on the page does not line up with the SpinCalc euler 123 conversion from Matlab Central. Maybe the equation on the page rotates the points in a body while keeping the reference frame the same?

From SpinCalc.m with scalar at 4th position

Q=[s1.*c2.*c3+c1.*s2.*s3,   c1.*s2.*c3-s1.*c2.*s3,   c1.*c2.*s3+s1.*s2.*c3,   c1.*c2.*c3-s1.*s2.*s3];  —Preceding unsigned comment added by 128.157.160.13 (talk) 22:42, 3 September 2009 (UTC)Reply 


Are the "Euler angles" in this article really Tait-Bryan_angles?

Canonical form of quaternion?

edit

The equation presented for conversion from Euler angles to Quaternion has several discontinuities that are not necessarily present in the Quaternions themselves.

For instance, for the Euler angles (0,0,-180) and (0,0,180), the conversion would produce the quaternions (0,0,0,1) and (0,0,0,-1). These refer to the same attitude, but linear interpolation or slerp between them would not work well.

It appears that the proper way to handle this is to compute the cosine of the angle between the quaternions (via the dot product) and if this is less than zero to negate one of the quaternions.

Which definition of the Euler angles is being employed in this page?

edit

Absolutely no mention is given as to which (of the 12 possible) definitions of the Euler angles are being employed in this discussion.


I agree. This seems to be using the Tait-Brain (or whatever spelling) convention.

This one here is the standard: https://hepweb.ucsd.edu/ph110b/110b_notes/node36.html . It uses the sequence z-y-z, with notation phi, theta, psi. We can easily verify that the formulas given on this page are wrong for that standard, by computing omega once from phi,theta,psi and their derivatives, and once from the quaternion q as per the presented formula her, and its derivative dq.

This article is frustrating because it pretends a hands-on appeal ("just pick up the equations and use them for your project") when in fact they are plainly incorrect. I only noticed it when GPT pointed me to where it came up with those inconclusive equations; so you are doing a lot of damage here. I propose we pull this article offline until it is correct and verified to be correct. And since we can verify correctness of algebra, I would suggest we go ahead and do this for all Wikipedia articles that feature any formulas. — Preceding unsigned comment added by 31.17.92.45 (talk) 11:21, 29 October 2024 (UTC)Reply

Totally agree, this page does not make much sense.
I personally think this page should be scrapped, condensed to a little section called "conversion between ZYX Tait-Bryan angles and quaternions" that only gives out the equations, explains why this sequence is being given particular interest (because it's the most used) and then add it to the main page called Quaternions and spatial rotation.
This would be MUCH less confusing, in my opinion, and still gives the formula in a "just pick up the equations and use them for your project" way, albeit more explicitly. Ebernardes (talk) 11:44, 29 October 2024 (UTC)Reply

Order of angles specified?

edit

Does the order of rotation (described as "in the order yaw, pitch, roll" in first section) match the matrix given in "Rotation matrices" section? That matrix corresponding to rotation with Euler angles can be given by (Rz (Ry Rx)). Isn't that in the order x,y,z instead? — Preceding unsigned comment added by 144.212.114.62 (talk) 22:25, 2 December 2006 (UTC)Reply

Matrix convention

edit

It should be stated what the convention being used for the rotation matrices is. Is it supposed to be pre-multiplied by a row vector or post-multiplied by a column vector? Icalanise (talk) 23:18, 21 October 2008 (UTC)Reply

someone seems to be confused. "The orthogonal matrix (post-multiplying a column vector) corresponding to a clockwise/left-handed rotation by the unit quaternion q=q_0+iq_1+jq_2+kq_3 is given by the inhomogeneous expression"
If you are using a column vector then the matrix is on the left of the vector and that would appear to be pre-multiplying, not post-multiplying.Eregli bob (talk) 12:17, 28 October 2012 (UTC)Reply

Euler Conversion

edit

Is the displayed formula correct? The link in the singularity section (http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/) displays a different formula ... —Preceding unsigned comment added by 83.171.153.247 (talk) 18:07, 1 March 2009 (UTC)Reply

Could this be because the article uses a left-handed rotation (as specified on the paragraph giving the matrix for x-y-z convention rotation) ? I'mt not sure, but I think there are a LOT of different ways to convert quaternions to euler angles. See http://www.cgafaq.info/wiki/Euler_angles_from_matrix for example.
Basically, if someone knowledgeable enough could rewrite the part on conversion to discuss the various possibilities, that would be very nice. 81.63.104.6 (talk) 20:22, 8 May 2012 (UTC)Reply

The final matrix in the "Rotation Matrices" section corresonds to "ZYX" ordering, as per page A-11 of the NASA memo in the references; I've verified that the expression for the quaternion conforms to the same convention. — Preceding unsigned comment added by 50.76.20.17 (talk) 22:12, 14 January 2014 (UTC)Reply

The 'source code' for the quaternion-to-Euler angle conversion doesn’t match the vector representation immediately above it. SimonJWright (talk) 16:32, 6 December 2016 (UTC)Reply

Error in Quaternion to Euler Angles Conversion

edit

The Quaternion to Euler Angles Conversion when used with a Quaternion created with Euler Angles to Quaternion Conversion does not provide back the same Euler angles originally used for input. Take for example inputs for creating the quaternion of roll = 180, pitch = 90, yaw = 45, if you create a quaternion using the ToQuaternion() function and then use the result as input for ToEulerAngles() the result is roll = 180, pitch = 90, yaw = 26.565. This is likely due to multiple sets of Euler angles satisfying any quaternion, but the page should make that more clear. Drankinatty (talk) 04:27, 11 February 2020 (UTC)Reply

The C++ code got the pitch computation wrong it should be:
double sinp = std::sqrt(1 + 2 * (q.w * q.y - q.x * q.z))
double cosp = std::sqrt(1 - 2 * (q.w * q.y - q.x * q.z))
Rather than:
double sinp = std::sqrt(1 + 2 * (q.w * q.x - q.y * q.z));
double cosp = std::sqrt(1 - 2 * (q.w * q.x - q.y * q.z)); Rfspadaro (talk) 18:20, 5 January 2023 (UTC)Reply

Matrices and handedness

edit

The matrices given are for left-handed systems, whereas the drawing uses a right-handed convention. There is no way a beginner in the field can make sense of what is explained. Sam Hocevar (talk) 11:21, 30 April 2012 (UTC)Reply


== This should be updated because normally the diagrams are supporting the conversation and instead they are directly opposite of what the article is discussing. Would be better if this article was written in right handed notation since that is the most common and the pictures kept.

The reference does not exist anymore!

edit

As above — Preceding unsigned comment added by 128.2.176.70 (talk) 16:16, 11 June 2013 (UTC)Reply

If someone needs a quaternion-to-Euler method that actually seems to work,...

edit

...then check this out.

http://bediyap.com/programming/convert-quaternion-to-euler-rotations/ [dead] --> https://web.archive.org/web/20210410215436/http://bediyap.com/programming/convert-quaternion-to-euler-rotations/

I haven't checked if it works, and I don't know the usage rights or licenses that apply to it (if any), but it accounts for multiple sets of Euler angles and it actually tells you which math goes with which set, so it's already better than this article by a mile. 108.3.188.161 (talk) 01:48, 22 July 2014 (UTC)Reply

Sign of pitch angle

edit

In the second figure, showing the Tait-Bryant angles for an aircraft, the upwards pitch is labelled in the figure as negative theta. This pitch angle would be positive, it is counter-clockwise if you were remotely located on the aircraft's Y axis sticking out of its right wing direction.Lathamibird (talk) 07:10, 2 June 2015 (UTC)Reply

Euler Magic Squares

edit

It says in the introduction Euler used quaternions for Magic squares. This seems unlikely as the math is completely unrelated. Can somebody figure out if there is some way this is true and maybe fix the link?

This page says it deals with JPL quaternions, and I think it's not quite right

edit

At the beginning of the section Definition, it's written "For the rest of this article, the "passive" JPL quaternion convention shall be used." There are two problems with this:

1) I don't think this is right, both the rotation matrix and the quaternion product formulas seem to be consistent with Hamilton matrices instead.

2) The page Quaternions and spatial rotation makes very valid points on why Hamilton quaternions should be favored, so using only Hamilton quaternions here should be preferred. Ebernardes (talk) 14:31, 18 December 2022 (UTC)Reply

Changed the quaternion to Euler angles conversion formula

edit

This new one has no numerical problems for the pitch. For anyone interested, I'll leave here a simple Python snippet that test both expressions to show they are equivalent:

import numpy as np
from itertools import product

for w, x, y, z in product([-1, 0, 1], repeat=4):
    n = np.sqrt(w**2 + x**2 + y**2 + z**2)
    if n > 10e-7:
        w /= n
        x /= n
        y /= n
        z /= n

        sinp = np.sqrt(1 + 2 * (w * x - y * z));
        cosp = np.sqrt(1 - 2 * (w * x - y * z));
        pitch1 = 2 * np.arctan2(sinp, cosp) - np.pi / 2;

        pitch2 = np.arcsin(2 * (w * x - y * z))

        assert (pitch1 - pitch2) < 10e-7

Ebernardes (talk) 16:41, 18 December 2022 (UTC)Reply

---

@Ebernardes:, I think you are referring to this revision you made, right?: https://en.wiki.x.io/w/index.php?title=Conversion_between_quaternions_and_Euler_angles&diff=1128143523&oldid=1128124788

And I think in your code above, pitch1 is the new code, and pitch2 was the old calculation, right? What are the problems with pitch2? Why is using pitch1 better? Also, you have a typo I believe: it should be pitch2 = np.arcsin(2*(w*y - z*x)). You have w*x mistakenly where w*y goes. --ERCaGuy (talk) 03:55, 12 October 2023 (UTC)Reply

Hey there @ERCaGuy, thank you for your interest! Indeed, there is a typo! But since I did the same typo twice it still passed the test: the important where was to numerically show that, for our values,   for some value of  .
As to why this is arguably better, there was an explanation but it was removed in this edit: https://en.wiki.x.io/w/index.php?title=Conversion_between_quaternions_and_Euler_angles&oldid=1128353649.
Basically,   are not as numerically well-behaved as  , which is why we used this version when I updated the transformation code in https://scipy.org/. This is, in my opinion, still not the best version, as this needs the quaternion to be normalized beforehand and the (because of the summation with 1, etc).
If you're interested, I showed how to get these equations on this open access paper: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0276302. Moreover, apart from Scipy, I also implemented it on Sympy, which can be useful if you want to play with the equations symbolically. Ebernardes (talk) 06:51, 12 October 2023 (UTC)Reply
Just a heads-up though: the first definitions on this paper have sadly a mistake, and I still didn't manage to make the editors correct it... Ebernardes (talk) 06:51, 12 October 2023 (UTC)Reply
@Ebernardes, thank you for all of the responses and links! This is helpful. For anyone wishing to have some Python code to use and test, here is my quaternions_to_euler_angles.py Python program from my eRCaGuy_hello_world repo. I test both techniques. See functions quaternion2euler() and quaternion2euler2(). I run unit tests on them both too. — Preceding unsigned comment added by ERCaGuy (talkcontribs) 16:24, 19 October 2023 (UTC)Reply
@ERCaGuy I'm glad I could help! If you're interested, you can find my implementation of the general method in my repo.
Moreover, in the SciPy implementation there are also two implemented conversion methods: an older one from matrix to angles, and the one I published from quaternions directly to angles. The former is not used anymore, except for the unit tests: we wanted to make absolutely sure that the new conversions gave the same answers. Ebernardes (talk) 07:40, 20 October 2023 (UTC)Reply

Cleanup

edit

This article reads like a stream of consciousness university lecture, rather than a Wikipedia article. I personally find the inclusion of sample code to be particularly out of place, but the POV of the article is really strange as well. I recommend that it be cleaned up. TimeEngineer (talk) 13:52, 28 January 2024 (UTC)Reply

I totally agree that this is a strange page. I do not really have the time to attempt rewriting it, but I'm up for helping with the math if a rewrite is ever done. Ebernardes (talk) 13:35, 29 August 2024 (UTC)Reply