如何在matlab中绘制多个3d立方体
我试图在一个m文件中绘制两个立方体。这是我的代码: format compact h(1) = axes('Position',[0.2 0.2 0.6 0.6]); vert = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ... 1 1 2;1 2 2; 2 2 2;2 1 2]; fac = [1 2 3 4; ... 2 6 7 3; ... 4 3 7 8; ... 1 5 8 4; ... 1 2 6 5; ... 5 6 7 8]; patch('Faces',fac,'Vertices',vert,'FaceColor','r'); % patch function material shiny; alpha('color'); alphamap('rampdown'); view(30,30); 格式压缩 h(1)=轴(‘位置’,[0.20.20.60.6]); 垂直=[1 1;1 2 1;2 2 1;2 1。。。 1 1 2;1 2 2; 2 2 2;2 1 2]; fac=[1 2 3 4。。。 2 6 7 3; ... 4 3 7 8; ... 1 5 8 4; ... 1 2 6 5; ... 5 6 7 8]; 面片('Faces','fac','vert','FaceColor','r');%面片函数 材料光泽; 阿尔法(“颜色”); alphamap(“缓降”); 视图(30,30); 现在,我想画第二个立方体,替换第一个立方体。有人知道我该怎么做吗如何在matlab中绘制多个3d立方体,matlab,3d,cube,Matlab,3d,Cube,我试图在一个m文件中绘制两个立方体。这是我的代码: format compact h(1) = axes('Position',[0.2 0.2 0.6 0.6]); vert = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ... 1 1 2;1 2 2; 2 2 2;2 1 2]; fac = [1 2 3 4; ... 2 6 7 3; ... 4 3 7 8; ... 1 5
这样做吗?使用
按住命令
format compact
h(1) = axes('Position',[0.2 0.2 0.6 0.6]);
%----first cube------
vert = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ...
1 1 2;1 2 2; 2 2 2;2 1 2];
fac = [1 2 3 4; ...
2 6 7 3; ...
4 3 7 8; ...
1 5 8 4; ...
1 2 6 5; ...
5 6 7 8];
patch('Faces',fac,'Vertices',vert,'FaceColor','r'); % patch function
material shiny;
alpha('color');
alphamap('rampdown');
view(30,30);
%------second cube-----
hold on;
vert2 = [1 1 1; 1 2 1; 2 2 1; 2 1 1 ; ...
1 1 2;1 2 2; 2 2 2;2 1 2]/5;
fac2 = [1 2 3 4; ...
2 6 7 3; ...
4 3 7 8; ...
1 5 8 4; ...
1 2 6 5; ...
5 6 7 8];
patch('Faces',fac2,'Vertices',vert2,'FaceColor','b'); % patch function
也许你想要这样的东西:
您只需要稍微修改原始代码:1。定义一个新的多维数据集,该多维数据集应放置在第一个多维数据集中。2.请记住在“补丁”之后添加“等待”
clf;
figure(1);
format compact
h(1) = axes('Position',[0.2 0.2 0.6 0.6]);
vert = [1 1 -1;
-1 1 -1;
-1 1 1;
1 1 1;
-1 -1 1;
1 -1 1;
1 -1 -1;
-1 -1 -1];
fac = [1 2 3 4;
4 3 5 6;
6 7 8 5;
1 2 8 7;
6 7 1 4;
2 3 5 8];
% I defined a new cube whose length is 1 and centers at the origin.
vert2 = vert * 0.5;
fac2 = fac;
patch('Faces',fac,'Vertices',vert,'FaceColor','b'); % patch function
axis([-1, 1, -1, 1, -1, 1]);
axis equal;
hold on;
patch('Faces', fac2, 'Vertices', vert2, 'FaceColor', 'r');
material metal;
alpha('color');
alphamap('rampdown');
view(3);
你是说把第二个立方体放在第一个立方体里面?然后,您需要更改vert2的坐标,并使第一个立方体透明,以便可以看到第二个立方体。