clc;close all;clear all;warning off;%清除变量

% 地球半径(单位:千米)
R = 6371;

% 定义角度范围
theta = linspace(0, 2*pi, 100); % 经度范围
phi = linspace(0, pi, 100); % 纬度范围(从北极到南极,0到pi)

% 生成网格
[ThetaGrid, PhiGrid] = meshgrid(theta, phi);

% 根据球体的参数方程计算X, Y, Z坐标
X = R * sin(PhiGrid) .* cos(ThetaGrid);
Y = R * sin(PhiGrid) .* sin(ThetaGrid);
Z = R * cos(PhiGrid);

% 绘制地球仪
figure;
surf(X, Y, Z, 'EdgeColor', 'none'); % 无边缘颜色的表面图

% 设置图形属性
axis equal; % 确保各轴比例相同,使球体看起来是圆的,而不是椭圆的
xlabel('X');
ylabel('Y');
zlabel('Z');
title('地球仪模型');
grid on;

% 添加光照和材质以增强3D效果
shading interp; % 平滑着色
camlight left; % 添加左侧光源
lighting phong; % 使用Phong光照模型
material([0.5 0.5 0.5]); % 设置材质颜色为灰色,模拟地球的颜色

% 可选:为地球添加经纬线
hold on;
for lon = 0:30:330 % 经线,每隔30度画一条
    plot3(R*cosd(lon)*sind(PhiGrid), R*sind(lon)*sind(PhiGrid), R*cosd(PhiGrid), '--k');
end
for lat = -90:15:90 % 纬线,每隔15度画一条
    circleRadius = R*cosd(lat);
    circleTheta = linspace(0, 2*pi, 100);
    plot3(circleRadius*cos(circleTheta), circleRadius*sin(circleTheta), repmat(R*sind(lat),1,length(circleTheta)), '--k');
end
hold off;

% 调整视角以便更好地查看地球仪
view(3); % 设置3D视角

MATLAB绘制地球仪-LMLPHP

04-14 06:01