How can I rotate the following cube in real time?
2 次查看(过去 30 天)
显示 更早的评论
Hello to everyone,
I´m reading some data of an IMU in a microcontroller and I send "roll, pitch and "yaw" information from the angles to Matlab by serial port. I have created that multicolor cube in order to know better which part of the sensor is each face of the cube. I would like to create a function that receives roll, pitch and yaw angle values and then rotates the cube in real time.
patch([0, 4, 4, 0], [0, 0, 3, 3], [0, 0, 0, 0], 'blue') %Cara de la parte de abajo de la imu
patch([0, 4, 4, 0], [0, 0, 3, 3], [1, 1, 1, 1], 'red') %Cara de la parte de arriba
patch([0, 0, 0, 0], [0, 0, 3, 3], [0, 1, 1, 0], 'green') %Borde corto nº1 del sensor
patch([0, 4, 4, 0], [0, 0, 0, 0], [0, 0, 1, 1], 'yellow') %Borde largo nº1 del sensor
patch([4, 4, 4, 4], [0, 3, 3, 0], [0, 0, 1, 1], 'magenta') %Borde largo nº2 del sensor
patch([4, 4, 0, 0], [3, 3, 3, 3], [0, 1, 1, 0], 'cyan') %Borde corto nº2 del sensor
axis square
Thank you in advance,
0 个评论
采纳的回答
KSSV
2019-4-4
X = [0, 4, 4, 0
0, 4, 4, 0
0, 0, 0, 0
0, 4, 4, 0
4, 4, 4, 4
4, 4, 0, 0] ;
Y = [0, 0, 3, 3
0, 0, 3, 3
0, 0, 3, 3
0, 0, 0, 0
0, 3, 3, 0
3, 3, 3, 3] ;
Z = [0, 0, 0, 0
1, 1, 1, 1
0, 1, 1, 0
0, 0, 1, 1
0, 0, 1, 1
0, 1, 1, 0] ;
C = {'blue' ;'red' ; 'green' ; 'yellow' ; 'magenta' ; 'cyan'};
figure
hold on
for i = 1:6
patch(X(i,:), Y(i,:), Z(i,:),C{i}) ;
end
axis square
view(3)
%% Rotate
th = linspace(0,2*pi) ;
for i = 1:length(th)
R = [1 0 0 ;0 cos(th(i)) -sin(th(i)) ; 0 sin(th(i)) cos(th(i))] ;
T = [X(:) Y(:) Z(:)]*R ;
Xi = reshape(T(:,1),[],4) ;
Yi = reshape(T(:,2),[],4) ;
Zi = reshape(T(:,3),[],4) ;
figure(1)
hold on
for j = 1:6
patch(Xi(j,:), Yi(j,:), Zi(j,:),C{j}) ;
end
axis square
view(3)
drawnow
hold off
clf
end
Can be improved a lot.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!