首页 > 解决方案 > MATLAB 隐藏线移除的限制?

问题描述

我在 Mathwork 的网站上问过这个问题,所以如果不允许交叉发布,请告诉我,我会删除它。

我正在尝试在 MATLAB 中一起渲染小对象和大对象。我正在使用相机命令来限制我的视野,以便我可以看到两者。但是,当我这样做时,小物体上的隐藏线移除失败。我原以为可以在机器精度下对浮点数进行隐藏线删除,但似乎并非如此。这是我的显卡的功能还是我可以解决这个问题?下面的代码是我能想到的最小示例。绘制在具有默认限制的轴上,隐藏线移除工作正常(左)当轴设置为大范围(与对象相比)时,线移除失败(中)。当我让轴消失时,事情又好了(右)。 问题中描述的三个不同的渲染图像

对于这个例子,我可以隐藏轴并且输出看起来正确。但对于我真正想做的事情,这不是一个选择。有什么建议或有人可以指出我正确渲染的场景中最小和最大对象之间的适当限制吗?生成上述球体的代码如下。提前致谢!

由 MATLAB 2018A 生成的图像

clearvars
F1 = figure(1);
clf
set(F1,'color',[1 1 1],'Renderer','opengl'); % have to enable this to clip surfaces behind the camera


for step = [2 1 3] % out of order because the axis in case 2 is trying to hide the first plot

subplot(1,3,step)
view(gca,3);
camproj(gca,'Perspective'); % have to enable this to clip surfaces behind the camera

[Xs,Ys,Zs] = sphere(20);
r = 30e-6;
surf(gca,Xs*r,Ys*r,Zs*r);
axis(gca,'equal');

 % three different behaviors, pick a number 1, 2, or 3
switch step
    case 1 % this plots the sphere correctly
    %axis([-2 2 -2 2 -2 2]);
    %axis off

    case 2 % this messes up the hidden line removal
    axis([-2 2 -2 2 -2 2]);
    %axis off   

    case 3 % removing the axis walls fixes things again
    axis([-2 2 -2 2 -2 2]);
    axis off
end

% put viewpoint on unit sphere
camera_pos = get(gca,'CameraPosition');
mag_camera_pos = sqrt(sum(camera_pos.^2));
camera_pos = camera_pos / mag_camera_pos; 
set(gca,'CameraPosition',camera_pos);

final_angle = 2.5*atand(r/1);
set(gca,'CameraViewAngle',final_angle);
end

drawnow

标签: matlabmatlab-figure

解决方案


推荐阅读