从 3D 平面上的 3D 点检索 2D 坐标 [英] Retrieve 2D co-ordinate from a 3D point on a 3D plane

查看:27
本文介绍了从 3D 平面上的 3D 点检索 2D 坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个点 (x, y, z) 位于由 ax+by+cz+d=0 定义的平面上.我试图弄清楚 (x', y') 相对于平面是什么,它的起点是 (x0, y0, z0) 并且 x' 轴由 (1,0) 和y' 轴由 (0,1) 定义.

I have a point a point (x, y, z) that is on a plane defined by ax+by+cz+d=0. I'm trying to figure out what the (x', y') relative to the plane, where it has a starting point of (x0, y0, z0) and the x'-axis is defined by (1,0) and the y'-axis is defined by (0,1).

我的主要目标是让鼠标点击一个表面,并知道特定表面上的 2D 坐标.我已经成功地将光线非常简单地与平面相交.

My major goal is to have the mouse click on a surface, and know the 2D co-ordinates on a particular surface. I've managed to intersect the ray onto a plane quite trivially.

顺便说一下,我使用的是 DirectX 9 - 我对矩阵/向量数学的熟悉受到通过 D3DX 库提供给我的 API 的限制.

As a side-note, I'm using DirectX 9 - my familiarity with matrix/vector math is limited by the APIs provided to me through the D3DX libraries.

我的一个想法是使用轴向量之一之间的角度并找到距原点的距离,然后使用简单的三角函数计算出 x/y.但我不确定这是否真的是一个理想的解决方案 - 或者它是否真的可以解决手头的问题.

One thought I had was to use the angle of between one of the axis vectors and find the distance from origin, and figure out the x/y using simple trig. But I'm not sure if that's really an ideal solution or not - or if it can actually solve the issue at hand.

推荐答案

由于您在该平面上有一个 2D 图像,您显然希望匹配其坐标系.为此,请确定图片的单位向量.即,取任意 x>0 的图片位置 (x,0) 的 3d 坐标 B,并从中减去原点 (0,0) 的图片.结果向量 B - A 将描述图像的正 x 方向.对 y 方向执行相同操作.然后对这两个向量进行归一化.这意味着将它们除以它们的长度 sqrt(x²+y²+z²),但 D3Dx 有一个函数 D3DXVec3Normalize 为此.我们将生成的 3d 向量称为 XY.要计算任何 3D 点 pxy 坐标,只需从 中减去原点 Ap,即计算向量p − A.然后计算结果与单位向量XY 之间的点积.这将为您提供两个数字:所需的坐标.这是因为点积可用于计算正交投影.

Since you have a 2D image on that plane, you apparently want to match its coordinate system. To do so, determine the unit vectors of the picture. That is, take the 3d coordinates B for the picture position (x,0) for any x>0, and subtract from that the 3d coordinates A for the origin (0,0) of the picture. The resulting vector B − A will describe the positive x direction of your image. Do the same for the y direction. Then normalize both these vectors. This means dividing them by their length, sqrt(x²+y²+z²), but D3Dx has a function D3DXVec3Normalize for this. Let's call the resulting 3d vectors X and Y. To compute the x and y coordinate of any 3D point p, simply subtract the origin A from p, i.e. compute the vector p − A. Then compute the dot product between the result and the unit vectors X and Y. This will give you two numbers: the desired coordinates. This is because the dot product can be used to compute an orthogonal projection.

将其翻译成 D3Dx,它应该看起来有点像下面这样.由于我从未使用过它,因此可能会出错.

Translating this into D3Dx, it should look somewhat like the following. As I have never used it, this might have mistakes.

D3DXVECTOR3 *p;                  // input point
D3DXVECTOR3 a, b, c, ab, ac, ap; // helper vectors
FLOAT x, y;                      // output coordinates
imagePosTo3D(&a, 0, 0);          // a = origin of image
imagePosTo3D(&b, 1, 0);          // b = anywhere on positive x axis, perhaps a corner
imagePosTo3D(&c, 0, 1);          // c = anywhere on positive y axis, perhaps a corner
D3DXVec3Subtract(&ab, &b, &a);   // ab = b - a
D3DXVec3Subtract(&ac, &c, &a);   // ac = c - a
D3DXVec3Normalize(&ab, &ab);     // ab = ab / |ab|
D3DXVec3Normalize(&ac, &ac);     // ac = ac / |ac|
// the above has to be done once for the image, the code below for every p
D3DXVec3Subtract(&ap, p, &a);    // ap = p - a
x = D3DXVec3Dot(&ab, &ap);       // x = ab∙ap
y = D3DXVec3Dot(&ac, &ap);       // y = ac∙ap

这篇关于从 3D 平面上的 3D 点检索 2D 坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆