发现两个旋转矩阵之间的差异 [英] finding difference between two rotation matrices
问题描述
我遇到了以下问题,我已经开发了将大型欧拉角数组转换为旋转矩阵的代码,我的数据是phi1,phi和phi2值,如下所示
I am having following problem, I have developed code for converting the large array of euler angles to rotation matrices, my data is phi1,phi and phi2 values like as follows
phi1 phi phi2
2 3 5
1 2.2 4.3
3 4 5
....还有另外200万个数据数组.
.....there are other 2 million array of data.
但是我想对由第一行欧拉角形成的旋转矩阵求逆,并将其乘以从第二行形成的矩阵.然后,我必须使用所得矩阵的元素之一. 有什么办法吗?
but I want to carry out inverse of the rotation matrix formed from first row of euler angles and multiply it to matrix developed from the second row. Then I have to use one of the elements of the resultant matrix. Is there any way to do that?
g_11=((cosd(phi1).*cosd(phi2))-(sind(phi1).*sind(phi2).*cosd(phi)));
g_12=((sind(phi1).*cosd(phi2))+(cosd(phi1).*sind(phi2).*cosd(phi)));
g_13= (sind(phi2).*sind(phi));
g_21 =((-cosd(phi1).*sind(phi2))-(sind(phi1).*cos(phi2).*cos(phi)));
g_22 = ((-sin(phi1).*sind(phi2))+(cosd(phi1).*cosd(phi2).*cosd(phi)));
g_23 = (cosd(phi2).*sind(phi));
g_31 = (sind(phi1).* sind(phi));
g_32 = -cosd(phi1).* sind(phi);
g_33 = cosd(phi);
g1 =[g_11 g_12 g_13 ; g_21 g_22 g_23 ; g_31 g_32 g_33]
这里g1是数据第一行的旋转矩阵 我想找到g2,它是数据第二行的旋转矩阵.薄,我要进行
Here g1 is the rotation matrix for first row of the data I want to find g2 which is the rotation matrix for second row of the data. thin I want to carry out
del_g= inv(g1).*g2;
然后我要提取所得矩阵的g11和g13元素.
then I want to extract g11 and g13 elements of the resultant matrix.
数据取自具有以下数据的文本文件
The data is taken from a text file with the following data
4.55686 0.88751 4.71368 0.00000 0.00000 879.7 0.143 1.77 1 1 Iron - Alpha
4.57459 0.87938 4.71205 20.00000 0.00000 926.3 0.196 2.13 1 1 Iron - Alpha
4.57459 0.87938 4.71205 40.00000 0.00000 550.3 0.196 2.13 1 1 Iron - Alpha
4.57709 0.88250 4.71319 60.00000 0.00000 631.4 0.232 1.85 1 1 Iron - Alpha
4.57507 0.88371 4.72148 80.00000 0.00000 639.7 0.375 2.10 1 1 Iron - Alpha
4.57507 0.88371 4.72148 100.00000 0.00000 643.9 0.375 1.86 1 1 Iron - Alpha
4.57507 0.88371 4.72148 120.00000 0.00000 680.4 0.375 1.75 1 1 Iron - Alpha
4.57507 0.88371 4.72148 140.00000 0.00000 691.6 0.375 1.81 1 1 Iron - Alpha
4.57507 0.88371 4.72148 160.00000 0.00000 674.9 0.375 1.66 1 1 Iron - Alpha
4.58254 0.87567 4.69293 180.00000 0.00000 651.6 0.286 1.95 1 1 Iron - Alpha
4.58254 0.87567 4.69293 200.00000 0.00000 657.5 0.286 1.92 1 1 Iron - Alpha
4.58254 0.87567 4.69293 220.00000 0.00000 693.4 0.286 2.18 1 1 Iron - Alpha
4.58254 0.87567 4.69293 240.00000 0.00000 670.5 0.286 2.06 1 1 Iron - Alpha
前三列分别是欧拉角phi1,phi和phi2 从我正在使用的文本文件中提取数据
The first three columns are the euler angles phi1,phi and phi2 respectively for extracting the data from the text file I am using
fid = fopen('test.txt');
A = textscan(fid, '%f %f %f %f %f %*f %*f %*f %*f %*f %*s %*s %*s') ;
%read the file
a = A{1};
e = A{2};
c = A{3};
x = A{4};
y = A{5};
%converted the euler angles into degrees
phi1= radtodeg(a);
phi= radtodeg(e);
phi2= radtodeg(c);
这里phi1是1999999X1的数组,类似地phi和phi2是相同大小的数组,这是我在后面的部分中使用的.
here phi1 is an array of 1999999X1 similarly phi and phi2 are arrays of same size, this I am using in the later part.
推荐答案
从制作一个获取g1
的函数开始,我调用了函数get_gi
,因此应将其另存为单独的m文件get_gi.m:
Start with making a function that gets g1
, I called the function get_gi
so it should be saved as a separate m file get_gi.m:
function gi=get_gi(pvec)
%pvec is a 1x3 vector of [phi1 phi phi2]
g_11=((cosd(pvec(1)).*cosd(pvec(3)))-(sind(pvec(1)).*sind(pvec(3)).*cosd(pvec(2))));
g_12=((sind(pvec(1)).*cosd(pvec(3)))+(cosd(pvec(1)).*sind(pvec(3)).*cosd(pvec(2))));
g_13= (sind(pvec(3)).*sind(pvec(2)));
g_21 =((-cosd(pvec(1)).*sind(pvec(3)))-(sind(pvec(1)).*cos(pvec(3)).*cos(pvec(2))));
g_22 = ((-sin(pvec(1)).*sind(pvec(3)))+(cosd(pvec(1)).*cosd(pvec(3)).*cosd(pvec(2))));
g_23 = (cosd(pvec(3)).*sind(pvec(2)));
g_31 = (sind(pvec(1)).* sind(pvec(2)));
g_32 = -cosd(pvec(1)).* sind(pvec(2));
g_33 = cosd(pvec(2));
gi =[g_11 g_12 g_13;g_21 g_22 g_23;g_31 g_32 g_33];
然后,您可以遍历大型数组(称为LA
),获取所需的所有g
,并在此同时进行所需的计算:
then you can loop over your large array (call it LA
), getting all the g
you need, and while at it, so the calculation you want:
for ii=1:n-1
del_g= inv(get_gi(LA(ii,:)).*get_gi(LA(ii+1,:);
ans(ii,:) = [del_g(1,1) del_g(1,3)];
end
那是你想要的吗?
这篇关于发现两个旋转矩阵之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!