Making a spherical cap using equations of sphere
16 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to make a spherical cap using points or nodes and mesh grid . I dont want to use built in functions. I am having some problems. Here is my code
% plotting script
% select : which plot you want
set(groot,'defaultLegendInterpreter','latex');
set(0, 'DefaultFigureRenderer','painters');
set(0, 'DefaultFigureRenderer', 'OpenGL');
set(groot,'defaultAxesTickLabelInterpreter','latex');
set(groot,'defaulttextInterpreter','latex');
%%
% Plot the sphere or spherical patch
p = linspace(-1/2,1/2,10);
radius_1 = p(size(p,2))/2;
radius_2 = radius_1 /2;
[X,Y,Z] = meshgrid(p,p,p);
theta= atan(Y./X);
active = (X.^2+Y.^2 +Z.^2 <= radius_1);
active_2 = (X.^2+Y.^2 +Z.^2 <= (radius_1 -radius_2)) ;
figure()
plot3(X(active),Y(active),Z(active),'o','MarkerFaceColor','red');
hold on
plot3(X(active_2),Y(active_2),Z(active_2),'o','MarkerFaceColor','cyan');
I cannot draw the spherical cap. I have the thetha but how do i use it to cut the sphere to make spherical cap and i want to know which nodes are inside the cap and which are outside the cap using mesh grid.
Does anyone knows how to do it?
1 个评论
Bruno Luong
2022-3-24
X.^2+Y.^2 +Z.^2 is the square of the distance to origin, then you compare with radius and diffderence of radius, it does noot make any interpretable sense to me.
采纳的回答
Bruno Luong
2022-3-24
phi=linspace(pi/2,pi/6,30); % the cap end is determined by pi/6 change accordinglt
theta=linspace(0,2*pi,120);
r=3;
[PHI,THETA]=meshgrid(phi,theta);
X=r*cos(THETA).*cos(PHI);
Y=r*sin(THETA).*cos(PHI);
Z=r*sin(PHI);
surf(X,Y,Z)
axis equal;
8 个评论
Bruno Luong
2022-3-24
Sorry I don't understand what you ask for.
And in your last code you are still compare distance squared with radius without squared.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!