使用matlab在球面上生成点,根据仰角和方位角
[x,y,z] = sphere(50);
% 缩放球体并绘制
r = 5; % 半径设置为 5
x = x * r;
y = y * r;
z = z * r;
% 创建一个图形对象,并设置旋转模式
figure;
rotate3d on;
h_surf = surf(x, y, z, 'EdgeColor', 'none', 'FaceAlpha', 0.7);
% 定义旋转的速度和方向
w = 10;
v = [0 0 1];
% 循环旋转球体
% 计算每一帧旋转的角度
dtheta = w * pi / 180; % 角度转弧度
R = [cos(dtheta), -sin(dtheta), 0;
sin(dtheta), cos(dtheta), 0;
0, 0, 1];
% 旋转球体
xyz = [x(:) y(:) z(:)];
xyz_rotated = xyz * R;
x_rotated = reshape(xyz_rotated(:,1), size(x));
y_rotated = reshape(xyz_rotated(:,2), size(y));
z_rotated = reshape(xyz_rotated(:,3), size(z));
% 更新球体的坐标
set(h_surf, 'XData', x_rotated, 'YData', y_rotated, 'ZData', z_rotated);
count = 0;
for i=0:20:91
for j=0:20:360
count=count+1;
x(count,1)=sin(i*pi/180)*cos(j*pi/180)*r;
y(count,2)=sin(i*pi/180)*sin(j*pi/180)*r;
z(count,3)=cos(i*pi/180)*r;
end
end
%z(:,3) = abs(z(:,3)); % 保留 z 坐标为正的点
% 绘制半球面上的点
hold on;
plot3(x(:,1),y(:,2), z(:,3), '.', 'MarkerSize', 15, 'Color', 'red');
% 更新图形
drawnow;
不得不说感谢chatgpt太有用啦