用Matlab绘制3-D RGB立方体模型 [英] Drawing 3-D RGB cube model with Matlab

查看:946
本文介绍了用Matlab绘制3-D RGB立方体模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这段代码来绘制RGB立方体,但是它的颜色不完全正确吗?

I wrote this code to draw an RGB cube, but it's color not exact as true?

%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]

%Plot the cube ----- gives each face a different color and creates the cube at a convenient viewing angle
patch('Vertices',vm,'Faces',fm,'FaceVertexCData',hsv(8),'FaceColor','interp');
view(3);

推荐答案

到时候,我完成了代码,@ horchler的答案已经在线了.看起来很完美.无论如何也要发布我的.

By the time, I finished the code, @horchler's answer was online already. It looks perfect. Anyway posting mine as well.

要了解您要应用的颜色,我按如下方式打印了hsv(8)的值.

To understand what colors you are applying, I printed values of hsv(8) as follows.

1.0000         0         0
1.0000    0.7500         0
0.5000    1.0000         0
     0    1.0000    0.2500
     0    1.0000    1.0000
     0    0.2500    1.0000
0.5000         0    1.0000
1.0000         0    0.7500

但是实际上要应用的是红色,绿色,蓝色,白色和青色,品红色,黄色,黑色.请参考此链接以了解有关Matlab颜色的信息代码.因此,我们可以根据您的要求将颜色手动应用于每个顶点.我如下更改了您的代码.

But what you want to apply actually is red, green, blue, white, and cyan, magenta, yellow, black. Please refer to this link to know about Matlab color codes. Hence we can apply the colors to each vertex manually based on your requirement. I changed your code as follows.

% 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];

% Plot the cube ----- gives each face a different color and creates the 
% cube at a convenient viewing angle
clear cdata;
cdata = [
    0 0 0; % black
    1 0 0; % red
    1 0 1; % magenta
    0 0 1; % blue
    0 1 0; % green
    1 1 0; % yellow
    1 1 1; % white
    0 1 1; % cyan
    ];

patch('Vertices',vm,'Faces',fm,'FaceVertexCData',cdata,'FaceColor','interp');

axis equal;
axis off;
view(3);

输出:

这篇关于用Matlab绘制3-D RGB立方体模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆