- 基本原理:
實質為利用球面參數方程,利用網格化數據繪制
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]時:

2.rgb=[0,0,1]時:
