Mollymews Posted May 10, 2021 Share Posted May 10, 2021 for the wiki then I think what is important is that the reader gets an understanding of what is meant by the order of operations. Quistessa's code shows this quite well i have tidied the code up a little format-wise so is clear to the reader what the order of operations is. Euler2Rot encodes Z then Y then X. Rot2Euler decodes in reverse order: X then Y then Z and it is this understanding which the wiki should impart to the readers example tidy up: (i have prefaced the functions with q for Quistessa) rotation qEuler2Rot(vector euler) { euler *= 0.5; return // z-axis <0.0, 0.0, llSin(euler.z), llCos(euler.z)> * // y-axis <0.0, llSin(euler.y), 0.0, llCos(euler.y)> * // x-axis <llSin(euler.x), 0.0, 0.0, llCos(euler.x)>; } vector qRot2Euler(rotation rot) { vector euler; vector temp; // x-axis temp = <0.0, 0.0, 1.0> * rot; euler.x = llAtan2(temp.z, temp.y) - PI_BY_TWO; rot /= llEuler2Rot(<euler.x, 0.0, 0.0>); // y-axis temp = <0.0, 0.0, 1.0> * rot; euler.y = -llAtan2(temp.z, temp.x) + PI_BY_TWO; rot /= llEuler2Rot(<0.0, euler.y, 0.0>); // z-axis temp = <1.0, 0.0, 0.0> * rot; euler.z = llAtan2(temp.y, temp.x); return euler; } Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted May 10, 2021 Share Posted May 10, 2021 On 5/6/2021 at 3:24 PM, Quistessa said: Your algorithm seems to use the standard pitch-yaw-roll convention. SL doesn't. I've jut realised the significance of this: Most of the explanatory articles about using quarternions do follow the pitch-roll-yaw model, so I too have always done so, but I now see from both your comment and reading through another article that SL inverted the way quarternions generally worked. Is it only when trying to convert between the two formats that this becomes significant? Link to comment Share on other sites More sharing options...
Quistess Alpha Posted May 10, 2021 Author Share Posted May 10, 2021 (edited) 1 hour ago, Profaitchikenz Haiku said: Is it only when trying to convert between the two formats that this becomes significant? Yes, the only significant differences between LSL Rotations and Standard-definition quaternions are: 1. In LSL quaternions are specified <i,j,k,r> with the real component last. nost textbooks and the like will put the real component first. 2. In LSL multiplying two rotations p and q : p*q has the effect of rotating by p, then q. Outside LSL p*q has the effect of rotating by q then p. These differences don't really have any relation to any specific Euler representation of the quaternion (remember there are 12(+?) viable specifications/Euler formats) If you can wrap your head around the 2d complex case where the product is the same as adding the angles: (cos(a)+i*sin(a))(cos(b)+i*sin(b)) = (cos(a)cos(b)-sin(a)sin(b))+i(cos(a)sin(b)+cos(b)sin(a)= cos(a+b)+i*sin(a+b) (provable using either Euler's formula e^(it)=C(t)+iS(t) ; e^(ia)*e^(ib)=e^(ia+ib) or by justifying the trig identities) it's not then hard to justify to yourself that the same should (and does) hold in the case of quaternions i,j,k. All that's left at that point to actually do quaternion computations yourself is to justify the products of i j and k (draw an xyz coordinate axis, following the right hand rule: i rotates y->z ; j rotates z->x ; k rotates x ->y; then that for example both 'i then j' and '-k' take y->x should be obvious) and to justify the actual computation that to rotate a vector v (represented by a quaternion <x,y,z,0>) by quaternion q you need to sandwich the vector by two quaternions (rotate (1/q)*v*q by sl convention quaternions,( backwards otherwise)) to keep the result in the r=0 subset (useful for the algebra to know that 1/<a,b,c,d> = <-a,-b,-c,d>/(aa+bb+cc+dd) and for normalized quaternions (aa+bb+cc+dd)=1 (by definition)) this sandwiching doubles the angle applied to v. What I haven't found an easy way to explain yet is why the axis angle translation (<X,Y,Z>,Th*2) = <s(th)X,s(th)Y,s(th)Z,c(th)> makes sense. (thinking in 4 dimensions, if you imagine a graph of the complex plane (i going up r going right) the r-j and the r-k planes, it makes a little sense, not entirely obvious to me that you can decompose a rotation like that though.) Edited May 10, 2021 by Quistessa Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now