I'm trying to figure out the general equation for calculating the launch angle of one projectile required when trying to find a collision between that projectile and another. For the equation I've worked out so far, everything is constant/user-defined. I'm also assuming both projectiles are launched at time 0. d_T is the displacement of the target and d_P is the displacement of the projectile.
My initial vectored equations for the motion of the two particles. The user simply specifies the two velocity components for the target, and then the two projectile components are broken from the magnitude into two using sin and cos.
$$d_T= <V_{Tx}t + d_{T0x}, V_{Ty}t + d_{T0y} - \frac{1}{2}gt^2>$$
$$d_P=<V_{P}t\cos(\theta) + d_{P0x}, V_{P}t\sin(\theta) + d_{P0y} - \frac{1}{2}gt^2>$$
Setting the each component equal to the other's respective component:
$$V_{Tx}t + d_{T0x} = V_{P}t\cos(\theta) + d_{P0x}$$ $$V_{Ty}t + d_{T0y} = V_{P}t\sin(\theta) + d_{P0y}$$
Algebra: $$t(V_{Tx}-V_{P}\cos(\theta)) = d_{P0x} - d_{T0x}$$ $$t(V_{Ty}-V_{P}\sin(\theta)) = d_{P0y} - d_{T0y}$$ $$\frac{d_{P0x}-d_{T0x}}{V_{Tx}-V_{P}\cos(\theta)}=\frac{d_{P0y} - d_{T0y}}{V_{Ty}-V_{P}\sin(\theta)}$$
Now this is where my question comes into play. Is there a way to further manipulate the expression to solve for theta? I tried playing around with it a bit to get $$\frac{V_{Ty}-V_{P}\sin(\theta)}{V_{Tx}-V_{P}\cos(\theta)}=\frac{d_{P0y} - d_{T0y}}{d_{P0x}-d_{T0x}}$$
where I hoped I could get a sin/cos to get a tan, but no such luck cause of the pesky target velocity. Is there a possible way to algebraically/otherwise way to solve this or do I need to completely reapproach the problem?
Thanks!
Here is how I would solve this.
Let's assume that the target is launched from $(x_0, y_0)$, $x_0 \ge 0$, towards negative $x$ coordinates, at time $t = -t_0$, $t_0 \ge 0$. The muzzle velocity is $v_0$, angle $\theta_0$, and gravity $g$. Wind resistance and coriolis forces are not accounted for. The trajectory of the target projectile is $$\begin{cases}x_T(t) = x_0 - (t + t_0) v_0 \cos\theta_0\\ y_T(t) = y_0 + t v_0 \sin\theta_0 - (t + t_0)^2 g/2\end{cases}$$
The target projectile reaches ground when $y_T(t) = 0$. (Because the trajectory is a parabola, the $t$ we are interested from is the larger one, if there are two real roots. If there are no real roots, then the target projectile is launched from below the ground level, without the projectile ever reaching ground level.) Solving $y_T(t_{Z}) = 0$ for $t_{Z}$ yields $$t_Z = \sin(\theta_0) \frac{v_0}{g} + \frac{\sqrt{\sin(\theta_0)^2 v_0^2 + 2 g y_0}}{g} - t_0$$ Later, when we solve for the time when the intercept is to occur, we need to compare against $t_Z$, to make sure the intercept occurs before the target projectile reaches the ground.
The intercepting projectile is launched from origin $(0,0)$ at time $t=0$ towards positive $x$ coordinates, with muzzle velocity $v_1$, and launch angle $\theta_1$. The trajectory of this intercepting projectile is $$\begin{cases}x_I(t) = t v_1 \cos\theta_1\\ y_I(t) = t v_1 \sin\theta_1 - t^2 g/2\end{cases}$$ It is easier to do the following calculations if we use $c = \cos\theta_1$ and $\sin\theta_1 = \sqrt{1-c^2}$. The trajectory is then $$\begin{cases}x_I(t) = t v_1 c\\ y_I(t) = t v_1 \sqrt{1-c^2} - t^2 g/2\end{cases}$$
For the intercept to occur at time $t$, the projectiles' $x$ coordinates must match: $$x_T(t) - x_I(t) = 0$$ Solving for $c$ we get $$c(t) = \frac{x_0 - (t_0 + t)\cos\theta_0 v_0}{t v_1}$$ The launch is only possible when $-1 \le c(t) \le 1$. Solving for $t$ we get $$\begin{align} c(t_{min}) =& 1 &\iff& t_{min} = \frac{x_0 - t_0 v_0 \cos\theta_0}{v_0 \cos\theta_0 + v_1}\\ c(t_{max}) =& -1 &\iff& t_{max} = \frac{x_0 - t_0 v_0 \cos\theta_0}{v_0 \cos\theta_0 - v_1}\end{align}$$
Using the cosine of launch angle $c(t)$ to intercept the target projectile at time $t$, the projectiles' $y$ coordinates must be equal at $t$ for them to collide: $$y_T(t) = x_T(t), c = c(t)$$ This can be solved for $t$; it is just a quadratic equation in a funny form, with lots of terms. Move all terms to the left side, and the square root to the right side, square both sides, and move the right side back to left, and you end up with a quadratic equation in $t$. There are quite a few terms in it, though.
The two roots are of form $$t = \frac{q \pm \sqrt{s}}{d}$$ where $$d = 2 (g^2 t_0^2 - 2 v_T g t_0 \sin\theta_0 + v_0^2 - v_1^2)$$ $$q = v_0 (3 g t_0^2 - 2 y_0) \sin\theta_0 + 2 v_0 x_0 \cos\theta_0 - t_0(g^2 t_0^2 - 2 g y_0 + 2 v_0)$$ $$s = t_0^2 (g^2 t_0^2 v_1^2 - 4 g^2 x_0^2 - 4 g v_1^2 y_0 + 4 v_1^2 v_0^2) + 4 v_1^2 x_0^2 + 4 v_1^2 y_0^2 - 4 v_0^2 x_0^2 + 4 t_0 v_0 x_0 (g^2 t_0^2 + 2 g y_0 - 2 v_1^2) \cos\theta_0 - v_0^2 (g t_0^2 2 x_0 + 2 y_0)(g t_0^2 - 2 x_0 + 2 y_0) (\cos\theta_0)^2 - 4 v_0^2 x_0 (g t_0^2 + 2 y_0)(\cos\theta_0)\sin\theta_0 - 4 v_0 t_0 (g t_0^2 v_1^2 - 2 g x_0^2 - 2 v_1^2 y_0)\sin\theta_0$$
If $\max(0, t_{min}) < t < \min(t_Z, t_{max})$, then $t$ is a valid time for the collision to occur. If both $t$ are valid, you can pick one -- the earlier one is the obvious choice. (This can occur when the intercepting launcher is positioned correctly to hit the target projectile both when it is ascending, and when it is descending, I believe.)
The intercepting launcher angle is then trivially solved from $c(t)$, i.e. $$\theta_1 = \arccos\left( \frac{x_0 - (t_0 + t)\cos\theta_0 v_0}{t v_1} \right)$$
Remember, interception launch always happens at time $t = 0$; the $t$ above is the time of the collision.
All this math is dull without example code.
Consider this simple awk script,
example.awk:When run, it outputs $N = 200$ rows of trajectory information. Each row has format
time target_x target_y interceptor_x interceptor_y(with the last two duplicated on the moment of collision). If you have bothawkandgnuplotavailable, you can runto compute the trajectories, saving them in file
out, and plotting it on screen usinggnuplot.Using the current parameters in the file, the collision occurs at time $t = 2.931$, with $27.1$ degree launch angle: