How to rotate cube in MATLAB.?

69 views (last 30 days)
Nimisha
Nimisha on 28 Dec 2014
Commented: Nimisha on 3 Jan 2015
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.?

Accepted Answer

Shoaibur Rahman
Shoaibur Rahman on 28 Dec 2014
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 Comments
Nimisha
Nimisha on 3 Jan 2015
Thank You So Much,
Finally it works for me :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!