本文介绍了使用三维阵列简单立方晶格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请使用MATLAB简单立方晶格。

I want to draw a simple cubic lattice using MATLAB.

我已经阅读如何绘制三维网格(立方体)在Matlab ,不过,我想每一个颜色的小立方体。

I have read How to plot 3D grid (cube) in Matlab, however, I want to color every small cube.

我有一个三维阵列在MATLAB,如,

I have a three-dimensional array in MATLAB, such as,

cube(:,:,1) = [1 0 1
               0 1 1
               1 1 0]
cube(:,:,2) = [0 0 1
               1 1 1
               0 1 0]
cube(:,:,3) = [1 1 1
               0 1 1
               1 0 1]

我如何可以得出一个简单的立方晶格使用这个数组,其中立方体(:,:,1)表示立方晶格的一楼,立方体(:,:,2)表示二楼,立方体(:,:,3)。三楼

How can I draw a simple cubic lattice using this array, in which cube(:,:,1) denotes the first floor of the cubic lattice, cube(:,:,2) denotes the second floor, and cube(:,:,3) the third floor.

A 0 表示一个白色的小立方体,而一个 1 表示一个黑色的小立方体。

A 0 denotes a small white cube, whilst a 1 denotes a small black cube.

期望的结果是这样的: http://www.instructables.com/id /益智-立方/

The desired result is something like this: http://www.instructables.com/id/Puzzle-Cube/

推荐答案

我找不到任何简单的,所以这是它是什么!

I couldn't find anything simpler, so this is what it is!

C = randi(2,[3 3 3])-1;
colorC = char(repmat('k',[3 3 3]));
colorC(C == 0) = 'y';
figure(1);
for x = 0 : 2
for y = 0 : 2
for z = 0 : 2
     vert = [1 1 0; 
             0 1 0; 
             0 1 1; 
             1 1 1; 
             0 0 1;
             1 0 1; 
             1 0 0;
             0 0 0];
     vert(:,1) = vert(:,1) + x;
     vert(:,2) = vert(:,2) + y;
     vert(:,3) = vert(:,3) + z;
     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];
     patch('Faces',fac,'Vertices',vert,'FaceColor',colorC(x + 1, y + 1, z + 1)); 
     axis([0, 3, 0, 3, 0, 3]);
     alpha('color');
     alphamap('rampdown');
     axis equal
     hold on
end
end
end

给你这个,

如果您删除阿尔法('颜色'); 的alphamap(斜坡降压'); 和使用轴断,你得到的,

If you delete alpha('color'); and alphamap('rampdown');and use axis off, you get,

这篇关于使用三维阵列简单立方晶格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 23:02