给定相机和视平面的 2D 点的 3D 坐标
我希望从相机产生穿过观察平面的光线。为了做到这一点,我需要我的相机位置(“眼睛”)、向上、向右和朝向向量(其中朝向是相机在相机所观察的物体方向上的向量)和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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
直线和平面内切的一般解见 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?
要计算P,您需要相机到近剪裁平面(屏幕)的距离,近剪裁平面上窗口的大小(或视角,您可以从视角算出窗口大小)以及渲染窗口的大小。
实际上,您得到:
其中 x 和 y 是:
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.
In effect, you get:
where x and y are:
当我直接将建议的公式插入我的程序时,我没有获得正确的结果(也许需要进行一些调试)。我最初的问题似乎是对插值角点的 (x,y,z) 坐标的误解。我分别处理 x、y、z 坐标,而我不应该这样做(这可能特定于应用程序,因为相机可以面向任何方向)。相反,解决方案结果是对观察平面的角点进行简单插值:
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: