它是需要更新的颜色图,以使您的绘图看起来像中的颜色图你的链接 http://lodev.org/cgtutor/images/colorcube.jpg。您不能简单地使用内置函数来直接生成正确的序列。另外,调用hsv(8)
产生您不需要的其他颜色(在命令行窗口中打印出来查看),但不包括纯白色或黑色。您可以使用hsv(6)
并附加[0 0 0]
and [1 1 1]
,但您需要确保顺序与代码的其余部分一致(fm
and vm
).
这是您的代码的修订版本 –cm
矩阵对每个顶点的颜色图案进行编码:
% Define a six row by four column matrix to define the six cube faces
fm = [1 2 6 5;
2 3 7 6;
3 4 8 7;
4 1 5 8;
1 2 3 4;
5 6 7 8];
% Define an eight row by three column matrix to define the vertices at which the faces meet
vm = [0 0 0;
1 0 0;
1 1 0;
0 1 0;
0 0 1;
1 0 1;
1 1 1;
0 1 1];
% RGB colors for each vertex
cm = [0 0 0;
0 1 0;
1 1 0;
1 0 0;
0 0 1;
0 1 1;
1 1 1;
1 0 1];
% Plot the cube - gives each face a different color and creates the cube at a convenient viewing angle
figure('Color','w')
patch('Vertices',vm,'Faces',fm,'FaceVertexCData',cm,'FaceColor','interp');
view(120,30);
% Plot axes
axis equal;
axis off;
d1 = 1.25;
line([0 0 0;d1 0 0],[0 0 0;0 d1 0],[0 0 0;0 0 d1],'Color','k','LineWidth',2);
% Label axes
d2 = 0.1;
text([0 1 0],[1 -d2 -d2],[-d2 0 1],'255','FontSize',11,'HorizontalAlignment','center');
text([0 d1 0],[d1 d2 d2],[d2 0 d1],{'R','G','B'},'FontSize',16);
这会产生一个看起来像这样的数字