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

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

问题描述

我有一个点一个点(X,Y,Z),它是由AX +定义的一个平面+ 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).

我的主要目标是让鼠标在表面上,并且知道在特定表面的二维坐标。我已经成功地相交线到面相当平凡。

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,并且从减去该三维坐标的的为原点(0画面的,0)。所得载体的 B - A 的将描述正面图像中的 X 的方向。做同样的的的方向。然后正常化这两个载体。这意味着它们通过它们的长度划分,开方(X 2 + Y 2 + Z 2),但D3DX有一个函数的 D3DXVec3Normalize 这一点。让我们把生成的三维矢量的 X 的。为了计算的 X 的任何三维点坐标的 P 的,简单地从减去原点的 A P 的,即计算矢量的 p - 一个的。然后计算结果和单位向量的内积的 X 的。这会给你两个数字:所需要的坐标。这是因为在点积可被用于计算正交投影

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点上的三维平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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