English 中文(简体)
3D 中垂直与第三个矢量垂直的两个矢量的计算机化两个矢量
原标题:Computing two vectors that are perpendicular to third vector in 3D

计算与第三种矢量(X)相垂直和相互垂直的两个矢量的最佳(最快)

这就是我现在如何计算这个矢量的方法:

// HELPER - unit vector that is NOT parallel to X
x_axis = normalize(X);
y_axis = crossProduct(x_axis, HELPER);
z_axis = crossProduct(x_axis, y_axis);

我知道这个问题有无数的解决办法,我不在乎哪一种办法将是我的解决办法。

这个问题背后的原因是什么:我需要构建转换矩阵,我知道应该用哪个方向来指 X 轴( 矩阵中的第一列) 。 我需要计算 Y 轴和 Z 轴( 第二列和第三列) 。 我们知道, 所有轴必须相互垂直。

最佳回答

我所做的一切, 只要 X< & gt; 0 Y< & gt; 0

  1. A = [-Y, X, 0]
  2. B = [-X*Z, -Y*Z, X*X+Y*Y]

然后使向量正常化。

[ X,Y,Z]·[-Y,X,0] = -X*Y+Y*X = 0
[ X,Y,Z]·[-X*Z,-Y*Z,X*X+Y*Y] = -X*X*Z-Y*Y*Z+Z*(X*X+Y*Y) = 0
[-Y,X,0]·[-X*Z,-Y*Z,X*X+Y*Y] = Y*X*Z+X*Y*Z = 0

这是您向量的 < em> nullspace

如果 X=0 Y=0 然后 A=[1,0,0] , B=[0,1,0]

问题回答

This is the way to do it.
It s also probably the only way to do it. Any other way would be mathematically equivalent.
It may be possible to save a few cycles by opening the crossProduct computation and making sure you re not doing the same multiplications more than once but that s really far into micro-optimization land.

当然,有一点你应该小心。那就是HELPER矢量。不仅它不能与X平行,而且它也是一个好主意,即它不会与X完全平行。如果X和HELPER甚至有些平行,那么你的浮点计算就会是不稳定和不准确的。你可以测试和看看如果X和HELPER的点产物类似0.99999,会发生什么情况。

有办法找到一个好的帮助者(其实,它已经准备好成为你的 y_ 轴) 。

让 s X = (轴、 轴、 ay、 az) 。 选择两个较大大小的元素, 交换它们, 并取消其中的一个元素。 设定为 0 3 个元素( 最小大小) 。 此矢量与 X 垂直 。

示例:

如果 (ax & lt; = ay) 和 (ax & lt; = az), 然后 HELPER = (0, - az, ay) (或 (0, az, - ay))

*XHELPER = 0 *0 - ay *az + az *ay = 0

如果 (ay< = ax) 和 (ay< = az), 然后 HELPER = (az, 0, -ay)

对于好的 HELPER 矢量: 找到 X 与 < em> 最小绝对值 < / em > 的坐标, 并使用该坐标轴 :

absX = abs(X.x); absY = abs(X.y); absZ = abs(X.z);
if(absX < absY) {
  if(absZ < absX)
    HELPER = vector(0,0,1);
  else // absX <= absZ
    HELPER = vector(1,0,0);
} else { // absY <= absX
  if(absZ < absY)
    HELPER = vector(0,0,1);
  else // absY <= absZ
    HELPER = vector(0,1,0);
}

注:这实际上与@Mbo s 回答非常相似:使用最小坐标轴的交叉产品等于将最小坐标设定为零,将大坐标对齐,将大坐标对齐,并否定坐标轴对齐。

我认为单位矢量中所有元素中最小最大放大度值总是大于0.577, 这样你就可以逃脱:

- & gt; 找到3D 矢量为 2D 矢量的垂直矢量, 发现任何磁度大于0. 5 的元素, 从而减少发现三D 矢量为 2D 矢量的问题, 然后忽略一个不同的元素( 在位置上使用 0), 然后对剩余元素中的 2D 矢量公式应用垂直值 (对于 2D x- 轴= (ax, ay) - & gt; y- 轴= (- ay, ax) )

let x-axis be represented by (ax,ay,az)

if (abs(ay) > 0.5) {
  y-axis = normalize((-ay,ax,0))
} else if (abs(az) > 0.5) {
  y-axis = normalize((0,-az,ay))
} else if (abs(ax) > 0.5) {
  y-axis = normalize((az,0,-ax))
} else {
  error("Impossible unit vector")
}




相关问题
Maths in LaTex table of contents

I am trying to add a table of contents for my LaTex document. The issue I am having is that this line: subsubsection{The expectation of (X^2)} Causes an error in the file that contains the ...

Math Overflow -- Handling Large Numbers

I am having a problem handling large numbers. I need to calculate the log of a very large number. The number is the product of a series of numbers. For example: log(2x3x66x435x444) though my actual ...

Radial plotting algorithm

I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...

Subsequent weighted algorithm for comparison

I have two rows of numbers ... 1) 2 2 1 0 0 1 2) 1.5 1 0 .5 1 2 Each column is compared to each other. Lower values are better. For example Column 1, row 2 s value (1.5) is more ...

热门标签