Plotting overlapping surfaces...
24 次查看(过去 30 天)
显示 更早的评论
I have two or more 3D surfaces that overlap eachother at certain areas (e.g. four spirals of a certain thickness with different pitch, but same radius). I use the "surface" function of matlab to give each of the surfaces a different face color but the same edge color.
The problem is that at the overlapping areas the surface colors mix with eachother, whereas i would like to be able to see only color of the top-most surface at that area (meaning the surface that was plotted last at that area). Since not all surfaces overlap at the same areas, each of the overlapping area should have a different color.
It seems that the way OpenGL is used by Matlab does not allow such plotting of overlapping surfaces. I tried , surf, mesh, surfc and the rest of the functions, and got similar results.
Am i missing something? Is there a way to overcome this problem?
Any help would be greatly appreciated.
Dimitrios
3 个评论
Andrew Newell
2011-5-2
If you can post a screenshot anywhere on the Web, you can use <<>> to link to it (see Markup Help).
回答(4 个)
Patrick Kalita
2011-5-2
The situation I think you are describing is known as z-stitching or z-fighting. It happens when two surfaces occupy the same coplanar space, and the graphics hardware has no idea which one to draw on top. This page describes in a little more detail.
Here is an example that shows it in MATLAB (at least on the graphics hardware on my machine):
x1 = [0:9; 0:9];
y1 = [0:9; 1:10];
z1 = zeros(2,10);
x2 = x1;
y2 = [9:-1:0; 10:-1:1];
z2 = z1;
s1 = surface(x1, y1, z1, 'FaceColor', [1 0 0], 'EdgeColor', 'none');
s2 = surface(x2, y2, z2, 'FaceColor', [0 1 0], 'EdgeColor', 'none');
set(gcf, 'Renderer', 'opengl');
view(0, 60)
There isn't really a generic solution to the problem. For some scenes, it may be acceptable to manually switch back the painters renderer:
set(gcf, 'Renderer', 'painters');
As I said, this won't always work. This may not give correct visual results for some scenes and it may give performance issues for others.
For other scenes you may be able to adjust the surface data to avoid the issue. For the example above, you could add a small amount to z2:
set(gca, 'ZLimMode', 'manual');
z2 = z1 + 0.0001;
set(s2, 'ZData', z2)
3 个评论
Patrick Kalita
2011-5-2
@Andrew, correct. When and how you see this problem will depend on your graphics card.
Shaozhen Lin
2016-5-6
Have you solved this problem? I have met a similar problem and solved it. You can separate the two or more surfaces a tittle to make the top-most surface is strictly on the top rather than overlaping. Then only the color of the top-most surface will be seen.
0 个评论
Andrew Newell
2011-5-2
If I type
cplxroot(3)
I don't see any color mixing. It uses surf to plot. Maybe you have inadvertently set the transparency to below 1. Try
h = surf(...)
get(h,'FaceAlpha')
If the answer is not 1, then type
set(h,'FaceAlpha',1)
0 个评论
Dimitrios
2011-5-2
1 个评论
Andrew Newell
2011-5-2
This material would be better located in your original question, which you are free to edit.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!