Help with a rotation matrix

6 ビュー (過去 30 日間)
Scott Hunter
Scott Hunter 2018 年 10 月 26 日
コメント済み: Stephen23 2025 年 7 月 10 日
I have a code which requires 4 different rotation matrices, and since all my variables are in the form of arrays I'm trying to make these matrices also in the form of arrays. So far, the code I have below is what I believe should work. The parameters at the top are parameters for each of the 4 orbits, laid out in 1x4 array. R1, R2 and R3 are not giving me the answers I expect in all the cells (R1,2 and 3 will be combined to make R the final matrix). The matrices should have more zeros in them but I am getting a very very small number (10^-17) instead, I don't know where the maths is going wrong? Thanks! (.png attached at top).
clear
close
i = [90 90 90 90]; %[deg] Inclinations for each orbit
o = [0 0 0 0]; %[deg] Small omega of each orbit
O = [0 45 90 135]; %[deg] RAANs for each orbit
R1 = [cos(o).*cos(O)-sin(o).*cos(i).*sin(O); % Column 1 of rotation matrix for the 4 orbits
cos(o).*sin(O)+sin(o).*cos(i).*cos(O);
sin(o).*sin(i)];
R2 = [-sin(o).*cos(O)-cos(o).*cos(i).*sin(O); % Column 2 of rotation matrix for the 4 orbits
-sin(o).*sin(O)+cos(o).*cos(i).*cos(O);
cos(o).*sin(i)];
R3 = [sin(i).*sin(O); % Column 3 of rotation matrix for the 4 orbits
-sin(i).*cos(O);
cos(i)];
  15 件のコメント
Scott Hunter
Scott Hunter 2018 年 10 月 26 日
Oh right I see thank you. Why is this a benefit?

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 26 日
編集済み: Bruno Luong 2018 年 10 月 26 日
You seem to apply sin/cos to degree angles which is wrong, since argument must be in radian.
Also the code is correct and might returns small error when expected result is 0.
>> cos(pi/2)
ans =
6.1232e-17
PS: I put my comment here for you to accept if it solves your pb
  2 件のコメント
Scott Hunter
Scott Hunter 2018 年 10 月 26 日
I will do! Maybe add in that my confusion was due to the error in accuracy?
Image Analyst
Image Analyst 2018 年 10 月 26 日
You can use degrees. Just switch to the "d" versions of the trig functions: sind() and cosd().

サインインしてコメントする。

その他の回答 (1 件)

sanjay
sanjay 2025 年 7 月 10 日
cos(pi/2)
ans =
6.1232e-17
  2 件のコメント
Steven Lord
Steven Lord 2025 年 7 月 10 日
That's correct. If you want to compute the cosine or sine of an angle represented as a multiple of pi radians, you can use cospi and sinpi.
cos(pi/2)
ans = 6.1232e-17
cospi(1/2)
ans = 0
sin(pi)
ans = 1.2246e-16
sinpi(1)
ans = 0
Stephen23
Stephen23 2025 年 7 月 10 日
Or use degrees:
cosd(90)
ans = 0
sind(180)
ans = 0

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by