[英]Point of intersection between two vectors when the direction of one vector is not known
Problem: I have two vectors. 问题:我有两个向量。 I know the starting point of one vector, its direction, its magnitude. 我知道一个向量的起点,方向,大小。 I know the starting point of the other vector and its magnitude. 我知道另一个向量的起点及其大小。 I need to find the direction of second vector as well as the position of intersection. 我需要找到第二个向量的方向以及交点的位置。
Vector A: Vector B:
Position = Known Position = Known
Direction= Known Direction= UNKNOWN
Magnitude= Known Magnitude= Known
To Find: Point of intersection.
Is it possible to find the point of intersection, with the given parameters? 是否可以找到具有给定参数的交点? If so then how? 如果是这样,那又如何?
Application: I want to find the position where a player would be found based on the velocity he is moving, and shoot a bullet at him at the moment he would be found, taking into account the time taken for the bullet to reach that virtual target position. 应用程序:我想根据玩家的移动速度找到能够找到该玩家的位置,并在发现该玩家的那一刻向他发射子弹,同时考虑到子弹到达该虚拟目标所花费的时间位置。
Following on from the comments I'm going to take a leap here and answer your ultimate question directly. 在评论之后,我将在这里跳过并直接回答您的最终问题。
Say the player is, at the initial time, at a point p
and travelling with velocity v
; 假设玩家最初处于点p
并以速度v
行驶; your gun is at position q
and shoots a bullet in any direction at speed s
: 您的枪位于q
位置,并以s
速度向任何方向发射子弹:
The length of OP is vΔt
and that of Q sΔt
. OP的长度为vΔt
,Q的长度为sΔt
。 The angle a
is given by the dot product: 角度a
由点积给出:
We can then use the cosine rule to solve for Δt
: 然后,我们可以使用余弦规则来求解Δt
:
Written in this form, we can easily see that it is a quadratic equation, and thus directly solve for Δt
using the Quadratic formula : 写在这个形式中,我们可以很容易地看到,这是一个二次方程,并且因此直接解决Δt
使用二次式 :
There are a few cases we need to consider here: 这里有一些情况我们需要考虑:
v < s
: need to take the positive root only as otherwise we would get negative time. v < s
:只需要取正数根,否则我们将得到负数时间。 v > s
and dot(PQ, s) < 0
: the bullet will never catch the player. v > s
和dot(PQ, s) < 0
:子弹永远不会抓住玩家。 v > s
and dot(PQ, s) > 0
: take the negative root this time, as the positive root is for a backwards travelling player (longer time; this is also the case presented in the diagram above). v > s
和dot(PQ, s) > 0
:这次取负根,因为正根是向后移动的玩家(较长的时间;上图中也是如此)。 Having the correct value for Δt
from above will then enable us to find the intersection point o
, and therefore the intended direction d
: 从上方获得正确的Δt
值将使我们能够找到交点o
,从而找到目标方向d
:
Note that d
is not normalized. 请注意, d
未标准化。 Also, this solution works for 3D too, unlike an approach with angles. 此外,与带有角度的方法不同,该解决方案也适用于3D 。
Let subscript 1 mark the player, and subscript 2 mark the AI: 让下标1标记玩家,下标2标记AI:
The positions as a function of time t are : 根据时间t的位置是:
You have 2 uknowns: 您有2个未知数:
The collision happens when Xs and Ys match. X和Y匹配时发生冲突。 ie: 即:
So, 所以,
and also 并且
substitue your values and equate these to expressions of alpha_2 to obtain t, then you can substitue t in either expression to obtain the angle alpha_2. 将您的值代入并等于alpha_2的表达式以获得t,然后可以在任一表达式中代入t以获得角度alpha_2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.