0
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ Are the trajectories two- or three-dimensional? Your math looks 2d, i.e. the launchers are collinear and facing each other (or directed in the same direction). $\endgroup$ – Nominal Animal May 20 '16 at 8:06
  • $\begingroup$ @NominalAnimal Sorry, yes, it's 2D for now. $\endgroup$ – Nic May 20 '16 at 17:50
0
$\begingroup$

There is no unique answer. The collision occurs at different points depending on what the projectile velocity is.

Changing variable names for ease of reference.

For projectile:

  • horizontal and vertical components of velocitiy $v_1, v_2$ respectively
  • launch point $O(0,0)$

For target:

  • horizontal and vertical components of velocitiy $u_1, u_2$ respectively

  • launch point $A(a,b)$

Now solve for point of collision.

  • Horizontal: $$v_1 t=u_1 t+a$$
  • Vertical: $$v_2t-gt^2/2=u_2t-gt^2/2+b\\ \Rightarrow v_2t=u_2t+b$$

Solving gives $$v_2=\frac ba (v_1-u_1)+u_2$$ and $$t=\frac a{v_1-u_1}$$

Hence the collision will occur at $t=a/(v_1-u_1)$ if the launch velocity of the projectile has components $(v_1,v_2)=(v_1,\frac ba(v_1-u_1)+u_2) \qquad\blacksquare$.

See this as an illustration.

$\endgroup$
0
$\begingroup$

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:

#!/usr/bin/awk -f
function x_T(t)   { return x_0 - (t + t_0) * v_0 * cos_T }
function y_T(t)   { return y_0 + (t + t_0) * v_0 * sin_T - 0.5 * g * (t + t_0) * (t + t_0) }
function x_I(t,c) { return t * v_I * c }
function y_I(t,c) { return t * v_I * sqrt(1 - c*c) - 0.5 * g * t * t }

BEGIN {
    N = 200         # 200 points along the trajectory

    g = 9.81        # Standard gravity, 9.81 m/s^2

    # Target launcher
    x_0 = 1000.0    # 1000 m away
    y_0 = 30.0      # Higher elevation
    a_0 = 30.0      # 30 degree launch angle
    v_0 = 100.0     # 100 m/s muzzle velocity
    t_0 = 5.0       # Fired five seconds ago

    # Intercepting launcher
    v_I = 120.0     # 120 m/s muzzle velocity

    cos_T = cos(a_0 * 3.14159265358979323846 / 180.0)
    sin_T = sin(a_0 * 3.14159265358979323846 / 180.0)

    # In case the target never reaches ground level...
    if (sin_T*sin_T*v_0*v_0 + 2*g*y_0 < 0.0) {
        printf "Target never reaches ground level.\n" > "/dev/stderr"
        exit(0)
    }

    # Time when target projectile hits y(0) (final time)
    t_Z = sin_T * v_0 / g + sqrt(sin_T*sin_T*v_0*v_0 + 2*g*y_0) / g - t_0;
    if (t_Z < 0.0) {
        printf "Target projectile reaches destination %.3f seconds before intercept launch.\n", -t_Z > "/dev/stderr"
        exit(0)
    }

    # Minimum and maximum launch times (with valid launch angle)
    t_min = (x_0 - cos_T*t_0*v_0) / (cos_T * v_0 + v_I)
    t_max = (x_0 - cos_T*t_0*v_0) / (cos_T * v_0)
    if (t_min < 0)   t_min = 0
    if (t_max > t_Z) t_max = t_Z
    if (t_min > t_max) {
        printf "No launch window for interception.\n" > "/dev/stderr"
        exit(0)
    }

    # Coefficients for launch time solutions
    s = t_0*t_0*(g*g*t_0*t_0*v_I*v_I - 4*g*g*x_0*x_0 - 4*g*v_I*v_I*y_0+4*v_I*v_I*v_0*v_0)+4*v_I*v_I*x_0*x_0+4*v_I*v_I*y_0*y_0-4*v_0*v_0*x_0*x_0 + cos_T *4*t_0*v_0*x_0*(g*g*t_0*t_0+2*g*y_0-2*v_I*v_I) - cos_T*cos_T*v_0*v_0*(g*t_0*t_0+2*x_0+2*y_0)*(g*t_0*t_0-2*x_0+2*y_0) - cos_T*sin_T*4*v_0*v_0*x_0*(g*t_0*t_0+2*y_0) - sin_T*4*v_0*t_0*(g*t_0*t_0*v_I*v_I-2*g*x_0*x_0-2*v_I*v_I*y_0);
    d = 2*(g*g*t_0*t_0 - 2*v_0*sin_T*g*t_0 - v_I*v_I + v_0*v_0)
    c = sin_T*v_0*(3*g*t_0*t_0 - 2*y_0) + 2*cos_T*v_0*x_0 - t_0*(g*g*t_0*t_0 - 2*g*y_0 + 2*v_0*v_0)
    if (s >= 0.0 && d != 0.0) {
        t1 = (c + sqrt(s)) / d
        t2 = (c - sqrt(s)) / d
    } else {
        printf "Interception is not possible.\n" > "/dev/stderr"
        exit(0)
    }

    # Interception time
    if (t1 >= t_min && t1 <= t_max && t2 >= t_min && t2 <= t_max) {
        if (t1 < t2) t_I = t1
        else         t_I = t2
    } else
    if (t1 >= t_min && t1 <= t_max)
        t_I = t1
    else
    if (t2 >= t_min && t2 <= t_max)
        t_I = t2
    else {
        printf "Interception will fail.\n" > "/dev/stderr"
        exit(0)
    }

    # Cosine of the launch angle
    c = (x_0 - cos_T * v_0 * (t_0 + t_I)) / (t_I * v_I);
    if (c <= 0.0 || c >= 1.0) {
        printf "Incorrect launch angle.\n" > "/dev/stderr"
        exit(0)
    }

    # Launch angle. awk has no arccos()...
    a = 180.0/3.14159265358979323846 * atan2(sqrt(1-c*c), c)
    printf "Intercept in %.3f seconds using %.1f degree launch angle.\n", t_I, a > "/dev/stderr"

    # Output the trajectories using N samples.
    t = -t_0
    for (i = 0; i <= N; i++) {
        tprev = t
        t = -t_0 + (t_Z + t_0) * i / N

        # Interceptor launch?
        if (tprev < 0 && t >= 0) {
            printf "%.6f", 0
            printf " %.6f %.6f", x_T(0), y_T(0)
            printf " %.6f %.6f", 0, 0
            printf "\n"
        }

        # Intercept?
        if (tprev < t_I && t >= t_I) {
            printf "%.6f", t_I
            printf " %.6f %.6f", x_T(t_I), y_T(t_I)
            printf " %.6f %.6f", x_I(t_I, c), y_I(t_I, c)
            printf " %.6f %.6f", x_I(t_I, c), y_I(t_I, c)
            printf "\n"
        }

        # Time
        printf "%.6f", t

        # Target
        printf " %.6f %.6f", x_T(t), y_T(t)

        # Interceptor projectile?
        if (t >= 0 && t < t_I)
            printf " %.6f %.6f", x_I(t, c), y_I(t, c)

        printf "\n"
    }

    exit(0)
}

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 both awk and gnuplot available, you can run

awk -f example.awk > out && gnuplot -p -e 'plot "out" u 2:3 t "Target" w lines lc 1, "out" u 4:5 t "Interceptor" w lines lc 3, "out" u 6:7 notitle w points pt 1 lc -1'

to compute the trajectories, saving them in file out, and plotting it on screen using gnuplot.

Using the current parameters in the file, the collision occurs at time $t = 2.931$, with $27.1$ degree launch angle: Example

$\endgroup$
-1
$\begingroup$

change in the MathJax that results in every MathJax equation being doubled, one being an image and one being a text-based rendering. Usually one of them is hidden, but sometimes the doubles are positioned corner to corner, as shown here. As was already noted, a hard-refresh (Ctrl-F5) usually

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.