Intersection of two vectors with tails?

112 Views Asked by At

I'm working on a 2 degree of freedom simulation of gas dynamics.

Suppose you have two vectors in the x-y plane. Each vector has two tails, or coordinates where they start. Because I'm looking for a point in the future where the vectors will intersect, I can treat the vectors as rays, as long as they maintain the same direction and tail. How can you find where, or if, they intersect?

The Vectors in the program are stores as having an x-Magnitude, y-Magnitude, and a coordinate position for their tails.

2

There are 2 best solutions below

0
On

Each vector can be represented as $V_k=a_k+s_kb_k$ where $a_k$ are the start points, $b_k$ the direction vectors and $s_k$ distances (scalar) along the vectors. Use $V_1=V_2$ to find values for $s_k$, where the vectors meet.

Note that $a_k$ and $b_k$ are known. Answer is given by solving for $s_k$.

0
On

Let's say particle $i$ is at $(\mathcal{X}_{i} ,\, \mathcal{Y}_{i})$ at time $t = 0$, with velocity $(\dot{\mathcal{X}}_i, \dot{\mathcal{Y}}_i)$, so that unless it collides with another particle, it's trajectory at time $t \ge 0$ is $$\begin{aligned} x_i(t) & = \mathcal{X}_i + t \dot{\mathcal{X}}_i \\ y_i(t) & = \mathcal{Y}_i + t \dot{\mathcal{Y}}_i \\ \end{aligned}$$
There are two possible questions here: whether particles $i$ and $j$ intersect, i.e. $$\left\lbrace \begin{aligned} x_i(t) & = x_j(t) \\ y_i(t) & = y_j(t) \\ \end{aligned} \right. \tag{1}\label{G1}$$ or whether the lines extending the particle trajectories intersect, $$\left\lbrace \begin{aligned} x_i(t_1) & = x_j(t_2) \\ y_i(t_1) & = y_j(t_2) \\ \end{aligned} \right. \tag{2}\label{G2}$$
Solving $\eqref{G1}$ we find that if at least one of particles $i$, $j$ is moving, $$\lvert \dot{\mathcal{X}}_i \rvert + \lvert \dot{\mathcal{Y}}_i \rvert + \lvert \dot{\mathcal{X}}_j \rvert + \lvert \dot{\mathcal{Y}}_j \rvert \gt 0 \tag{1a}\label{G1a}$$ and an intersection is possible, $$(\mathcal{X}_i - \mathcal{X}_j)(\dot{\mathcal{Y}}_j - \dot{\mathcal{Y}}_i) - (\mathcal{Y}_i - \mathcal{Y}_j)(\dot{\mathcal{X}}_j - \dot{\mathcal{X}}_i) = 0 \tag{1b}\label{G1b}$$ then the particles intersect at time $t$, $$t = \frac{\mathcal{X}_i - \mathcal{X}_j}{\dot{\mathcal{Y}}_j - \dot{\mathcal{Y}}_i} = \frac{\mathcal{Y}_i - \mathcal{Y}_j}{\dot{\mathcal{X}}_j - \dot{\mathcal{X}}_i} \tag{1c}\label{G1c}$$ noting that if the particles' trajectories diverge, above yields $t \lt 0$ (indicating a collision would occur if time passed backwards); and also that the first right side is undefined if $\dot{\mathcal{Y}}_i = \dot{\mathcal{Y}}_j$, and the second right side is undefined if $\dot{\mathcal{X}}_i = \dot{\mathcal{X}}_j$.

(Numerically, you'll need to use $\lvert \dots \rvert \le \epsilon_2$ for $\eqref{G1b}$, where $\epsilon_2$ is the largest value squared that you still consider zero. For example, if your coordinates and velocity components have three decimals, then $\epsilon_2 = 0.0005^2 = 0.00000025$. For $\eqref{G1c}$, use the side whose denominator has the largest magnitude: the first right side if $\lvert \dot{\mathcal{Y}}_j - \dot{\mathcal{Y}}_i \rvert \ge \lvert \dot{\mathcal{X}}_j - \dot{\mathcal{X}}_i \rvert$, the second right side otherwise.)

Solving $\eqref{G2}$ for $t_1$ and $t_2$ yields $$\begin{aligned} d &= \dot{\mathcal{X}}_i \dot{\mathcal{Y}}_j - \dot{\mathcal{Y}}_i \dot{\mathcal{X}}_j \\ t_1 &= \displaystyle \frac{ ( \mathcal{X}_j - \mathcal{X}_i ) \dot{\mathcal{Y}}_j - ( \mathcal{Y}_j - \mathcal{Y}_i ) \dot{\mathcal{X}}_j }{d} \\ t_2 &= \displaystyle \frac{ ( \mathcal{X}_j - \mathcal{X}_i ) \dot{\mathcal{Y}}_i - ( \mathcal{Y}_j - \mathcal{Y}_i ) \dot{\mathcal{X}}_i }{d} \\ \end{aligned}$$ and if $d = 0$, the trajectories are parallel and do not intersect. One or both of the times $t_1$ or $t_2$ may be negative, as well.