Reputation: 81
I want to plot a solid sphere in matlab and hence i trid the following code
for radius = 0:0.1:10
theta = linspace(0,2*pi);
phi = linspace(0,pi/2);
[theta,phi] = meshgrid(theta,phi);
[xs,ys,zs] = sph2cart(theta,phi,radius);
surf(xs,ys,zs);
end
But I still only get the surface of the outer most sphere.Any help is appreciated.
Upvotes: 0
Views: 9271
Reputation: 21563
As can be made out from the comments, the code to plot a solid half sphere would be:
hold on
for radius = 0:0.1:10
theta = linspace(0,2*pi);
phi = linspace(0,pi/2);
[theta,phi] = meshgrid(theta,phi);
[xs,ys,zs] = sph2cart(theta,phi,radius);
surf(xs,ys,zs);
end
For a full sphere one would also be interested in
surf(xs,ys,-zs);
Upvotes: 1