How can I rotate the following cube in real time?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aitor Burdaspar
am 4 Apr. 2019
Kommentiert: Aitor Burdaspar
am 4 Apr. 2019
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 Kommentare
Akzeptierte Antwort
KSSV
am 4 Apr. 2019
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.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!