make slices and project to 2d plot

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

darova
darova 2021년 4월 2일
Can't you calculate radius of a circle and just use plot3?
Nne Akallu
Nne Akallu 2021년 4월 8일
Hello. I can, but I would like to pick a random coordinate and plot. The issue is finding the radius at that coordinate.

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2021년 4월 2일
편집: DGM 2021년 4월 3일

0 개 추천

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.

카테고리

질문:

2021년 4월 1일

댓글:

2021년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by