How to calculate if 2 objects following 2 different arbitrary trajectories will collide?

258 Views Asked by At

I would like to know how I can determine if two objects following a trajectory will collide only knowing their position and velocities and acceleration due to gravity.

Example 1: A pirate shoots a cannonball from his ship, which we can call "evil ship" at another ship which we can call "victim ship". An ally of victim ship, which we can call "ally ship" tries to stop the cannonball from hitting the victim ship by trying to shoot a cannonball towards the trajectory of evil ship's cannonball, in the hopes to knock evil ship's cannonball out of its trajectory.

Problem: As soon as ally ship shoots his cannonball and we know its initial velocity, how can it be determined if his cannonball will meet with evil ship's cannonball at that moment?

Example 2: In one of the scenes in the movie "Incredibles", Mr. Incredible tries to save a man that's falling from a building by trying to jump from another building at just the right time to catch the falling man in the air and knocking him back into the building he was falling from (this happens right before "bomb voyage" appears).

Problem: As soon as Mr. Incredible jumps and we know his jump-velocity, how can it be determined if he will successfully be able to catch the falling man at that moment?

2 scenarios to keep in mind:

  1. If Mr. Incredible jumps towards the falling man too early or too soon, he won't be able to save the man, and if the ally ship shoots too early or too soon, he won't be able to save the victim ship. In this case it's not simply checking if 2 parabolas will cross.

  2. It shouldn't be assumed that the 2 trajectories will actually cross; it could be that Mr. Incredible jumps in a completely wrong direction or the ally ship shoots the cannonball in a completely wrong direction. In this case, just checking if the 2 parabolas will cross should be enough, because there will be no collision regardless of when Mr. Incredible jumps or when the ally ship shoots its cannonball.

The idea is to know the outcome of a possible collision between 2 objects simply by knowing their velocities and positions at any given time. This way, it can be predetermined when the collision of 2 objects will occur at the moment that the cannonball is shot (example 1) or the character jumps towards another character (example 2), before the actual collision happens (if it even happens).

It would be greatly appreciated if the math is explained in depth, including the meaning of any greek letters or symbols used to denote math terms. Also, providing an example with actual values would help a lot too.

2

There are 2 best solutions below

2
On

If you know about relative motion, then if you see from frame of reference of ball A. Then you will notice that acceleration of both the balls is same (magnitude as well as direction) so wrt ball A acceleration of ball B will be zero, and relative velocity of ball B wrt ball A, will remain the same at all time( because acceleration is zero). So wrt ball A, Ball B will do straight line motion with constant velocity(=initial relative velocity). So if the direction cosines of line through ball B and ball A's initial position are equal to direction cosines of relative velocity, then definitely they will collide. (provided they are approaching each other)

0
On

We will do the calculation on a surface with no curvature and two cannons firing in arbitrary directions. Cannon $1$ fires from position $\textbf{r}_1$ with velocity $\textbf{v}_1$ and cannon $2$ fires from position $\textbf{r}_2$ with velocity $\textbf{v}_2$. From the initial relative distances $\Delta \textbf{r}_0 = \textbf{r}_1 - \textbf{r}_2$ and velocities $\Delta \textbf{v} = \textbf{v}_1 - \textbf{v}_2$ one can compute the relative distance $\Delta \textbf{r}$ between two cannonballs:

$$ \Delta \textbf{r} = \Delta \textbf{v} t + \Delta \textbf{r}_0 $$

Or:

$$ \Delta \textbf{r}_x = \Delta v_x t + \Delta x $$ $$ \Delta \textbf{r}_y = \Delta v_y t + \Delta y $$ $$ \Delta \textbf{r}_z = \Delta v_z t + \Delta z $$

From which we can conclude that the distance between the cannonballs $\Delta s$ is:

$$ \Delta s = \vert \Delta \textbf{r} \vert = \sqrt{\sum_i \left( \Delta v_i t + \Delta x_i \right)^2} $$

With $v_i = v_x, v_y, v_z$ and $x_i = x, y, z$. Differentiating above we get:

$$ \frac{d \Delta s}{dt} = \frac{\sum_i \left( \Delta v_i t + \Delta x_i \right) \Delta v_i}{\sqrt{\sum_i \left( \Delta v_i t + \Delta x_i \right)^2}} $$

From which we can conclude that the cannonballs are closest at time $t$:

$$ t = -\frac{\sum_i \Delta x_i \Delta v_i}{\sum_i \Delta v_i^2} $$

Or:

$$t = -\frac{\Delta x \Delta v_x + \Delta y \Delta v_y + \Delta z \Delta v_z}{\Delta v_x^2 + \Delta v_y^2 + \Delta v_z^2} = -\frac{\Delta \textbf{v} \cdot \Delta \textbf{r}_0}{\Delta \textbf{v}^2}$$

We then check if $t > 0$ and that the distance $ \Delta s $ is within some threshold $\epsilon$, i.e. $\Delta s \leq \epsilon$ and if this is the case a collision has occurred. We should then check that the collision occurs within the game space

An example. Consider two cannons $A$ and $B$. $A$ is located at $\textbf{r}_1 = \left(0, 0, 0 \right)$ and $B$ is located at $\textbf{r}_2 = \left(1, 1, 0 \right)$. Cannon $A$ fires with initial velocity $\textbf{v}_1 = \left(1, 1, 100 \right)$ and cannon $B$ with $\textbf{v}_2 = \left(-1, -1, 100 \right)$. After a time of $\frac{1}{2}$ indeed $\Delta s = 0$.

Alternatively, we can include the radii $R_j$, $j = 1,2$, of the cannonballs in the model. Then we have:

$$ \sum_i \left( \Delta v_i t + \Delta x_i \right)^2 = \left( R_1 + R_2 \right)^2 = R^2$$

Which means the cannonballs collide at time $t$:

$$ t = \frac{- \Delta \textbf{v} \cdot \Delta \textbf{r}_0 - \sqrt{\left( \Delta \textbf{v} \cdot \Delta \textbf{r}_0 \right)^2 - \Delta \textbf{v}^2 \left( \Delta \textbf{r}_0^2 - R^2 \right)} } {\Delta \textbf{v}^2} $$