matlab 空心立方体,Matlab 利用参数方程绘制空心球体

基本原理:

实质为利用球面参数方程,利用网格化数据绘制x=R*sin(theta)*cos(phi)

y=R*sin(theta)*sin(phi)

z=R*cos(theta)

绘制函数:function draw_sphere(rgb)

%此函数旨在绘制各种颜色的球面

%rgb为颜色参数,为三个0~1之间的三个数组成的数组

%such as:    [1,0,0],  [1,0.2,0.5], [0,1,0.5]

%you may run as :  draw_sphere([1,0,0])

%author:   杨文波 12/16/2016

t=linspace(0,2*pi,100*pi);

p=linspace(0,2*pi,100*pi);

[theta,phi]=meshgrid(t,p);                  %网格化数据

R=1;                                        %设置球面半径

x=R*sin(theta).*cos(phi);                   %代入参数方程

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

z=R*cos(theta);

colormap(rgb);

surf(x,y,z);                                %绘制表面图

daspect([1,1,1]);                           %设置xyz轴比例为1:1:1

camlight;                                   %设置默认光照

shading interp;

axis off;                                   %隐藏坐标轴

end简单调用:figure(1)

draw_sphere([1,0,0.5]);

figure(2)

draw_sphere([0,0,1]);NOTE:

不推荐使用subplot分割绘图,因为colormap作用域为整个figure结果展示:

#### 1.rgb=[1,0,0.5]时:

edd418f7a889544e0c2c02e950cad033.png

#### 2.rgb=[0,0,1]时:

4cb4b3811267f7ab233df2a2f4169c72.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值