Plotting overlapping surfaces...

24 Ansichten (letzte 30 Tage)
Dimitrios
Dimitrios am 2 Mai 2011
Beantwortet: Shaozhen Lin am 6 Mai 2016
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 Kommentare
Dimitrios
Dimitrios am 2 Mai 2011
i do not know how to upload a screenshot on this site, but i can try to send you one on your email, if you are interested.
part of the code i placed further down in this thread.
Andrew Newell
Andrew Newell am 2 Mai 2011
If you can post a screenshot anywhere on the Web, you can use <<>> to link to it (see Markup Help).

Melden Sie sich an, um zu kommentieren.

Antworten (4)

Patrick Kalita
Patrick Kalita am 2 Mai 2011
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 Kommentare
Dimitrios
Dimitrios am 2 Mai 2011
thank you very much for the help. I had already tried the change of renderer but it had not solved the problem. Nevertheless, thank you very much for the link, at least now i know the terminology for this problem , and perhaps i can find a workaround.
I have also thought of the offset in the data, but the number of the surfaces changes and adding a small displacement to each of the surfaces results to a completely different shape when a large amount of surfaces take part.
Again thanks for the valuable help.
Best regards,
dimitrios
Patrick Kalita
Patrick Kalita am 2 Mai 2011
@Andrew, correct. When and how you see this problem will depend on your graphics card.

Melden Sie sich an, um zu kommentieren.


Shaozhen Lin
Shaozhen Lin am 6 Mai 2016
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.

Andrew Newell
Andrew Newell am 2 Mai 2011
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)

Dimitrios
Dimitrios am 2 Mai 2011
The following part of the code is repeated in a loop, to plot the different surfaces. at each loop the tape.x, tape.y, and tape.z, values are changing
h1 = surface(tape.x(minz:maxz,:),tape.y(minz:maxz,:),tape.z(minz:maxz,:), 'facecolor',colorV(xi,:),'edgecolor','none', 'FaceAlpha', 1);
h2 = surface(tape.x((minz: maxz),:),tape.y((minz: maxz),:),tape.z((minz: maxz),:), 'facecolor','none','edgecolor',[0 0 0], 'MeshStyle', 'column', 'LineWidth', fiberWidth/10);
h4 = surface(tape.x(maxz:end,:),tape.y(maxz:end,:),tape.z(maxz:end,:), 'facecolor',colorV(xi,:),'edgecolor','none', 'FaceAlpha', 1);
h5 = surface(tape.x((maxz:end),:),tape.y((maxz:end),:),tape.z((maxz:end),:), 'facecolor','none','edgecolor',[0 0 0], 'MeshStyle', 'column', 'LineWidth', fiberWidth/10);
  1 Kommentar
Andrew Newell
Andrew Newell am 2 Mai 2011
This material would be better located in your original question, which you are free to edit.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by