分解旋转矩阵(x,y',z'')-笛卡尔角 [英] Decomposing rotation matrix (x,y',z'') - Cartesian angles

查看:94
本文介绍了分解旋转矩阵(x,y',z'')-笛卡尔角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用旋转矩阵,并且遇到以下问题:给定三个重合的坐标系( O0,x0,y0,z0; O1,x1,y1,z1; O2,x2,y2,z2 ).我们首先相对于第 0 帧旋转第 1 帧,然后相对于第 1 帧旋转第 2 帧.

Im currently working with rotation matrices and I have the following problem: Given three coordinate systems (O0,x0,y0,z0; O1,x1,y1,z1; O2,x2,y2,z2) which coincide. We rotate first the frame #1 with the respect to frame #0, then the frame #2 with respect to frame #1.

旋转顺序: R = Rx_alpha * Ry_beta * Rz_gamma ,因此首先关于 x ,然后是 y' ,然后是 z'' ,也称为笛卡尔角.如果R1代表第一旋转,R2代表第二旋转,则我们正在寻找在两次旋转之后第二帧相对于初始帧(#0)的角度.这可以通过分解旋转矩阵 R(其中: R = R1 * R2 )来完成.现有许多文献介绍如何通过Euler角和RPY角实现此功能,但我找不到任何关于在笛卡尔角情况下解决此问题的方法.

The order of the rotations: R = Rx_alpha * Ry_beta * Rz_gamma, so first about x, then y', then z'', which are also known as the Cartesian angles. If R1 stands for the 1st and R2 for the 2nd rotation, we are looking for the angles of the 2nd frame with respect to initial frame (#0) after both of the rotations. This can be done by decomposing the rotation matrix R (where:R = R1*R2 ). There are many literature available, how it can be done by Euler- and RPY-angles, but I don't find any, how to solve this problem in case of Cartesian angles.

我有一个 matlab函数,该函数只能通过简单的旋转来工作.如果所有角度的值都不同于0(下面的示例),那么结果将变得非常不稳定.

I have a matlab function which works only by simple rotations. If all the angles have values different than 0 (example below), then the result becomes really unstable.

第1帧相对于第0帧的方向:

Orientation of the 1st frame with respect to the frame #0:

    alpha1 = 30*pi/180;
    beta1 = 10*pi/180;
    gamma1 = 0*pi/180;

第2帧相对于第1帧的方向

Orientation of the 2nd frame with respect to the frame #1

    alpha2 = 10*pi/180;
    beta2 = 10*pi/180;
    gamma2 = 0*pi/180;

我用来解决问题的matlab函数:

The matlab function I was using for solving the problem:

function [q] = cartesian_angles(R)

beta = asin(R(1,3));

*% Catching the numerical singularty*
if abs(abs(beta)-pi/2) > eps;
    *% singulartiy of acos*
    gamma1 = acos(R(1,1) / cos(beta));
    gamma2 = asin(-R(1,2) / cos(beta));
    if gamma2<0
        gamma=2*pi-gamma1;
    else
        gamma=gamma1;
    end
    alpha1 = acos(R(3,3) / cos(beta));
    alpha2 = asin(-R(2,3) / cos(beta));
    if alpha2<0
        alpha = 2*pi-alpha1;
    else
        alpha = alpha1;
    end
else
    fprintf('beta=pi/2 \n')
    gamma = 0;
    alpha = 0;
    beta  = 0;
end;

alpha = alpha*180/pi;
beta = beta*180/pi;
gamma = gamma*180/pi;

q = [alpha; beta; gamma];

谢谢您的帮助!如果您有任何疑问,请随时提出来!

Thank you for any help! If you have some questions don't hesitate to ask!

Marci

推荐答案

首先,我假设您正在向函数传递条件良好的右手旋转矩阵.我将使用与上面列出的相同的旋转顺序X Y'Z''

First, I'm going to assume you are passing into your function a well conditioned, right-handed rotation matrix. I'm going to use the same rotation sequence as you listed above, X Y' Z''

如果您知道要从中提取角度的旋转矩阵的符号构造,则数学计算非常简单.下面是一个Matlab代码示例,用于确定X-Y'-Z''阶旋转矩阵的构造

If you know the symbolic construction of the rotation matrix you are trying to extract angles from, the math is pretty straight forward. Below is an example of matlab code to determine the construction of the rotation matrix of order X-Y'-Z''

a = sym('a');%x
b = sym('b');%y
g = sym('g');%z

Rx = [1 0 0;0 cos(a) -sin(a);0 sin(a) cos(a)];
Ry = [cos(b) 0 sin(b);0 1 0;-sin(b) 0 cos(b)];
Rz = [cos(g) -sin(g) 0;sin(g) cos(g) 0;0 0 1];

R = Rz*Ry*Rx

输出看起来像这样:

R =

[ cos(b)*cos(g), cos(g)*sin(a)*sin(b) - cos(a)*sin(g), sin(a)*sin(g) + cos(a)*cos(g)*sin(b)]
[ cos(b)*sin(g), cos(a)*cos(g) + sin(a)*sin(b)*sin(g), cos(a)*sin(b)*sin(g) - cos(g)*sin(a)]
[       -sin(b),                        cos(b)*sin(a),                        cos(a)*cos(b)]

使用更好看的格式得到的结果是相同的:

Here's the same result in a nicer looking format:

现在让我们回顾一下数学,从该矩阵中提取角度.现在是您熟悉atan2()函数的好时机.

Now let's go over the math to extract the angles from this matrix. Now would be a good time to become comfortable with the atan2() function.

首先求出beta角(顺便说一下,alpha是绕X轴的旋转,beta是绕Y'轴的旋转,gamma是绕Z''轴的角度):

First solve for the beta angle (by the way, alpha is the rotation about the X axis, beta is the rotation about Y' axis, and gamma is the angle about the Z'' axis):

beta = atan2(-1*R(3,1),sqrt(R(1,1)^2+R(2,1)^2))

更正式地写

现在我们已经解决了β角,我们可以更简单地解决其他两个角:

Now that we have solved for the beta angle we can solve more simply for the other two angles:

alpha = atan2(R(3,2)/cos(beta),R(3,3)/cos(beta))
gamma = atan2(R(2,1)/cos(beta),R(1,1)/cos(beta))

经过简化且格式更好,

以上方法是从旋转矩阵中获取欧拉角的一种非常可靠的方法.atan2函数确实使它变得更加简单.

The above method is a pretty robust way of getting the Euler angles out of your rotation matrix. The atan2 function really makes it much simpler.

最后,我将回答一系列旋转后如何求解旋转角度.首先考虑以下符号.向量或旋转矩阵将通过以下方式表示:

Finally I will answer how to solve for the rotation angles after a series of rotations. First consider the following notation. A vector or rotation matrix will be notated in the following way:

此处"U"表示通用框架或全局坐标系."Fn"表示不同于U的第n个局部坐标系.R表示旋转矩阵(此表示法也可用于均质变换).左侧上标将始终代表旋转矩阵或矢量的父参照系.左侧下标指示参考的子框架.例如,如果我在F1中有一个向量,并且想知道它在通用参照系中的等效性,那么我将执行以下操作:

Here "U" represents the universal frame, or global coordinate system. "Fn" represents the nth local coordinate system that is different from U. R means rotation matrix (this notation could also be used for homogeneous transformations). The left side superscript will always represent the parent frame of reference of the rotation matrix or vector. The left side subscript indicates the child frame of reference. For example, if I have a vector in F1 and I want to know what it is equivalently in the universal frame of reference I would perform the following operation:

要获得在通用框架中解析的向量,我只需将其乘以将矩阵从F1转换为U的旋转矩阵即可.请注意,下标如何被等式中下一项的上标抵消".这是一个聪明的表示法,可以帮助某人避免混淆.如果您还记得,条件良好的旋转矩阵的一个特殊属性是逆矩阵是矩阵的转置,也将是逆变换,如下所示:

To get the vector resolved in the universal frame I simply multiplied it by the rotation matrix that transforms things from F1 to U. Notice how the subscripts are "cancelled" out by the superscript of the next item in the equation. This is a clever notation to help someone from getting things mixed up. If you recall, a special property of well conditioned rotation matrices is that the inverse matrix is the transpose of the matrix, which is will also be the inverse transformation like this:

现在,注释的详细信息已不复存在,我们可以开始考虑解决一系列复杂的旋转问题了.可以说我有"n"个坐标系(另一种表示"n"个不同旋转的方式).要找出通用框架中第n个"框架中的向量,我将执行以下操作:

Now that the notation details are out of the way, we can start to consider solving for complicated series of rotations. Lets say I have "n" number of coordinate frames (another way of saying "n" distinct rotations). To figure out a vector in the "nth" frame in the universal frame I would do the following:

要确定由n"次旋转产生的卡丹角/欧拉角,您已经知道如何分解矩阵以获得正确的角度(在某些领域也称为逆运动学),您只需要正确的矩阵.在此示例中,我对旋转矩阵感兴趣,该旋转矩阵将事物放在第n个"坐标框架中并将其解析为通用框架U:

To determine the Cardan/Euler angles that result from "n" rotations, you already know how to decompose the matrix to get the correct angles (also known as inverse kinematics in some fields), you simply need the correct matrix. In this example I am interested in the rotation matrix that takes things in the "nth" coordinate frame and resolves them into the Universal frame U:

就这样,我只需按照正确的顺序相乘就可以将所有旋转组合到感兴趣的旋转中.这个例子很简单.当有人想找到一个刚体的参考框架解析为另一个刚体的参考框架时,会出现更复杂的情况,而这两个刚体唯一的共同点是它们在通用框架中的测量.

There is it, I combined all the rotations into the one of interest simply by multiplying in the correct order. This example was easy. More complicated cases come when someone wants to find the reference frame of one rigid body resolved in the frame of another and the only thing the two rigid bodies have in common is their measurement in a universal frame.

我还想指出,这种表示法和方法也可以用于同构转换,但有一些关键的区别.旋转矩阵的逆是它的转置,对于齐次变换则不是这样.

I want to also note that this notation and method can also be used with homogeneous transformations but with some key differences. The inverse of a rotation matrix is its transpose, this is not true for homogeneous transformations.

这篇关于分解旋转矩阵(x,y',z'')-笛卡尔角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆