简体   繁体   English

如何在MATLAB中为表面的不同侧面选择不同的颜色

[英]How to choose different colors for different sides of a surface in MATLAB

I am plotting orientable open surfaces in MATLAB, where each side of the surface is well defined.我正在 MATLAB 中绘制可定向的开放曲面,其中曲面的每一侧都定义明确。 I want to have each side be a different color so it is easy to tell if you are looking at the "front" or back.我想让每一面都是不同的颜色,这样很容易判断你是在看“正面”还是背面。 I can't seen to get this in MATLAB.我看不到在 MATLAB 中得到这个。 I've tried back face lighting but this does not produce a difference.我试过背面照明,但这不会产生差异。 I'm not sure if it's because my data is an open surface rather than a closed one.我不确定这是不是因为我的数据是一个开放的表面而不是一个封闭的表面。 It could also be the choice of other variables.它也可能是其他变量的选择。 Here is a code snippet.这是一个代码片段。

       h = surf(xc,yc,-zc);
       set(h,'faceColor',[0.75 0.75 0.75],'BackFaceLighting','lit');   

I've tried different choices for the option.我已经为选项尝试了不同的选择。 Ultimately what I'd like is to have the front face (the one visible) be a dark shade of grey and the back a different lighter shade of grey.最终,我想要的是正面(可见的)是深灰色,背面是不同的浅灰色。 There are cases when the surfaces fold or contort and part of the back is visible.在某些情况下,表面会折叠或扭曲,并且可以看到部分背部。 Also, if another plotting function, other than surf(), does this please let me know.另外,如果除了 surf() 之外的另一个绘图函数是否这样做,请告诉我。

SciLab actually does this by default with blue and yellow (or some other combo of colors). SciLab 实际上默认使用蓝色和黄色(或其他一些颜色组合)执行此操作。 So I've not had to worry about specifying options.所以我不必担心指定选项。

You can plot two surfaces, one slightly lower then the other.您可以绘制两个曲面,一个略低于另一个。

Example:例子:

[X, Y, Z] = peaks(25);
figure;
surf(X, Y, Z, 'faceColor', [0.15 0.15 1]);
hold on
Z2 = Z - 0.01; %Set Z2 values slightly lower then Z
surf(X, Y, Z2, 'faceColor', [0.75 0.75 0.75], 'BackFaceLighting', 'lit');
hold off

Result:结果:
在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM