在 MATLAB 中以 3D 方式可视化日食,并受到近平面裁剪的抑制

问题描述 投票:0回答:1

我正在尝试在 MATLAB 中可视化日食,将太阳和月亮绘制为球体,并将相机放置在地球的位置,为简单起见,将所有内容沿 x 轴排列。 看来当我尝试使用正确的距离时,月亮没有被渲染。 据我所知,这是由于近平面剪裁而发生的。 是否有解决方案,以便更一般地,可以可视化非常靠近相机的相对较小的物体?

以下是当前代码生成的内容,相机远离太阳,以便确实渲染月球:
enter image description here

但是当我尝试将相机移近时,月亮就消失了。

重现问题的 MATLAB 代码:

% Define sizes/positions of sun, earth, moon, with the camera on earth
sunRadius         = 696340;                            % Sun radius in km
moonRadius        = 1737;                              % Moon radius in km
earthPosition     = 149600000;                         % Distance from Sun center to Earth center (1 AU)
earthMoonDistance = 384400;                            % Distance from Earth to Moon (in km)
moonPosition      = earthPosition - earthMoonDistance; % Moon position relative to Sun

% Move camera just a little further away from the moon to avoid near-plane clipping
camPosition  = earthPosition*1.01; 
% If we put the camera right at the earth, the moon is not rendered due to near-plane clipping:
% camPosition  = earthPosition;

% Plot Sun and Moon as spheres, and set camera position
figure;
set(gcf, 'WindowState', 'maximized')

hold on;
axis equal;
% Configure lighting for better visualization
lighting phong;
light('Position', [1 1 1], 'Style', 'infinite');

% Plot the Sun (yellow sphere) at the origin
[x_sun, y_sun, z_sun] = sphere(50);
sun = surf(sunRadius * x_sun, ...
           sunRadius * y_sun, ...
           sunRadius * z_sun);
set(sun, 'FaceColor', [1, 1, 0], 'EdgeColor', 'none');

% Plot the Moon (grey sphere) relative to the Sun
[x_moon, y_moon, z_moon] = sphere(50);
moon = surf(moonRadius * x_moon + moonPosition, ...
            moonRadius * y_moon, ...
            moonRadius * z_moon);
set(moon, 'FaceColor', [0.5, 0.5, 0.5], 'EdgeColor', 'none');

% Set up camera properties relative to the Sun
camproj('perspective')
campos([camPosition, 0,0]); % Camera at approximately
camtarget([camPosition-1, 0, 0]); % Camera looking down the x-axis towards the origin
camva(1); % Set camera view angle small enough to zoom in on eclipse
matlab
1个回答
0
投票

我认为你可以通过缩小轴范围来解决这个问题。最简单的修复方法是运行

axis tight

Result when using axis tight

© www.soinside.com 2019 - 2024. All rights reserved.