sphere made of 2d circles in 3d plot
    7 次查看(过去 30 天)
  
       显示 更早的评论
    
hi i made the code below the create a sphere using 2d circles in a 3d plot:
r=1
teta=-pi:0.01:pi
x=r*cos(teta);
y=r*sin(teta);
axis square
for i=0.0:0.1:1
      z=i*sin(teta);
      plot3(x,y,z);    
      hold on
end
for i=0.0:-0.1:-1
      z=i*sin(teta);
      plot3(x,y,z);
      hold on
end
for i=0.0:0.1:1
      y=i*sin(teta);
      plot3(x,y,z);
      hold on
end
for i=0.0:-0.1:-1
      y=i*sin(teta);
      plot3(x,y,z);
      hold on
end
however it doesn't create a clear sphere from some views it shows sphere from some views it shows something( i don't know what ).
anyway i want to creat a sphere using the code below to create a sphere using 2d circles(code below).
r=1
teta=-pi:0.01:pi
x=r*cos(teta);
y=r*sin(teta);
z=zeros(1,numel(x));
plot3(x,y,z);
1 个评论
  Walter Roberson
      
      
 2014-1-2
				This should probably have been a continuation of http://www.mathworks.co.uk/matlabcentral/answers/111219-3d-plot-2d-cirlce-specific-degree-tilt-slope
回答(2 个)
  Amit
      
 2014-1-2
        You can use sphere function to create a sphere. Do you specifically need sphere from circles?
2 个评论
  Amit
      
 2014-1-2
				If you really just want to use 2-D circles, the code will be something like this:
r=1;
teta=-pi:0.1:pi;
x=zeros(size(teta));
y=x;
z = x;
axis square
for i=(-1)*r:0.1:r
    x = ((r^2-i^2)^0.5)*cos(teta);
    y = ((r^2-i^2)^0.5)*sin(teta);
    z = i*ones(size(teta));
    plot3(x,y,z);
    hold on;
end
  Roger Stafford
      
      
 2014-1-2
        
      编辑:Roger Stafford
      
      
 2014-1-2
  
      To use 'surf' do this:
 r = 1;
 [theta,phi] = ndgrid(linspace(0,pi),linspace(0,2*pi));
 X = r*cos(phi).*sin(theta);
 Y = r*sin(phi).*sin(theta);
 Z = r*cos(theta);
 surf(X,Y,Z)
or if you just want circles, do this:
 r = 1;
 [theta,phi] = ndgrid(linspace(0,pi),linspace(0,2*pi));
 X = r*cos(phi).*sin(theta);
 Y = r*sin(phi).*sin(theta);
 Z = r*cos(theta);
 for k = 1:numel(theta)
  plot3(X(k,:),Y(k,:),Z(k,:))
  hold on
 end
(Corrected)
0 个评论
另请参阅
类别
				在 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!



