Cube movement in X - Direction.?

5 vues (au cours des 30 derniers jours)
Nimisha
Nimisha le 4 Avr 2016
if P == 1
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];
axis([-2 2 -2 2 -2 2])
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;
axis([-2 2 -2 2 -2 2])
plot3(P(:,1),P(:,2),P(:,3)) % rotated cube
axis([-2 2 -2 2 -2 2])
plot3(0,0,0,'or')
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
elseif P==2
.
.
.
I am creating a cube with this code, and as P changes, i want to move cube in x direction with increment of 1. How to perform this operation.? I tried to move, but previous lines remains as it is, and it becomes rectangle..!

Réponses (2)

Walter Roberson
Walter Roberson le 4 Avr 2016
Modifié(e) : Walter Roberson le 4 Avr 2016
Create a hgtransform() and parent everything to be moved to it. Then when it is time to move it, set its transform matrix, which you can do directly or you can use (for example)
Txy = makehgtform('translate',[-1.5 -1.5 0]);
set(t2,'Matrix',Txy)
  1 commentaire
Nimisha
Nimisha le 4 Avr 2016
Modifié(e) : Nimisha le 4 Avr 2016
I checked, and object is moving at its axis.!
I want to shift my cube by 1 w.r.t its position..! As well my object is square.
clear all;clc
ax = axes('XLim',[-15 15],'YLim',[-15 15],'ZLim',[-15 15]);
view(3)
grid on
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;
t = hgtransform('Parent',ax);
Rz = eye(4);
Sxy = Rz;
for r = 1
% Z-axis rotation matrix
Rz = makehgtform('zrotate',r);
Sxy = makehgtform('scale',r);
% Concatenate the transforms and
% set the transform Matrix property
set(t,'Matrix',Rz*Sxy)
drawnow
end
pause(1)
set(t,'Matrix',eye(4))
But the problem is that which will be the variable which will control my cube movement in this program to LEFT, RIGHT, UP, DOWN or HOME LOCATION-RESET ?

Connectez-vous pour commenter.


alejandro perez
alejandro perez le 2 Fév 2020
In the description of this video is the code of a cube which rotates, moves and grows up.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by