将法线向量旋转到轴平面上 [英] Rotate normal vector onto axis plane

查看:124
本文介绍了将法线向量旋转到轴平面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3D空间中有一组数据点,这些数据点显然全部落在特定平面上.我使用PCA计算平面参数. PCA的第三个分量为我提供了平面的法向矢量(最弱的分量).

I have a set of data points in 3D space which apparently all fall onto a specific plane. I use PCA to compute the plane parameters. The 3rd component of PCA gives me the normal vector of the plane (weakest component).

我接下来要做的是将所有点转换到所述平面上,并以2D方式查看它.

What I want to do next is to transform all the points onto said plane and look at it in 2D.

我的想法是执行以下操作:

My idea was to do the following:

  • 在平面上找到中心点(平均点)
  • 从所有数据点中减去它,将它们围绕原点排列
  • 旋转法线使其变为(0,0,-1)
  • 将此轮换应用于所有数据点
  • 使用正交投影(基本上跳过z轴)

现在,我被困在寻找正确的旋转操作上.我尝试使用acos或atan并设置了两个旋转矩阵.似乎两种方法(使用acos,使用atan)给我错误的结果.也许您可以在这里帮助我!

Now I'm stuck at finding the right rotation operation. I tried working with acos or atan and setting up two rotation matrices. Seems both methods (using acos, using atan) give me the wrong result. Perhaps you can help me out here!

Matlab代码如下:

Matlab code follows:

b = atan(n(1) / n(2));
rotb = [cos(b) -sin(b) 0; sin(b) cos(b) 0; 0 0 1];
n2 = n * rotb;
a = atan(n(1) / n(3));
rota = [cos(a) 0 sin(a); 0 1 0; -sin(a) 0 cos(a)];
n3 = n2 * rotaows:

我希望n2的y分量为零.但是对于矢量(-0.6367,0.7697,0.0467)已经失败了.

I expect n2 to have y component of zero. However that fails already for the vector (-0.6367, 0.7697, 0.0467).

推荐答案

如果有飞机,则有法线向量和原点.我根本不会做任何轮换".您只需几个向量操作即可获得答案.

If you have a plane, you have a normal vector and an origin. I wouldn't do any "rotations" at all. You're just a few vector operations away from your answer.

  • 我们将飞机的法线向量称为新的z轴.
  • 您可以通过将旧的x轴与新的z轴(平面的法线)相交来生成新的y轴.
  • 通过将新的z与新的y交叉来生成新的x轴.
  • 将所有新的轴矢量设为单位矢量(长度1).
  • 对于您拥有的每个点,创建一个从新原点到点的向量(点的向量减法-plane_origin).只需点上新的x和y单位向量,就可以绘制一对(x,y)!

如果您已经具有叉乘积和点乘积功能,那么这只是几行代码.我知道它是可行的,因为我编写的大多数3D电子游戏都是以这种方式工作的.

If you have cross and dot product functions already, this is just a few lines of code. I know it works because most of the 3D videogames I wrote worked this way.

技巧:

  • 请注意向量指向的方向.如果它们指出的方向错误,则取反结果向量或更改叉积的顺序.
  • 如果您的飞机的法线与原始x轴完全相同,则会遇到麻烦.

这篇关于将法线向量旋转到轴平面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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