MATLAB: Showing intersection line between several surfaces in a 3D plot

3d plots

Hi all,
I would like to generate a 2D (x,y) plot into which the intersections of 3D surfaces (x,y,z) are projected.
At the moment, I am generating a 3 D plot with all the surfaces in different colors, and then rotate that plot such that the viewer looks along the z axis (i.e. it looks like a 2D plot). Next, I am importing that 2D image into a graphics program, draw the intersection lines manually, and then change the colors of the various surfaces to white.
Is there any better way to do this? Ideally, I'd like MATLAB to show the intersection lines automatically, without the need to do the post-processing in a graphics program.
Thanks for your help!
Sincerely, Patrick

Best Answer

If the two surfaces are defined on a rectangular grid, then it is easy to do. Call one of the surfaces f(x,y), the second g(x,y). They are each functions, even though you may not know their functional forms.
The "line" of intersection is a 1-manifold, a level set of points that has the property that
z(x,y) = f(x,y) - g(x,y) = 0.
This set of points lives in the (x,y) plane.
How do you find that set? Use the contour plotting functionality in MATLAB. It can generate the set of points such that the above relationship holds.
I would use the contourc function to return the contour at z = 0. (There may be more than one such curve, so you need to check for that.) Along this manifold in (x,y), you can get the height by interpolation. Use interp2 to find that height at each point.
I would do the plot differently from how you describe though. Plot the two surfaces as semi-transparent surfaces. Set the facealpha (and edgealpha) properties to be less than 1, so you can see through the surfaces. Now just plot the intersection curve as a solid line, in black. It will stand out from the surfaces because you will not plot it as transparent.
Related Question