필터 지우기
필터 지우기

Cube movement in X - Direction.?

조회 수: 2 (최근 30일)
Nimisha
Nimisha 2016년 4월 4일
답변: alejandro perez 2020년 2월 2일
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에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by