给定一个轴的向量,如何找到其他两个轴的向量?
这是一道数学题,我不知道该怎么做。该矢量未与轴对齐,因此仅围绕 x、y 或 z 旋转 90 度不一定会给出其他轴。
This is a maths problem I am not exactly sure how to do. The vector is not aligned to an axis, so just rotating 90 degrees around x, y or z won't necessarily give me the other axes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可以想到您可能会问的几种不同场景。
给定:预先存在的坐标系
在 2D 系统中,您的轴/基准始终为
[1,0]
和[0,1]
-- x 和 y 轴。在 3D 系统中,轴/基准始终为
[1,0,0]
、[0,1,0]
和[0 ,0,1]
-- x、y 和 z。给定:任意基 2D 坐标系中的一个轴
如果任意基 2D 坐标系中有一个轴,则另一个轴是正交向量。
正交逆时针旋转向量:
正交顺时针旋转向量:
总结:
给定:任意基 3D 坐标系中的两个轴 要做到这一点,需要
找到叉积。
遵循以下三个准则:(
给定:任意基 3D 坐标系中的一个轴
没有足够的信息来找到此问题的唯一解决方案。这是因为,如果您查看第二种情况(任意基二维坐标系中的一个轴),您首先需要找到一个正交向量。然而,3D 空间中存在无限数量的与单个轴正交的向量!
但是,您可以找到一种可能的解决方案。
查找任意一个正交向量的一种方法是查找任意向量
[d,e,f]
,其中:例如,如果您的原始轴是
[2,3,4]< /code>,你会解决:
也就是说,满足此条件的
[d,e,f]
的任何值都是令人满意的正交向量(只要它不是[0,0,0]
)。例如,可以选择[3,-2,0]
:如您所见,一个适用的“公式”是
[d,e,f] = [b, -a,0]
...但是还有很多其他的也可以工作;事实上,有无限个!一旦找到两个轴
[a,b,c]
和[d,e,f]
,您可以将其还原回之前的情况(情况 3),使用[a,b,c]
和[d,e,f]
作为您的 x 和 y 轴(或者您需要的任何轴,针对您的具体问题)。归一化
请注意,当您不断进行点积和叉积时,您的向量将开始变得越来越大。根据您的需要,这可能是不需要的。例如,您可能希望基向量(坐标轴)全部具有相同的大小/长度。
将任何向量(
[0,0,0]
除外)转换为单位向量(长度为1的向量,与原始向量方向相同) ):其中,
r'
表示r
的单位向量,即长度为 1 且与r
指向相同方向的向量。举个例子:现在,如果我想要一个与
r
方向相同、长度为 5 的向量,我只需将r' * 5
相乘即可,即[a' * 5, b' * 5, c' * 5]
。I can think of a couple of different scenarios you might be asking about.
Given: A pre-existing coordinate system
In a 2D system, your axes/basis are always
[1,0]
and[0,1]
-- x and y axes.In a 3D system, your axes/basis are always
[1,0,0]
,[0,1,0]
, and[0,0,1]
-- x, y, and z.Given: One axis in an arbitrary-basis 2D coordinate system
If you have one axis in an arbitrary-basis 2D coordinate system, the other axis is the orthogonal vector.
To rotate a vector orthogonally counter-clockwise:
To rotate a vector orthogonally clockwise:
To summarize:
Given: Two axes in an arbitrary-basis 3D coordinate system
To do this, find the cross product.
Following these three guidelines:
Given: One axis in an arbitrary-basis 3D coordinate system
There is not enough information to find the unique solution this problem. This is because, if you look at the second case (One axis in an arbitrary-basis 2D coordinate system), you first need to find an orthogonal vector. However, there are an infinite amount of possible orthogonal vectors to a single axis in 3D space!
You can, however, find one of the possible solutions.
One way to find an arbitrary one of these orthogonal vectors by finding any vector
[d,e,f]
where:For example, if your original axis is
[2,3,4]
, you'd solve:That is, any value of
[d,e,f]
that satisfies this is a satisfactory orthogonal vector (as long as it's not[0,0,0]
). One could pick, for example,[3,-2,0]
:As you can see, one "formula" that works to is
[d,e,f] = [b,-a,0]
...but there are many other ones that can work as well; there are, in fact, an infinite!Once you find your two axes
[a,b,c]
and[d,e,f]
, you can reduce this back to the previous case (case 3), using[a,b,c]
and[d,e,f]
as your x and y axes (or whatever axes you need them to be, for your specific problem).Normalization
Note that, as you continually do dot products and cross products, your vectors will begin to grow larger and larger. Depending on what you want, this might not be desired. For example, you might want your basis vectors (your coordinate axes) to all be the same size/length.
To turn any vector (except for
[0,0,0]
) into a unit vector (a vector with a length of 1, in the same direction as the original vector):Where
r'
represents the unit vector ofr
-- a vector with length of 1 that points in the same direction asr
does. An example:Now, if I wanted, for example, a vector in the same direction of
r
with a length of 5, I'd simply multiply outr' * 5
, which is[a' * 5, b' * 5, c' * 5]
.只有一个轴是不够的,因为在垂直平面上仍然有无数个轴。
如果您设法获得另一个轴,则可以使用叉积来找到第三个轴。
Having only one axis isn't enough, since there are still an infinite number of axes that can be in the perpendicular plane.
If you manage to get another axis though, you can use the cross product to find the third.
如果你有一个向量 (x,y,z),你可以得到一个与它垂直的向量 (y,-x,0) (点积为 xyyx+0*z = 0 )
然后取两者的叉积以获得剩余的垂直向量:
(x,y,z) × (y,-x,0) = (0y+zx, yz-0x, -x²-y²) = (zx, yz, -x²-y²)
If you have one vector (x,y,z) you can get one perpendicular vector to it as (y,-x,0) (dot-product is xy-yx+0*z = 0)
Then you take the cross-product of both to get the remaining perpendicular vector:
(x,y,z) × (y,-x,0) = (0y+zx, yz-0x, -x²-y²) = (zx, yz, -x²-y²)
您谈论的是典型的 3 坐标系统,例如 3D 引擎中使用的系统吗?
仅凭一个向量,您无法找到其他两个向量,您将获得的唯一信息是它们所在的平面。但如果它们与您拥有的唯一一个向量垂直,它们也可以呈任何角度。
Are you talking about a typical 3coordinate system like the one used in a 3D engine?
With just a vector you can't find the other two, the only information you will have it the plane on which they lay.. but they can be at any angle also if they're perpendicular with the only one vector you have.