How to calculate yxy rotation sequence given the quaternion transformation and how to interpret data - matlab

Still need the math: I am trying to calculate the yxy rotation sequence given a quaternion transformation. I can easily do this using Matlab's quat2angle function. However, I need to calculate this by hand using a python script.
This part solved: Please look at this awesome presentation which helped me resolve these issues below:
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0CCoQFjAC&url=http%3A%2F%2Fwww.udel.edu%2Fbiology%2Frosewc%2Fkaap686%2Freserve%2Fshoulder%2Fshoulder%2FBluePresentation.ppt&ei=jgRAVLHfOsSrogTJiYHABQ&usg=AFQjCNGFmwh11jEZen80jc3tM4f7HUQcNw&sig2=Dlr8_7TIFPLyUfJy6-pSJA&bvm=bv.77648437,d.cGU
Also, with Matlab, I am seeing strange results with the way they calculate yxy. I have a quaternion transformation of [1.0000 -0.0002 -0.0011 -0.0006] and I get y = 112.4291 x = -0.0719 y1 = -112.5506 (in degrees).
I don't expect to see any rotations here (my sensors aren't rotating). Why is Matlab showing me rotation? And when I try to just move in the x rotation, I see y and y1 also rotate, however, I don't expect y or y1 to be rotating. Any thoughts?
UPDATE:
When I add y + y1 I seem to get the value for the first y (when doing simple rotation around the first y), and this smooths out the data. However, when I combine the three rotations of the shoulder, the data doesn't make sense. I am trying to define shoulder movement based on plane of elevation, elevation and rotation (yxy) in a way that's easy to interpret. When I rotate around x, then the second y, I get "clipping" (data goes to 180 then -180 following positive trend for y1 and opposite happens for y), even though I start my sensors at the zero position. Also, If I try to rotate only around the second y, I see rotation in the x. That doesn't make any sense either. Any additional thoughts?
Note:
I am using 2 IMU sensors, taring them in the same orientation, holding one constant and rotating the other, calculating the relative rotation between them using quaternions, and then calculating the yxy rotation sequence angles.

In case anyone is interested in quaternion calculations and transformations. I solved it using this transformations library:
http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
There are several functions in here using matrices, quaternions, and Euler rotations. And you can convert quaternions to several different Euler rotation sequences. Give thanks to the person who created this script.

Related

Using scipy package, which sequence to choose for Rotation.as_euler()

I'm trying to convert from quaternion to row pitch yaw using the as_euler() function, but I don't know which sequence to choose as the parameter "zyx", "xyz", "zyz", etc
Also what is the order of the output euler angles? Is it going to be [roll, pitch yaw] or [yaw, pitch, roll]?
Much thanks!
Yaw, pitch, roll axes are used for rotation around its principal axis sequentially. there exist twelve possible sequences which are;
Proper Euler Angles "z-x-z, x-y-x, y-z-y, z-y-z, x-z-x, y-x-y"
Tait–Bryan angles "x-y-z, y-z-x, z-x-y, x-z-y, z-y-x, y-x-z"
Most common usages is z-y-x in Tait-Bryan angles. "yaw" means rotate around z axis, "pitch" means rotate around y axis, "roll" means rotate around x axis.
If you use z-y-x order the euler-angles order is [yaw, pitch, roll]. You must choose the order depending on what field you work in.

Computing Euler angles from rotation matrix: boundary cases

I want to compute the Euler angles from a rotation matrix in order to find out the orientation associated to that rotation. For that purpose, I am using MATLAB and the function rotm2eul that gives me the rotation first about x-axis, then about y-axis and finally the z-axis.
I am using a signal with 1000 frames and for each frame a rotation matrix is computed, as well, the three Euler angles. However, when I am going to see the Euler angles' curve, there is some "jumps" as I shown on the figures below.
On Technique 1, I think it jumps from -180º to 180º which should be the same. In fact, the upper portion of the plot seems a continuation of the lower portion. So in this case I thought I could subtract 360º to the upper portion to get the plot. But I am not sure if I do this I am falsifying the results.
On Technique 2, it makes a jump with a different reason of the previous one. I think it must be because the angle associated with the y-axis reaches 90º which should be a boundary case. But in this case I don't know how should I correct the data or , like previously, if I want to correct the plot is falsifying the euler angle result.
Technique 2: This is a Gimbal lock, known feature of Euler angles. You can't avoid it completely. You can change the rotation order, but it will appear in another position.

Simulink 3D Animation using VRML

I've set up an animation of a tugboat [from VRML library] using the Virtual Reality Animation objects. but am having trouble with viewing the rotation of the boat.
To be more specific: I have a simulator going, where I calculate from rigid body dynamics the trajectory of it in time. This is, I have x, y, z, phi, theta, psi vs. time. I associate the translations and rotations to the node corresponding to the boat. When pressing play, I can see the translation and rotation which is not as expected.
Not sure what the problem could be. I tried to add one Transform in the .wrl for each of the rotational degrees of freedom, but I found it weird as when I give rotation in one direction I see the object rotating and translating other directions as well.
Any help is most welcome.

Creating stereoParameters class in Matlab: what coordinate system should be used for relative camera rotation parameter?

stereoParameters takes two extrinsic parameters: RotationOfCamera2 and TranslationOfCamera2.
The problem is that the documentation is a not very detailed about what RotationOfCamera2 really means, it only says: Rotation of camera 2 relative to camera 1, specified as a 3-by-3 matrix.
What is the coordinate system in this case ?
A rotation matrix can be specified in any coordinate system.
What does it exactly mean "the coordinate system of Camera 1" ? What are its x,y,z axes ?
In other words, if I calculate the Essential Matrix, how can I get the corresponding RotationOfCamera2 and TranslationOfCamera2 from the Essential Matrix ?
RotationOfCamera2 and TranslationOfCamera2 describe the transformation from camera1's coordinates into camera2's coordinates. A camera's coordinate system has its origin at the camera's optical center. Its X and Y-axes are in the image plane, and its Z-axis points out along the optical axis.
Equivalently, the extrinsics of camera 1 are identity rotation and zero translation, while the extrinsics of camera 2 are RotationOfCamera2 and TranslationOfCamera2.
If you have the Essential matrix, you can decompose it into the rotation and a translation. Two things to keep in mind. First, the translation is up to scale, so t will be a unit vector. Second, the rotation matrix will be a transpose of what you get from estimateCameraParameters, because of the difference in the vector-matrix multiplication conventions.
Out of curiosity, what is it that you are trying to accomplish? Are you working with a single moving camera? Otherwise, why not use the Stereo Camera Calibrator app to calibrate your cameras, and get rotation and translation for free?
Suppose for left camera's 1st checkerboard (or to any world reference) rotation is R1 and translation is T1, right camera's 1st checkerboard rotation is R2 and translation is T2, then you can calculate them as follows;
RotationOfCamera2 = R2*R1';
TranslationOfCamera2= T2-RotationOfCamera2*T1
But please note that this calculations are just for one identical checkerboard reference. Inside matlab these two parameters are calculated by all given pair of checkerboard images and calculate median values as initial guess. Later these parameters will be refine by nonlinear optimization. So after median calculations they might be sigtly differ. But if you have just one reference point tranfomation for both two camera, you should use above formula. Note Dima told, matlab's rotation matrix is transpose of normal usage. So I wrote it as how the literature tells not matlab's style.

IOS openGL best way to rotate Sphere with touchesMoved

I drew Globe object using OpenGL and i can rotate it with finger touch , but it doesn't work well in some cases because i am rotating using the difference between x and y
Rotation3D rot = sphere.currentRotation;
rot.x += diffX ;
rot.y += diffY ;
rot.z += 10 ;
sphere.currentRotation = rot;
when you move your finger from Top Right to bottom Left it isn't work good.
Any ideas ?
Thanks
Peter Gabra
To arbitrarily rotate objects, it's easiest to store their current orientation as a transformation matrix and manipulate the elements. I explain this in detail here.
The only difference is that in that other question, the OP wanted to apply rotations from two controls (horizontal and vertical), whereas you are after drag-based rotation. The technique is basically the same, but instead of rotating around either the X or Y axis, you need to compute an arbitrary axis of rotation from the touch's delta vector as follows:
axis = [0, 0, 1] ⨯ [diffX, diffY, 0]
(⨯ = "cross product")
Then you rotate the U, V and W vectors (as described in my other answer) around the axis by some angle in proportion to the length of the delta vector:
M = rotation(k * length([diffX, diffY, 0]), axis)
U = M * U
V = M * V
W = M * W
If you find the object rotating in the opposite direction to what you expect, there are three possibilities:
If it's only the vertical rotation that goes the wrong way, you need to negate diffY. This is a common mistake I make due to inconsistencies between OpenGL and UIKit coordinate systems.
If it's all rotation, you can either swap the arguments in the cross-product or use [0, 0, -1]. This is usually because of confusion between left- and right-handed coordinate systems.
If it's just the horizontal rotation, make both adjustments. (Don't negate diffX, no one uses left-to-right X-coordinates.)
In case you're using Euler angles: I recommend not using Euler angles to model rotations. Use Quaternions instead. It might seem like it makes your code more complicated, but rotations work well when you use Quaternions. Here's some advantages:
it's very straightforward to apply user interaction to current rotation state
no gimbal lock problems
no need for matrix drift adjustments after repeated rotations
you can interpolate rotations easily
Note that Apple give you a Quaternion type to use: GLKQuaternion. No need to write your own Quaternion class.
See also:
http://www.ogre3d.org/tikiwiki/Quaternion+and+Rotation+Primer
Euler angles vs. Quaternions - problems caused by the tension between internal storage and presentation to the user?