给定一个表面正常的,找到的3D平面旋转 [英] Given a surface normal, find rotation for 3D Plane

查看:173
本文介绍了给定一个表面正常的,找到的3D平面旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有2个向量所描述的3D平面:

So I have a 3D Plane described by 2 Vectors:

病人:一个点位于该飞机上
  N:表面正常的平面

P : a point which lies on the Plane
N : the surface normal for the Plane

和我有一个非常大的,平面呈正方形多边形,这是我要呈现重新present这架飞机。我可以很容易地转换多边形给定的点,但我需要找到适当的轮换,以适用于做表面法线实际上是表面正常的。

And i have a very large, flat square Polygon, which I want to render to represent this Plane. I can easily translate the polygon to the given point, but then I need to find the proper rotation to apply to make the surface normal actually be the surface normal.

我想其他人提及的方法,其中这是:

I tried a method mentioned else where which was:

1)采取任何无并行向量(V)正常(N),并采取交叉乘积(W1)
  2)取的(W1的叉积)和(N)现在(W2),这是一个矢量(V'),其位于所述平面

1) Take any none parallel vector (V) to the normal (N), and take the cross product (W1)
2) Take the cross product of (W1) and (N) now (W2) and that is a Vector (V') which lies on the Plane

我再根据(V')布置在飞机上,让自己的多边形将与(V对准')产生旋转矩阵。这工作,但很显然,这种方法不能正常工作的全过程。多边形是不完全垂直于表面法线

I then generate a rotation matrix based on (V') laying on the Plane, so that my polygon would be aligned with (V'). that worked, but it's clear that this method is not working correctly as a whole. The Polygon is not perfectly perpendicular to the surface normal.

如何生成正确的旋转任何想法?

Any ideas on how to generate the proper rotation?

推荐答案

有关转一些有用的东西:

Some useful things about rotations:

  • 在安排行定义一个转变成一个新的基础(旋转成的基础上)任意三个正交向量。
  • 在任何旋转的转置是它的倒数。
  • 因此,排列为列任意三个正交向量定义了一些基础的旋转到你的世界的参照系。

那么,问题是要找到任何一组三个正交向量,并安排他们

So, the problem is to find any set of three orthonormal vectors and arrange them as

| x1 x2 x3  0 |
| y1 y2 y3  0 |
| z1 z2 z3  0 |
|  0  0  0  1 |

这正是你所描述的方法试图做的,如果它不工作,则可能是您的实现有问题。

this is exactly what the method you described tries to do, if it doesn't work then there is a problem with your implementation.

我们可以明显地使用你的作为(X1,Y1,Z1)正常的,但问题是该系统具有无穷多解剩下的两个向量(虽然知道其中一人给你其他的,如叉积)。下面code应该给一个稳定的向量垂直于(X1,Y1,Z1):

We can obviously use your normal as (x1,y1,z1), but the problem is the system has infinitely many solutions for the remaining two vectors (although knowing one of them gives you the other, as the cross product). The following code ought to give a stable vector perpendicular to (x1,y1,z1):

float normal[3] = { ... };

int imin = 0;
for(int i=0; i<3; ++i)
    if(std::abs(normal[i]) < std::abs(normal[imin]))
        imin = i;

float v2[3] = {0,0,0};
float dt    = normal[imin];

v2[imin] = 1;
for(int i=0;i<3;i++)
    v2[i] -= dt*normal[i];

此基本上使用革兰氏施密特orthogonalisation与已最正交的法线向量的维数。 V3然后可以通过服用的叉积获得正常 V2

This basically uses Gram-Schmidt orthogonalisation with the dimension that is already most orthogonal to the normal vector. v3 can then be obtained by taking the cross product of normal and v2.

您可能需要采取一些护理设置的旋转,它是关于原产地,所以你需要在旋转后应用翻译和它的列向量,而不是行向量。如果您使用的OpenGL观看了OpenGL将阵列中列优先顺序(而不是C的行优先顺序),所以你可能需要调换。

You may need to take some care setting up the rotation, it's about the origin so you need to apply the translation after the rotation and it's for column vectors rather than row vectors. If you're using OpenGL watch that OpenGL takes arrays in column major order (rather than C's row major order) so you may need to transpose.

我怕我没有测试上面,我只是从一些code我写了一段时间前,它适应于您的问题抓获吧!但愿我没有忘记任何细节。

I'm afraid I haven't tested the above, I've merely nabbed it from some code I wrote a while ago and adapted it to your problem! Hopefully I haven't forgotten any details.

编辑:我没忘了什么东西:)

I did forget something :)

矩阵上述假设您的正常多边形沿x轴,和我有一个偷渡怀疑它不会是,所有你需要做的就是把正常的载体在旋转的正确的列基质,和v2 / V3中的其他两列。因此,如果正常到您的多边形是沿着z轴,然后正常进入在第3列和v2 / v3中去,在头两列。

The matrix above assumes your normal to the polygon is along the x-axis, and I have a sneaking suspicion it won't be, all you need to do is put the "normal" vector in the correct column of the rotation matrix, and v2/v3 in the other two columns. So if the normal to your polygon is along the z axis, then the normal goes in the 3rd column and v2/v3 go in the first two columns.

很抱歉,如果引起任何混乱。

Sorry if that causes any confusion.

这篇关于给定一个表面正常的,找到的3D平面旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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