Helo there. Can somebody please mod/update the templete to convert 3x3 matrix radians to euler degrees or radians and output them as X,Y,Z ? I have made a template for 010 Editor which parse data but i can't figure out code for converting matrices to euler. Order should be ZYX. Here's Template to mod. Thanks in advance!
Code: uint64 PHYSICS_MDL_TABLE_COUNT,NULL; struct{ struct { float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, POS_X,POS_Y,POS_Z,VAL12; uint FILE_ID0,FILE_ID1,FILE_ID0_TMP,FILE_ID1_TMP; Printf("File ID = %u File ID1 = %u\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\nPos X = %f\nPos Y = %f\nPos Z = %f\n\n",FILE_ID0,FILE_ID1,m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23,POS_X,POS_Y,POS_Z); }POS_XYZ[PHYSICS_MDL_TABLE_COUNT]<optimize=false>; }PHYSICS_MDL_POS_TABLE;
BTW i used this online converter Code: http://www.andre-gaschler.com/rotationconverter/ which works, but i am not sure how precise it is. So i would like to see real values from a file. EDiT: Here's some code in C++
Code: // Checks if a matrix is a valid rotation matrix. bool isRotationMatrix(Mat &R) { Mat Rt; transpose(R, Rt); Mat shouldBeIdentity = Rt * R; Mat I = Mat::eye(3,3, shouldBeIdentity.type());
return norm(I, shouldBeIdentity) < 1e-6;
}
// Calculates rotation matrix to euler angles // The result is the same as MATLAB except the order // of the euler angles ( x and z are swapped ). Vec3f rotationMatrixToEulerAngles(Mat &R) {
assert(isRotationMatrix(R));
float sy = sqrt(R.at<double>(0,0) * R.at<double>(0,0) + R.at<double>(1,0) * R.at<double>(1,0) );
bool singular = sy < 1e-6; // If
float x, y, z; if (!singular) { x = atan2(R.at<double>(2,1) , R.at<double>(2,2)); y = atan2(-R.at<double>(2,0), sy); z = atan2(R.at<double>(1,0), R.at<double>(0,0)); } else { x = atan2(-R.at<double>(1,2), R.at<double>(1,1)); y = atan2(-R.at<double>(2,0), sy); z = 0; } return Vec3f(x, y, z);
}
EDiT: After some digging i finally found solution. Used GNU Octave with this code:
Code: function convert_3x3mat2eul R = [-0.001869 -0.003010 -0.999994; -0.022299 0.999747 -0.002945; 0.999750 0.022276 -0.001943]; [x,y,z] = decompose_rotation(R); digits(10); x0 = rad2deg(x);y0 = rad2deg(y);z0 = rad2deg(z); # code for converting radians to degrees RotX = vpa(x0), RotY = vpa(y0), RotZ = vpa(z0) # final code for more output digits end
function [x,y,z] = decompose_rotation(R) x = atan2(R(3,2), R(3,3)); y = atan2(-R(3,1), sqrt(R(3,2)*R(3,2) + R(3,3)*R(3,3))); z = atan2(R(2,1), R(1,1)); end
|