Cube movement in X - Direction.?

2 次查看(过去 30 天)
Nimisha
Nimisha 2016-4-4
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..!

回答(2 个)

Walter Roberson
Walter Roberson 2016-4-4
编辑:Walter Roberson 2016-4-4
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 个评论
Nimisha
Nimisha 2016-4-4
编辑:Nimisha 2016-4-4
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 ?

请先登录,再进行评论。


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

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by