matlab - 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
解决方案
推荐阅读
- python - 我的拥抱脸模型没有在异步事件循环中生成摘要是否有原因?
- javascript - 如何编写一个脚本来跟踪我在使用 Firefox 时在每个网站上花费的时间?
- html - Box-Shadow color by image
- python - 在 QToolButton 上显示两种颜色的字体
- php - Laravel 权限 Ubuntu VPS - 挖掘。Ocean -Runs but Can't create directory 错误,或者如果没有更改权限,这是一个独白无法打开 fs 500 er
- javascript - 我是 React.js 的新手并且有这个错误:“警告:React.createElement:类型无效”
- mysql - SQL:操作数据类型 - 浮点数到字符串
- hash - 什么是计算 Avro 模式哈希的好方法?
- sql - 如何在代码中创建一个“硬编码”的小 SQL 连接表?
- swift - Xcode 单元测试 - 单元测试运行时无法一致显示打印命令