フィルターのクリア

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 Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by