变换点坐标从3D空间中SlimDX一个普通的二维平面 [英] Transform point coordinates from 3D space to a generic 2D plane in SlimDX

查看:224
本文介绍了变换点坐标从3D空间中SlimDX一个普通的二维平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要投射SlimDX.Vector3(X,Y和Z分量)在一个普通的二维平面(与SlimDX.Plane定义,与3 Vector3类型)。请注意,该平面是通用的,并且它不是在屏幕平面(否则,Vector3.Project可以使用)。 我需要从三维空间到二维平面确定Tranformation矩阵(或四元),但我不知道怎么办。 飞机的起源可以任意,例如第一点来定义的平面。

I need to project a SlimDX.Vector3 (X, Y and Z components) in a generic 2D plane (defined with SlimDX.Plane, with 3 Vector3). Please note that the plane is generic, and it is not the screen plane (otherwise, Vector3.Project could be used). I need to determine the Tranformation Matrix (or the Quaternion) from the 3D space to the 2D plane, but I don't know how. The origin of the plane can be whatever, e.g. the first point used to define the plane.

任何人都可以帮忙吗?

推荐答案

您的问题仍然很不清楚。不过,我想在黑暗中了一枪。

Your question is still very unclear. However, I'm trying a shot in the dark.

让我们先通过计算模型转换为平面(其将飞机趴在X / Y平面到它的实际位置)。你正在寻找的变换是这个矩阵的逆。

Let's start by calculating a model transform for the plane (which transforms the plane lying in the x/y plane to its actual position). The transform you are looking for is the inverse of this matrix.

我们可以通过寻找校长的图像构建矩阵。起源很简单。正如您所指定的起源应该被映射到第一点( V1 )。 z轴也很容易。这是飞机的正常。因此,基质是:

We can construct the matrix by finding the images of the principals. The origin is quite simple. As you specified, the origin should be mapped to the first point (v1). The z-axis is also easy. That's the plane's normal. Hence, the matrix is:

    /  .           .           .          . \
M = |  .           .           .          . |
    | p.Normal.X  p.Normal.Y  p.Normal.Z  0 |
    \ v1.X        v1.Y        v1.Z        1 /

现在来,你的描述缺乏信息的一部分。我们需要在飞机上的本地x轴。我认为该轴是由第二矢量定义:

Now comes the part where your description lacks information. We need a local x-axis on the plane. I assume that this axis is defined by the second vector:

Vector3 x = Vector3.Normalize(v2 - v1);

然后,将所得的本地y轴是:

Then, the resulting local y-axis is:

Vector3 y = Vector3.Normalize(Vector3.Cross(p.Normal, x));

    / x.X         x.Y         x.Z         0 \
M = | y.X         y.Y         y.Z         0 |
    | p.Normal.X  p.Normal.Y  p.Normal.Z  0 |
    \ v1.X        v1.Y        v1.Z        1 /

如前所述,你需要这个矩阵逆。因此:

As mentioned, you need this matrix' inverse. Hence:

       /  x.X     y.X     p.Normal.X  0 \
M^-1 = |  x.Y     y.Y     p.Normal.Y  0 |
       |  x.Z     y.Z     p.Normal.Z  0 |
       \ -v1.X   -v1.Y      -v1.Z     1 /

更紧凑,因为你并不需要的第三和第四维(虽然这可能不是最方便的再presentation的SDX):

More compactly, since you don't need the third and fourth dimensions (although this might not be the most convenient representation for SDX):

       /  x.X     y.X  \
   T = |  x.Y     y.Y  |
       |  x.Z     y.Z  |
       \ -v1.X   -v1.Y /

这篇关于变换点坐标从3D空间中SlimDX一个普通的二维平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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