how to plot a function on a 3D sphere?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
N0=100;
r_med=[0.445 0.889 1.445 2];
sigma_g=7;
N_ang=91;
theta = (0:1:360)/180*pi;
phi = (0:1:360)/180*pi;
[x,y]=meshgrid(theta,phi);
Num_r = 50e3;
r = linspace(1,50,Num_r)./2;
I0=1;Q0=0;U0=0;V0=0;
for i = 1:length(r_med)
% [P11(i,:),P12(i,:),P33(i,:),P34(i,:),Qsca_c(i,:),~,~] = ZK_W_Cloud_PhaseFunc(N0,r_med(i),sigma_g,N_ang);
P11_t(i,:) = [P11(i,:) fliplr(P11(i,2:end))];
P12_t(i,:) = [P12(i,:) fliplr(P11(i,2:end))];
P33_t(i,:) = [P33(i,:) fliplr(P11(i,2:end))];
P34_t(i,:) = [P34(i,:) fliplr(P11(i,2:end))];
P1=repmat(P11_t(i,:),length(phi),1);
P2=repmat(P12_t(i,:),length(phi),1);
P3=repmat(P33_t(i,:),length(phi),1);
P4=repmat(P34_t(i,:),length(phi),1);
z = P1.*I0+((P2.*Q0.*cos(2*y))+(P2.*U0.*sin(2*y)));
end
[v,u,w]=sph2cart(x,y,z);
v=z.*cos(y).*cos(x);
u=z.*sin(y).*cos(x);
w=z.*sin(y);
figure,
surf(v,u,w),xlabel('x'),ylabel('y'),zlabel('z')
%set(gca,'zscale','log');
I want to obtain the figure as shown

However, the output of my code is just a circle

Please correct me.
2 commentaires
Walter Roberson
le 3 Jan 2022
How does this differ from https://www.mathworks.com/matlabcentral/answers/1620195-how-to-plot-a-3d-function?s_tid=srchtitle ?
Réponses (1)
Matt J
le 3 Jan 2022
Modifié(e) : Matt J
le 3 Jan 2022
My recommendation would be to build these surfaces using the cylinder function, e.g.,
R=1; %radius of circular cross-section
d=1.5; %radius of torus
fn=@(z) 2*R*(z-0.5);
x=fn( linspace(0,1) );
r1=d-sqrt(R^2-x.^2); %inner half surface
r2=d+sqrt(R^2-x.^2); %outer half surface
[X1,Y1,Z1]=cylinder(r1,40);
[X2,Y2,Z2]=cylinder(r2,40);
h(1)=surf(X1, Y1, fn(Z1)); hold on
h(2)=surf(X2, Y2, fn(Z2)); hold off
rotate(h,[1,0,0],90)
axis equal
xlabel X; ylabel Y; zlabel Z;
view(35,30)
5 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




