finding difference between two rotation matrices

强颜欢笑 提交于 2019-12-11 15:12:40

问题


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

.....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]

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;

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

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);

here phi1 is an array of 1999999X1 similarly phi and phi2 are arrays of same size, this I am using in the later part.


回答1:


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];

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

Is that what you wanted?



来源:https://stackoverflow.com/questions/14620670/finding-difference-between-two-rotation-matrices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!