How can I rotate the following cube in real time?
6 ビュー (過去 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 で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!