How to get the rotation matrix and associated Euler Angles for the rotation of 3D objects depicted by the coordinates of its vertices
6 views (last 30 days)
Show older comments
How to get the rotation matrix and associated Euler Angles for the rotation of 3D objects depicted by the coordinates of its vertices - a Nx3 matrix.
I wanted to use six variables, three translation VT(DX, DY, DZ) and three rotation angles VR(Alpha, Beta, Gamma), to represent the transformation of a rigid 3D object composed of multiple vetices from one location to another with both translation and rotation in a 3D space.
The translation and rotation are handled separately. The coordinates of vertices of the object is now saved in an Nx3 matrix A where N is the number of vertices of the object. The coordinates of the vertices of the object after rotation and translation is a new Nx3 matrix B. Both A and B are known.
What I want to get is the six variables in VT and VR. Here is how I plan to it.
First, I use Matlab function [mean] to get the center coordinates of A and B with mean(A) and mean(B). Then the translation vector is: VT(DX, DY, DZ) = mean(B) –mean(A). For the rotation, using B’ = B – ones(N,1)* VT, I move B to A so that their centers overlap. So, basically the pure rotation from A to B will be that from A to B’ with respect to the center of A (and B').
To get the 3x3 rotation matrix R between A and B’, I use the Matlab code rigid_transform_3D.m developed by Nghia Ho at http://nghiaho.com/?page_id=671 for a write-up "Finding optimal rotation and translation between corresponding 3D points". Then I got the rotation matrix R.
As mentioned earlier, I will need to depict the rotation using three Euler Angles instead of a 3x3 matrix. To get the three Euler Angles, I refer to the Matlab code spincalc.m developed by John Fuller for Matlab file exchange “Function to Convert between DCM, Euler angles, Quaternions, and Euler vectors”
However, I always get issues for obtaining rotation matrix R. For example A = [-1 -1 -2; -1 1 -2; 1 1 -2; 1 -1 -2; -1 -1 2; -1 1 2; 1 1 2; 1 -1 2] B = [-2 -1 1; -2 1 1; -2 1 -1; -2 -1 -1; 2 -1 1; 2 1 1; 2 1 -1; 2 -1 -1] The rotation between A and B is a -90 (Z to X) degree rotation of the object with respect to axis Y. However I got RMSE >>0 which means the function is NOT correct. RMSE is the error of the difference between B and the rotated A with the obtained rotation matrix. So, using the obtained ROTATION matrix to perform the rotation will not produce the desired result and it means - no correct ROTATION matrix has been calculated.
So, my effort is stopped at obtaining the ROTATION matrix without going into the sponcalc.m to get the three Euler Angles.
Anybody knows why and better solution?
Thanks...
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!