计算与 3D 中的第三个向量垂直的两个向量 [英] Computing two vectors that are perpendicular to third vector in 3D

查看:43
本文介绍了计算与 3D 中的第三个向量垂直的两个向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算与第三个向量 (X) 垂直且彼此垂直的两个向量的最佳(最快)方法是什么?

What is the best (fastest) way to compute two vectors that are perpendicular to the third vector(X) and also perpendicular to each other?

这就是我现在计算这个向量的方式:

This is how am I computing this vectors right now:

// 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);

我知道对此有无数种解决方案,我不在乎哪一种是我的解决方案.

I know there is infinite number of solutions to this, and I don't care which one will be my solution.

这个问题的背后是什么:我需要构造变换矩阵,在那里我知道 X 轴(矩阵中的第一列)应该指向哪个方向.我需要计算 Y 和 Z 轴(第二和第三列).众所周知,所有的轴都必须相互垂直.

What is behind this question: I need to construct transformation matrix, where I know which direction should X axis (first column in matrix) be pointing. I need to calculate Y and Z axis (second and third column). As we know, all axes must be perpendicular to each other.

推荐答案

我所做的,前提是 X<>0Y<>0

What I have done, provided that X<>0 or Y<>0 is

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

然后对向量进行归一化.

and then normalize the vectors.

[ 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

这称为向量的零空间.

如果 X=0Y=0 那么 A=[1,0,0], B=[0,1,0].

If X=0 and Y=0 then A=[1,0,0], B=[0,1,0].

这篇关于计算与 3D 中的第三个向量垂直的两个向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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