如何通过居中固定距离相机确定 3d 盒子可见侧的宽度?

发布于 2024-10-10 08:56:38 字数 332 浏览 9 评论 0原文

我有一个 2.5d 视口,其中我试图用向内 45 度 2D 线来表达盒子深度的可视化,就好像它没有正面,而你从中心点凝视内部,如下所示:

-------------
| \_______/ |
| |       | |
| |_______| |
| /       \ |
-------------

我想绘制真实 3D 几何的隐喻,在给定相机距离的情况下,内部矩形与外部矩形的距离是正确的(假设距用户显示器的平均眼睛距离固定为 2 英尺),

我如何导出“公共内侧” width”来自:中心相机距离、盒子的宽度和高度以及我想要表示的深度?

谢谢!

I have a 2.5d viewport wherein I am trying to express a visualization of the depth of a box with 45 degree 2D lines inwards as if it had no front and you were staring inside from a central point, like this:

-------------
| \_______/ |
| |       | |
| |_______| |
| /       \ |
-------------

I want to draw the metaphor with real 3D geometry, in that the distance of the inner rect from the outer rect is correct, given a camera distance (say fixed at 2 feet for an average eye distance from the user's monitor)

How can I derive the "common inner side width" from: the centered camera distance, the width and height of the box, and the depth I'm trying to represent?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2024-10-17 08:56:38

您正在寻找的是透视投影。除了相机的位置和盒子的尺寸之外,您还需要在相机和盒子之间的某个位置放置一个“屏幕”,盒子将投影到该屏幕上。相机到屏幕的距离将缩放投影框的大小。

假设相机位于原点,距盒子 z 个单位,屏幕距相机 1 个单位,盒子的深度为 d,宽度为 >2w,高度2h

在 3D 环境空间中,框的左上角位于位置 (-w, h, z)。相机和该点之间的光线与投影屏幕相交于(-w/z, h/z, 1)

盒子底部的左上角位于位置 (-w, h, z+d) ,投影到 (-w/(z+d), h/ (z+d), 1)

同理,可以找到其他投影点的位置。因此,屏幕上外框的宽度为 2w/z,内框的宽度为 2w/(z+d),高度也类似。因此,内盒只是外盒的统一缩放版本,内盒尺寸 z/(z+d) 乘以外盒尺寸。

请注意,连接两个盒子的对角线不会成 45 度,除非盒子恰好是正方形。

What's you're looking for is a perspective projection. In addition to the position of the camera and dimensions of the box, you also need a "screen" somewhere between the camera and the box onto which the box will be projected. The distance from the camera to this screen will scale the size of the projected box.

Let's say the camera is at the origin and z units away from the box, the screen is one unit away from the camera, and the box was depth d, width 2w, and height 2h.

In 3D ambient space, the top-left corner of the box is at position (-w, h, z). The ray between the camera and this point intersects the projection screen at (-w/z, h/z, 1).

The top-left corner of the floor of the box is at position (-w, h, z+d) which is projected to (-w/(z+d), h/(z+d), 1).

Similarly, you can find the positions of the other projected points. Therefore the width of the outer box on the screen is 2w/z, the width of the inner box 2w/(z+d), and analogously for the heights. The inner box is thus just a uniformly scaled version of the outer box, with the inner box dimensions z/(z+d) times the outer box ones.

Note that the diagonals connecting the two boxes are not oriented at 45 degrees unless the box happens to be square.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文