我如何知道两个向量是否接近平行
由于浮点精度,我在查找平行向量时遇到一些麻烦。如何确定向量是否平行并具有一定的公差?
我还需要检查正交性和公差。
I am having some trouble finding parallel vectors because of floating point precision. How can I determine if the vectors are parallel with some tolerance?
I also need a check for orthogonality with tolerance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于向量
v1
和v2
,检查它们是否正交,其中epsilon
足够小。类似地,您可以用于并行性测试和
反并行性。
For vectors
v1
andv2
check if they are orthogonal bywhere
epsilon
is small enough. Analoguously you can usefor parallelity test and
for anti-parallelity.
如果您有 3D 矢量,答案很简单。计算叉积,如果它接近零,则向量几乎平行:
http://mathworld.wolfram.com/ParallelVectors.html
对于 2d 向量,您可以将它们转换为只需添加一个带零的坐标即可得到 3D 向量
(1;2)=> (1;2;0), (4;5.6) => (4; 5.6; 0) 等等
如果点积为零,两个向量正交或垂直:
http://mathworld.wolfram.com/CrossProduct.html-编辑
If you have 3D vectors the answer is simple. Compute the cross product and if it is nearly zero, your vectors are nearly parallel:
http://mathworld.wolfram.com/ParallelVectors.html
For 2d vectors you can convert them into 3D vectors just by adding a coordinate with zero
(1;2) => (1;2;0), (4; 5.6) => (4; 5.6; 0) and so on
Two vectors are orthogonal or perpendicular, if there dot product ist zero:
http://mathworld.wolfram.com/CrossProduct.html-edit
http://mathworld.wolfram.com/Perpendicular.html
如果您使用 3D 矢量,则可以使用工具带 vg 来简洁地完成此操作。它是 numpy 之上的一个轻层,支持单个值和堆叠向量。
我在上次创业时创建了这个库,它的动机是这样的:简单的想法在 NumPy 中是冗长或不透明的。
If you're working with 3D vectors, you can do this concisely using the toolbelt vg. It's a light layer on top of numpy and it supports single values and stacked vectors.
I created the library at my last startup, where it was motivated by uses like this: simple ideas which are verbose or opaque in NumPy.