给定相机和视平面的 2D 点的 3D 坐标

发布于 2024-08-27 04:01:14 字数 402 浏览 8 评论 0原文

我希望从相机产生穿过观察平面的光线。为了做到这一点,我需要我的相机位置(“眼睛”)、向上、向右和朝向向量(其中朝向是相机在相机所观察的物体方向上的向量)和P,观察平面上的点。一旦我有了这些,生成的射线是:

ray = camera_eye + t*(P-camera_eye);

其中 t 是沿射线的距离(现在假设 t = 1)。

我的问题是,鉴于 P 点位于观察平面上的位置 (i,j),如何获取 P 点的 3D 坐标?假设给定观察平面的左上角和右下角。

注意:观察平面实际上并不是一个平面,因为它不会向所有方向无限延伸。相反,人们可能会将该平面视为宽x高图像。在x方向上,范围是0-->宽度,在y方向上,范围是0-->高度。我希望找到第 (i,j) 个元素的 3D 坐标 0

I wish to generate rays from the camera through the viewing plane. In order to do this, I need my camera position ("eye"), the up, right, and towards vectors (where towards is the vector from the camera in the direction of the object that the camera is looking at) and P, the point on the viewing plane. Once I have these, the ray that's generated is:

ray = camera_eye + t*(P-camera_eye);

where t is the distance along the ray (assume t = 1 for now).

My question is, how do I obtain the 3D coordinates of point P given that it is located at position (i,j) on the viewing plane? Assume that the upper left and lower right corners of the viewing plane are given.

NOTE: The viewing plane is not actually a plane in the sense that it doesn't extend infinitely in all directions. Rather, one may think of this plane as a widthxheight image. In the x direction, the range is 0-->width and in the y direction the range is 0-->height. I wish to find the 3D coordinate of the (i,j)th element, 0

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

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

发布评论

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

评论(3

空心↖ 2024-09-03 04:01:14

直线和平面内切的一般解见 http:// local.wasp.uwa.edu.au/~pbourke/geometry/planeline/

您的特定图形库(OpenGL/DirectcX 等)可能有一个标准方法来执行此

编辑:您正在尝试找到 3d 交集场景中带有 3D 对象的屏幕点(例如鼠标光标)?

General solution of the itnersection of a line and a plane see http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/

Your particular graphics lib (OpenGL/DirectcX etc) may have an standard way to do this

edit: You are trying to find the 3d intersection of a screen point (eg a mouse cursor) with a 3d object in you scene?

傲性难收 2024-09-03 04:01:14

要计算P,您需要相机到近剪裁平面(屏幕)的距离,近剪裁平面上窗口的大小(或视角,您可以从视角算出窗口大小)以及渲染窗口的大小。

  1. 将屏幕位置缩放到 -1 < 范围内x < +1和-1< y < +1,其中 +1 是顶部/右侧,-1 是底部/左侧
  2. 按视图窗口大小缩放归一化的 x,y 按
  3. 相机的右侧和向上向量缩放并对结果求和
  4. 添加按缩放比例缩放的查看向量裁剪平面距离

实际上,您得到:

p = at * near_clip_dist + x * right + y * up

其中 x 和 y 是:

x = (screen_x - screen_centre_x) / (width / 2) * view_width
y = (screen_y - screen_centre_y) / (height / 2) * view_height

To work out P, you need the distance from the camera to the near clipping plane (the screen), the size of the window on the near clipping plane (or the view angle, you can work out the window size from the view angle) and the size of the rendered window.

  1. Scale the screen position to the range -1 < x < +1 and -1 < y < +1 where +1 is the top/right and -1 is the bottom/left
  2. Scale normalised x,y by the view window size
  3. Scale by the right and up vectors of the camera and sum the results
  4. Add the look at vector scaled by the clipping plane distance

In effect, you get:

p = at * near_clip_dist + x * right + y * up

where x and y are:

x = (screen_x - screen_centre_x) / (width / 2) * view_width
y = (screen_y - screen_centre_y) / (height / 2) * view_height
原谅我要高飞 2024-09-03 04:01:14

当我直接将建议的公式插入我的程序时,我没有获得正确的结果(也许需要进行一些调试)。我最初的问题似乎是对插值角点的 (x,y,z) 坐标的误解。我分别处理 x、y、z 坐标,而我不应该这样做(这可能特定于应用程序,因为相机可以面向任何方向)。相反,解决方案结果是对观察平面的角点进行简单插值:

  • 在 i 方向上对底部角点进行插值以获得 P1 在 i 方向上对
  • 顶部角点进行插值以获得 P2 在 i 方向上
  • 对 P1 和 P2 进行插值j方向获取最终点的世界坐标

When I directly plugged in suggested formulas into my program, I didn't obtain correct results (maybe some debugging needed to be done). My initial problem seemed to be in the misunderstanding of the (x,y,z) coordinates of the interpolating corner points. I was treating x,y,z-coordinates separately, where I should not (and this may be specific to the application, since the camera can be oriented in any direction). Instead, the solution turned out to be a simple interpolation of the corner points of the viewing plane:

  • interpolate the bottom corner points in the i direction to get P1
  • interpolate the top corner points in the i direction to get P2
  • interpolate P1 and P2 in the j direction to get the world coordinates of the final point
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文