I made a shitpost about this in /mg/ a while back and thought it deserved a good explanation
For those who don't know:
Euler angles and quaternions are two methods of approaching rotation. Ea's consist of three angles usually denoted theta1, t2, and t3, and q's are an extension of complex numbers comprising of w + xi + yj + zk which have a bunch of wierd rules. Basically, any vector can be rotated by multiplying it by matrices constructed from the components of these numbers, and they can be converted to each-other by setting matrices of each type equal to each-other.
I found these notes which outline a conversion between euler-angles and quaternions which loses the signs of w, x, y, and z, but otherwise works:
s(n) = sin(t.n), c(n) = cos(t.n)
M(r) = matrix formed from euler angles t.1, t.2, t.3
T = trace(M(t)) = c(2)c(3) + c(3)c(1) + c(1)c(2) + s(1)s(2)s(3)
|w| = sqrt((T + 1)/4)
|x| = sqrt((M(t).11)/2 + (1 - T)/4)
|y| = sqrt((M(t).22)/2 + (1 - T)/4)
|z| = sqrt((M(t).33)/2 + (1 - T)/4)
Obviously, if any component of q (w, x, y or z) is supposed to be negative, the conversion will mess up. Through some testing i figured that the signs only desync when they approach and eventually "bounce" off zero when they should be passing through it, so I set each of the right-hand expressions above equal to a value that approaches 0 in Desmos to see where these boundaries converge (attached image shows bounds across t.1 on the x axis and t.2 on the y axis when t.3 = 0.2).
If I could define these boundaries as a combination of continuous functions, I could convert euler to q properly. Nevermind just, idk, testing different sign combos and returning the one that converts back correctly, that would make too much sense.
The fact that there are 100 easier ways to do this is what made this little project so funny to me that i shitposted about it in /mg/ where nobody else would be sane enough to tell me it wasn't that funny.
Continued explanation in the reply.
For those who don't know:
Euler angles and quaternions are two methods of approaching rotation. Ea's consist of three angles usually denoted theta1, t2, and t3, and q's are an extension of complex numbers comprising of w + xi + yj + zk which have a bunch of wierd rules. Basically, any vector can be rotated by multiplying it by matrices constructed from the components of these numbers, and they can be converted to each-other by setting matrices of each type equal to each-other.
I found these notes which outline a conversion between euler-angles and quaternions which loses the signs of w, x, y, and z, but otherwise works:
s(n) = sin(t.n), c(n) = cos(t.n)
M(r) = matrix formed from euler angles t.1, t.2, t.3
T = trace(M(t)) = c(2)c(3) + c(3)c(1) + c(1)c(2) + s(1)s(2)s(3)
|w| = sqrt((T + 1)/4)
|x| = sqrt((M(t).11)/2 + (1 - T)/4)
|y| = sqrt((M(t).22)/2 + (1 - T)/4)
|z| = sqrt((M(t).33)/2 + (1 - T)/4)
Obviously, if any component of q (w, x, y or z) is supposed to be negative, the conversion will mess up. Through some testing i figured that the signs only desync when they approach and eventually "bounce" off zero when they should be passing through it, so I set each of the right-hand expressions above equal to a value that approaches 0 in Desmos to see where these boundaries converge (attached image shows bounds across t.1 on the x axis and t.2 on the y axis when t.3 = 0.2).
If I could define these boundaries as a combination of continuous functions, I could convert euler to q properly. Nevermind just, idk, testing different sign combos and returning the one that converts back correctly, that would make too much sense.
The fact that there are 100 easier ways to do this is what made this little project so funny to me that i shitposted about it in /mg/ where nobody else would be sane enough to tell me it wasn't that funny.
Continued explanation in the reply.