在自然界中,猎人使用恒定方位递减范围算法来捕捉猎物。我喜欢蝙蝠如何做这个链接文本的解释
我们需要定义更多的术语。
Point A - the position associated with vector R.
Point B - the position associated with vector T.
Vector AB - the vector from point A to point B
Angle beta - the angle between vector R and vector AB.
Angle theta - the angle between vector T and vector AB
该公式通常给出为
theta = asin( |R| * sin(beta) / |T| )
在哪里
beta = acos( AB.x R.x + AB.y R.y )
您不想直接使用它,因为 asin 和 acos 只返回 -PI/2 到 PI/2 之间的角度。
beta = atan2( R.y, R.x ) - atan2( AB.y, AB.x )
x = |R| * sin(beta) / |T|
y = 1 + sqrt( 1 - x*x )
theta = 2*atan2( y, x )
当然如果 x > 1 R 太快并且不存在交集
例如