make slices and project to 2d plot
Mostrar comentarios más antiguos
Hello. I have a sphere that I want to make slices of. I want to be able to slice the sphere from the z axis at any point and obtain a 2d circle plots on the x, y axis. The slice at z = 0 would be the biggest circle and z = 4 would be smallest circle. How can I do this? Thank you.

2 comentarios
darova
el 2 de Abr. de 2021
Can't you calculate radius of a circle and just use plot3?
Nne Akallu
el 8 de Abr. de 2021
Respuestas (1)
The general idea would be to use contour()
contour(X,Y,Z,V) will draw the contour at each level specified by the vector V.
If you want to only specify one level, specify it as [1 1]*mylevel (i.e. V is a minimum of 2 elements)
Bear in mind, contour just throws the plot at Z=0. If you don't need your surf plot centered, you can always offset it. You can probably offset the zlabels to match. Off the top of my head, idk how you'd offset the contour plot.
[X,Y,Z]=sphere;
r=5;
X2=X*r;
Y2=Y*r;
Z2=Z*r;
% say i want to offset it
surfoffset=5;
clf
surf(X2,Y2,Z2+surfoffset); hold on
% fudge the z axis labels
osz=@(x) num2str(str2num(x)-surfoffset);
set(gca,'zticklabels',cellfun(osz,get(gca,'zticklabels'),'uniformoutput',false))
% pick the z levels you want to plot
% note that these are WRT the non-offset object
contour(X2,Y2,Z2,[0 1 2 3 4])
would give this:

I'm sure there are more elegant ways of dealing with an offset contour.
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!