如何检查向量是否在两个向量内 [英] How to check if a vector is within two vectors
问题描述
这是一张图片:
我有两个向量:os,oe
I have two vectors : os, oe
它们之间的范围始终是从os(开始)到oe(结束).
the range between them is always from os (start) to oe (end).
因此,在此图像中,范围为270°.
So in this image the range between is a angle of 270°.
然后我要检查两个向量:oa,ob
Then I have two vector to check: oa, ob
您可以看到向量oa应该在osoe形成的范围内,向量ob应该在osoe之外.
As you can see the vector oa should be within the range formed by osoe and the vector ob should be outside.
我想知道是否有一种方法可以仅使用矢量数学(例如叉积点积)进行检查.
I am wondering if there is a way to do the check using only vector math (such as cross product dot product).
我试图将叉积与顺时针/逆时针检查一起使用,但是当两者之间的夹角大于180°时,情况就变得复杂了.
I tried to use cross product with clockwise/counter clockwise check but it seems like when the angle in between is larger then 180°, things get complex.
任何建议将不胜感激,谢谢:)
Any advice will be appreciated, thanks :)
推荐答案
我将指向 p 的向量表示为 op
.
I denote vector to point p as op
.
计算叉积
c_se = cross(os, oe)
如果 c_se> = 0
(角度位于 0..180范围
),那么您必须检查是否
If c_se>=0
(angle in 0..180 range
), then you have to check whether
cross(os, op) >= 0 AND cross(op, oe) >= 0
如果 c_se<0
(角度在 180..360范围
中),那么您必须检查是否
If c_se < 0
(angle in 180..360 range
), then you have to check whether
NOT (cross(oe, op) >= 0 AND cross(op, os) >= 0)
这篇关于如何检查向量是否在两个向量内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!