필터 지우기
필터 지우기

How to rotate cube in MATLAB.?

조회 수: 23 (최근 30일)
Nimisha
Nimisha 2014년 12월 28일
댓글: Nimisha 2015년 1월 3일
A = [0 0 0];
B = [1 0 0];
C = [0 1 0];
D = [0 0 1];
E = [0 1 1];
F = [1 0 1];
G = [1 1 0];
H = [1 1 1];
P = [A;B;F;H;G;C;A;D;E;H;F;D;E;C;G;B];
plot3(P(:,1),P(:,2),P(:,3))
I am creating a cube using this code.
Now i want to rotate this cube according to Roll, pitch and Yaw axis.
If R = -0.3064; P = -1.2258; Y = 9.8066
Then how to rotate this cube.?

채택된 답변

Shoaibur Rahman
Shoaibur Rahman 2014년 12월 28일
Add the following lines of code at the bottom of your code:
roll = -0.3064; pitch = -1.2258; yaw = 9.8066;
dcm = angle2dcm(yaw, pitch, roll);
P = P*dcm;
plot3(P(:,1),P(:,2),P(:,3)) % rotated cube
  댓글 수: 7
Shoaibur Rahman
Shoaibur Rahman 2015년 1월 2일
편집: Shoaibur Rahman 2015년 1월 2일
I guess, you are asking that if the rotation is 360 degrees, then both the original and rotated cube should look at the same position, right?
Instead of using 360, use 2*pi for roll, pitch, and yaw, i.e. in radians.
roll = 2*pi; pitch = 2*pi; yaw = 2*pi;
A = [0 0 0];
B = [1 0 0];
C = [0 1 0];
D = [0 0 1];
E = [0 1 1];
F = [1 0 1];
G = [1 1 0];
H = [1 1 1];
P = [A;B;F;H;G;C;A;D;E;H;F;D;E;C;G;B];
plot3(P(:,1),P(:,2),P(:,3),'g'), hold on
roll = 2*pi; pitch = 2*pi; yaw = 2*pi;
dcm = angle2dcm(yaw, pitch, roll);
P = P*dcm;
plot3(P(:,1),P(:,2),P(:,3)) % rotated cube
plot3(0,0,0,'or')
Nimisha
Nimisha 2015년 1월 3일
Thank You So Much,
Finally it works for me :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by