Rotation of a rigid body in three-dimensional space (about rotation matrix, DCM, rotation vector, four-dollar, Euler-angle)

Source: Internet
Author: User
Tags compact cos

Recently learned some about three-dimensional space rotation related knowledge, to comb the memo.


The rotation of the three-dimensional space (3D Rotation) is a very magical thing: if a rigid body in three-dimensional space for any rotation, as long as the center of rotation remains unchanged, no matter how many times the rotation can be used around a three-dimensional space in a rotation of one axis to represent. There are many ways to represent the rotation of three-dimensional space, such as rotation matrix, DCM, rotation vector, four-dollar number, Euler angle, etc. This article mainly combs these representations and the mutual conversion method.


1. Euler's angle (Euler Angle)

The most intuitive representation is to rotate an angle around the X, Y, and z three axes of the rigid body itself, which is called the Euler angle (Euler Angle) representation.



It should be noted that the order of yaw, pitch and roll in the representation of Euler angles has an effect on the results of rotation. given a set of Euler angular angle values, such as yaw=45 degrees, pitch=30 degrees, roll=60 degrees, rotating in the order of Yaw-pitch-roll and in Yaw-roll-pitch order, the final body orientation is different ! In other words, if a rigid body needs to be rotated to the same direction in two different rotations, the desired Euler angle value is different!


It is also important to note that, in the representation of Euler's angle, the three axes of rotation are generally the same as the rigid body in motion , the so-called intrinsic rotationin Wikipedia, as shown in the animation (pictured from Wikipedia). Another way to represent this is that three axes of rotation are fixed, not rotated with rigid bodies, i.e. extrinsic rotation, which is not commonly used in computer vision.



Euler angles are more intuitive to represent, but have several drawbacks:

(1) Euler angle is not the only way to express. Given a starting direction and a target orientation, even given the order of yaw, pitch, roll, the desired rotation can be represented by a combination of different yaw/pitch/roll angles. For example, the same Yaw-pitch-roll order, (0,90,0) and (90,90,90) will move the rigid body to the same position. This is mainly due to the universal lock (Gimbal Lock) caused by the explanation of the universal lock, the conditional classmate to see YouTube video may be more intuitive.

(2) Euler angle interpolation is more difficult.

(3) When calculating the rotation transformation, the general need to convert to a rotation matrix, this time need to calculate a lot of sin, cos, the calculation of a large amount.


2. Rotation matrix (Rotation matrix) and the direction cosine matrix (Direction cosine matrix)

When calculating coordinate transformations, a more convenient representation of rotation is the rotation matrix (Rotation matrix). The rotation matrix of three-dimensional space can be represented as a 3x3 matrix, the Euler angle to the rotation matrix is calculated as follows, assuming Euler angle yaw, pitch, roll angle of alpha, beta, gamma, the rotation matrix can be calculated as follows:


which


As can be seen here, if the order of yaw, pitch, roll is changed, the order of matrix multiplication needs to be changed accordingly, the result of the resulting rotation matrix will also change.


It should be noted that although there are 9 elements of the rotation matrix, but only 3 degrees of freedom, so not any matrix can be used as the rotation matrix, the rotation matrix needs to be orthogonal matrix (that is, inverse matrix equals transpose matrix).


In addition, another name for the rotation matrix is called the direction cosine matrix (Direction cosine matrix), or DCM, which is more commonly used in the field of gyroscope mechanics. The name of the DCM is actually used in addition to the Euler angle to represent three-dimensional rotation with 3 angle values, assuming that the rigid body at the beginning of the direction of the three axes of the vector is i,j,k, and the rigid body in the target direction of the three axis of the vector is i,j,k, The rotation can be represented by an angle of three axes, respectively, to the original axis, as shown in:


DCM can be calculated by the cosine of three angles as follows:


This is the origin of the DCM name. In fact, it can be verified thatDCM is actually the rotation matrix , so the following is no longer a distinction between DCM and rotation matrix.


In MATLAB (in later versions of r2006a, you need to install aerospace Toolbox), you can easily convert Euler angles and rotation matrices with angle2dcm and dcm2angle . The following MATLAB code can verify that two different Euler angle modes can be converted to the same rotation matrix:

% Matlab code by MULINB, Aerospace Toolbox is needed% Gimbal Lock experimentsyaw1 =   0;pitch1 = 90;roll1 =  0;YAW2 =   90;PITCH2 = 90;roll2 =  90; R1 = ANGLE2DCM (YAW1/180*PI,PITCH1/180*PI,ROLL1/180*PI); R2 = ANGLE2DCM (yaw2/180*pi,pitch2/180*pi,roll2/180*pi);d ISP (R1);d ISP (R2);


3. Four yuan (quaternion), rotation vector (Rotation vector), axis-angle representation (Axis-angle)

One of the magic of the rotation is that the three-dimensional space of arbitrary rotation, can be used around the three-dimensional space of a certain axis rotation over an angle to represent, that is, the so-called Axis-angle representation method. In this representation, axis can be represented by a three-dimensional vector (x, y, z), which is represented by an angular value, and visually, a four-dimensional vector (theta,x,y,z) can represent an arbitrary rotation of the three dimensions of Space (theta). Note that the three-dimensional vector (x, y, z) Here is only used to represent the direction of axis, so a more compact representation is to use a unit vector to represent the direction axis, and the length of the three-dimensional vector to represent the angular value theta. In this way, a three-dimensional vector (theta*x, theta*y, theta*z) can be used to represent the arbitrary rotation of the three-dimensional space , provided that (x, Y, z) is a unit vector. This is the representation of the rotational vector (Rotation vector), which is used extensively in OpenCV to represent rotation (see Rvec in the OpenCV Camera calibration section).


Axis-angle expression method can also deduce another very common three-dimensional rotation representation, called four Yuan (quaternion), here is a very easy to understand the introduction of four yuan of the article. Ibid., assuming (x, y, z) is a unit vector in axis direction, Theta is the angle around axis, then the four-dollar number can be expressed as [cos (THETA/2), X*sin (THETA/2), Y*sin (THETA/2), Z*sin ( THETA/2)]. Note that it can be deduced that the four-tuple vector used to represent rotation must also be a unit vector. The magic of four yuan is that for three-dimensional coordinate rotation, can be directly manipulated by four-dollar multiplication, and the above rotation matrix operation can be equivalent, but the representation is more compact, the calculation can be smaller. First, the multiplication of the four-dollar number is defined as follows:


From this definition, the inverse of the four-dollar number can also be calculated. As the rotation of four yuan, because of its unit vector characteristics, the inverse of four is actually equal to four yuan number of conjugate, that is, if four Yuan Q=[a,b,c,d], because of a^2+b^2+c^2+d^2=1, then Q's inverse and conjugate are Q ' =[a,-b,-c,-d]. It is important to note that the multiplication of four-tuple is not exchangeable . The rotation is calculated by a four-dollar number (a point v_i of three-dimensional space is rotated to V_b, and the four-dollar number is Q):


In MATLAB, you can use quatmultiply to calculate four-dollar multiplication, use quatinv to calculate the inverse of four-dollar number, with Quatconj to calculate the conjugate of the four-dollar number. The rotation of the four-dollar rotation and rotation matrix can be verified by the following MATLAB code:

% Matlab code by MULINB, Aerospace Toolbox is NEEDEDPT = [10,20,30]; % point Coordinateyaw =   45;pitch = 30;roll =  60;q = Angle2quat (YAW/180*PI,PITCH/180*PI,ROLL/180*PI); R = ANGLE2DCM (yaw/180*pi,pitch/180*pi,roll/180*pi);p t1 = r*pt ';p t2 = quatmultiply (Quatconj (q), quatmultiply ([0,pt],q) ); % NOTE the Orderdisp (PT1 ');d ISP (PT2 (2:4));

From the above code can also see four and Euler angle and DCM conversion, in MATLAB can be very convenient to use Quat, DCM, AngleBetween the transitions to any other. In addition, axis and angle are calculated from four of dollars, and can be calculated using the following code:

% Matlab code by MULINB, Compute the axis and angle from a quaternionfunction [axis, theta] = Quat2axisangle (q) theta = aco S (q (1)) * 2;axis = q (2:4)/sin (THETA/2);

The rotation vector and quaternion from OpenCV can be exchanged with the following code:

% Matlab code by MULINB, Convert a quaternion to a rotation vectorfunction Rvec = Quat2rvec (q) theta = ACOs (q (1)) * 2;axis = Q (2:4)/sin (THETA/2); axis = axis/norm (axis); Rvec = Axis*theta;
% Matlab code by MULINB, Convert a rotation vectors to a quaternionfunction q = rvec2quat (Rvec) theta = norm (Rvec); axis = RV Ec/theta;sht = sin (theta/2), q = [cos (THETA/2), Axis*sht];

4. Gyroscope (Gyroscope)

With the miniaturization and popularization of MEMS gyroscope, more and more computer vision algorithms will increase the IMU as auxiliary information input and increase the stability of the system. On the data fusion and attitude angle calculation of gyroscope, here are some good references:

[1]. IMU Data fusing:complementary, Kalman, and Mahony Filter

[2]. Crazepony Open Source Project





Rotation of a rigid body in three-dimensional space (about rotation matrix, DCM, rotation vector, four-dollar, Euler-angle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.