制作魔方';Matlab中的立方体?

制作魔方';Matlab中的立方体?,matlab,rubiks-cube,mupad,Matlab,Rubiks Cube,Mupad,我正在尝试制作一个魔方的3d模型 我最初尝试使用patch命令 vert = [0 0 0; 0 1 0; 1 1 0; 1 0 0 ; ... 0 0 1;0 1 1; 1 1 1;1 0 1]; 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]; k = patch('Faces',fac,'Vertices',vert,'F

我正在尝试制作一个魔方的3d模型

我最初尝试使用patch命令

vert = [0 0 0; 0 1 0; 1 1 0; 1 0 0 ; ...
        0 0 1;0 1 1; 1 1 1;1 0 1];
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];
k = patch('Faces',fac,'Vertices',vert,'FaceColor','r');  % patch function
material shiny;
alpha('color');
alphamap('rampdown');
view(30,30); 
但是因为我可能需要给每个曲面赋予不同的颜色,所以我不得不多次使用patch命令。因此,当我想引用整个立方体时,我无法引用它

我发现的另一种方法是在MuPAD中使用命令
plot::Box

plot(plot::Box(0..1, 0..1, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
     plot::Box(1..2, 0..1, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
plot::Box(2..3, 0..1, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
     plot::Box(0..1, 1..2, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
plot::Box(0..1, 2..3, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
     plot::Box(2..3, 1..2, 0..1, Filled = TRUE,
               FillColor = RGB::Red),
plot::Box(1..2, 2..3, 0..1,Filled = TRUE,
               FillColor = RGB::Red),
     plot::Box(2..3, 2..3, 0..1, Filled = TRUE,
               FillColor = RGB::RED,),
     Axes = None, Scaling = Constrained)
但在这里,我不能给每个表面单独的颜色。我尝试使用
FillColorDirection=[0,0,1])
但它不起作用

使用“打印:框”时,是否可以为每个面指定单独的颜色
或者有更好的方法吗?

我通过使用补丁本身解决了这个问题。修补程序有一个名为FaceVertexCData的属性。通过这一点,我们将能够指定每个面的颜色。我们还应该将Facecolor设置为平面,如下所示

cube = patch('Faces',fac,'Vertices',vertice,'FaceVertexCData',color,'FaceColor','flat');  % patch function
在上面的例子中,颜色是6*3矩阵,其中每行具有所需颜色的RGB值。每行中的颜色将按定义顺序应用于面