Good day everyone. I would like to lock the rotation about one specified axis. For example, let`s imagine that we have a quaternion which desribes the orientation of our rigid body relative to the global frame - $q$ To null the rotation about z-axis in global coordinate frame i do the following:
- Convert the conjugate quaternion $q^{-1}$ to euler angles.
- Zero the yaw (heading) angle (it is the same as rotation about z-axis in global coordinate frame)
- Convert the euler angles back to the quaternion.
After these steps i have an orientation which rotates only about $X$ and $Y$ axes in global coordinate frame, but not about $Z$ frame.
The question is - are there any more efficient alternative for this problem? May be someone has some examples for this problem in Matlab? Thanks.
Update: Today i tried an approach suggested by rschwieb. Imagine that i have a vector (magnetometer readings), measured in sensor frame and i want to represent this vector in world coordinate frame but ignore the rotation around Z-axis (parallel to the gravity vector). Also I have a quaternion $q$, which describes the sensor orientation relative to the global frame. To do so i use the following scheme.
- Represent the vector, orthonormal to Z-axis, in sensor frame (for example, it can be x-axis): $x' = qxq^{*}$, where $x = [1;0;0]$
- Project the transformed vector onto the plane: $p = z' - (dot(z', z)z)$ and then normalize it
- Find an angle between the projected vector and orthonormal one, $\theta$
- Build new quaternion: $q_{n} = [cos(\frac{\theta}{2}); sin(\frac{\theta}{2})z_x; sin(\frac{\theta}{2})z_y; sin(\frac{\theta}{2})z_z;]$
- Multiply new quaternion with original one: $q_{nulled}^{z} = qq_n$
- Transform vector from sensor coordinate frame to global, but ignore rotatione about z-axis: $z = q_{nulled}^{z}*m*q_{nulled}^{z*}$ , where $m$ - magnetometer readings. What i expect to see: the magnetometer readings, presented in global coordinate frame but without rotation about Z-axis. What i get: the magnetometer readings, which seems to be right, but they flip over when i change the orientation of the sensor.
Update2 This method gives the same results as an extraction of the roll and pitch angles from quaternion and then use this angles to transform the vector to the global coordinate frame. With both methods i keep getting the change of the sign of the vector when turning upside down the device around global Z-axis. Are there any legit ways to prevent it? I have a similar problem to this one: https://stackoverflow.com/questions/20821233/tilt-compensation-doesnt-work-with-pitch-bigger-than-90-degrees
Ok, i am stuck with this question - if someone has any thoughts, let me know please.