matlab画半球面,Matlab 绘制3D半球

R=10;

z=real(zeros(201,201));

m=0;

n=0;

step = 0.1;

for x=-R:step:R

m = m + 1;

%x

for y=-sqrt(R*R - x*x):step:sqrt(R*R - x*x)

%y

n = int32(y / step) + R / step + 1;

%n

z(n, m) = real(sqrt(R*R - x*x - y*y));

endfor

endfor

%z

mesh(z);

另一种方法(from octave):

function [xx, yy, zz] = sphere (varargin)

[hax, varargin, nargin] = __plt_get_axis_arg__ ("sphere", varargin{:});

if (nargin > 1)

print_usage ();

elseif (nargin == 1)

n = varargin{1};

else

n = 20;

endif

theta = linspace (0, 2*pi, n+1);

phi = linspace (-pi/2, pi/2, n+1);

[theta,phi] = meshgrid (theta, phi);

x = cos (phi) .* cos (theta);

y = cos (phi) .* sin (theta);

z = sin (phi);

if (nargout > 0)

xx = x;

yy = y;

zz = z;

else

oldfig = [];

if (! isempty (hax))

oldfig = get (0, "currentfigure");

endif

unwind_protect

hax = newplot (hax);

surf (x, y, z);

unwind_protect_cleanup

if (! isempty (oldfig))

set (0, "currentfigure", oldfig);

endif

end_unwind_protect

endif

endfunction

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值