Plotting level sets of a function on a triangulated surface.
Show older comments
I want to plot the level sets of one function g(x,y,z) as curves on an isosurface f(x,y,z)=c. The following code comes close, but I need help getting over the finish line.
[x,y,z] = meshgrid(-1:.025:1);
f = x.^2 +y.^2 + z.^2;
g = x.^2 - y.^2;
c = 0.8
[faces,verts,colors] = isosurface(x,y,z,f,c,g);
patch('Vertices',verts,'Faces',faces,'FaceVertexCData',colors,...
'FaceColor','interp','EdgeColor','none')
view(3)
axis equal
colormap(turbo(10))

In this example code, we can see the level sets as the boundaries between the colored regions, but what I really want is
- Curves on a solid-colored sphere
- The ability to choose which values of g(x,y,z) get plotted
- The ability to choose line styles, colors, and thicknesses
1 Comment
Roy Goodman
on 3 Jul 2025
Edited: Roy Goodman
on 13 Jan 2026
Accepted Answer
More Answers (1)
Categories
Find more on Lighting, Transparency, and Shading 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!

