How can I draw a 2D filled contour onto an arbitrary surface in 3D space?
Show older comments
I am drawing a 3D box and would like to have one of the surfaces of the box be a filled contour plot. I can draw the box like this:
figure;hold all;
vertices = [-2.5 0 0;2.5 0 0;2.5 13 0;-2.5 13 0;-2.5 0 2;2.5 0 2;2.5 13 2;-2.5 13 2];
faces = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8]; % draw all faces
% faces = [2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8]; % don't draw the front face
patch('Vertices',vertices,'Faces',faces,'FaceVertexCData',hsv(size(faces,1)),'FaceColor','flat');
axis equal; xlim([-6 6]); ylim([-2 14]); zlim([0 6]); view(37.5,30);
That will produce the box I want:

I can create the filled contour plot I want like this:
acrossPorts = -2:0.5:2;
verticalPorts = 0.25:0.5:1.75;
[AP,VP] = meshgrid(acrossPorts,verticalPorts);
portPressures = [
1 2 3 4 5 4 3 2 1
11 22 33 44 55 44 33 22 11
10 20 30 40 50 60 70 30 10
1 2 3 4 5 8 6 4 1];
figure;hold all;
contourf(AP,VP,portPressures,100,'linestyle','none');
plot(AP,VP,'ok');
axis equal; xlim([-2.5 2.5]); ylim([0 2]);

What I want to do is essentially replace the solid red surface on the first figure with the contour of the second figure. I'd like to have the circles, but if I lose those it's not a big problem. I'd also like to extrapolate the contour to the boundary of my 5x2 box for visual purposes, but again, if I have to sacrifice that it's OK.
I have not been able to find a function that lets me do what I want directly, so what I tried was to transform the contour after drawing it. I did this by drawing the box with the "don't draw the front face" line instead and then did this for the contour:
ax=gca; HG=hgtransform(ax);
contourf(AP,VP,portPressures,100,'linestyle','none','parent',HG);
HG.Matrix = makehgtform('xrotate',pi/2);
This stuck the contour in the right place, but it isn't being drawn correcly or something:

I can change the view using view(10,7); and it looks like this:

So the whole contour really is there and in the correct spot, but I can't get it to reliably be visible at arbitrary orientations. And I suspect that if I try to draw other surfaces like this with more complicated transformations, they certainly aren't going to work any better.
If someone can offer a better/more reliable way to draw the filled contour where I want it to be, I'd greatly appreciate it.
Accepted Answer
More Answers (0)
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
