Occlusion for two surfaces in linked axes

I wonder if there is a way to render two surfaces on top of each other, so that the surfaces properly occlude each other.
In the following example you can see the standard behaviour:
[X,Y,Z] = peaks(128);
X2 = X(32:64,32:64);
Y2 = Y(32:64,32:64);
Z2 = Z(32:64,32:64)+1;
fig = figure(1);clf
axes1 = axes('Parent',fig);
surf1 = surf(X,Y,Z,'Parent',axes1);
surf1.EdgeColor = 'none';
axis(axes1,'off');
axes2 = axes('Parent',fig);
surf2 = surf(X2,Y2,Z2,'Parent',axes2);
surf2.EdgeColor = 'red';
surf2.FaceAlpha = 0.5;
axis(axes2,'off');
colormap(axes1,parula);
colormap(axes2,cool);
linkprop([axes1,axes2],{'CameraPosition','CameraUpVector','XLim','YLim','ZLim'});
The second surface is always rendered on top of the first, even if it not be seen at some points, due to being occluded by the first.
I can decrease the transparency of the second surface, but it leads to clutter and makes it difficult to see which surface is on top of which.
Is there some axes property that allows me to render both surfaces as if their data came from a single surface?

5 Comments

What's the reason for separate axes with the linkprop command? Unless I'm missing something, using
hold(axes1,'on');
surf2 = surf(X2,Y2,Z2,'Parent',axes1);
does exactly what you're asking.
You are entirely correct. I unfortunately forgot to include the colormaps of both axes in the example code. I use two axes to set different colormaps for both surfaces.
I have amended the example to include that.
My best suggestion right now is to use the second colormap to build a CData input to the second surf() call. I'm late for work so I can't build a working example, but I'll try tonight if you can't figure it out.
jonas
jonas on 29 Nov 2017
Edited: jonas on 29 Nov 2017
Thank you very much for the suggestion, this solved my problem.
I didn't know that 3d colormaps were a possible input to surf :)
Glad to help.

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 24 Nov 2017

Commented:

on 29 Nov 2017

Community Treasure Hunt

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

Start Hunting!