# Calculating projectile path between 2 moving objects for given force

For 2 moving objects A and B (mass $$m_a$$, $$m_b$$) moving with constant acceleration, given initial accelerations, velocities and positions for both objects, find the velocity required to launch a projectile (mass $$m_p$$) from object A with a magnitude of s (a fixed speed) such that it reaches B. The projectile and object B are both subject to acceleration by wind and gravity vectors (constant).

This problem has stumped me and several other people trying to solve the problem. We are trying to create a cannon on a moving ship that will shoot and hit any moving target. The cannon always shoots the projectile with a constant force. Intuitively, there should always be at least 1 solution to this problem, given that the force is great enough to reach the target. However, we have not been able to find its solution.

Here are our unknowns:

• Travel time
• Projectile initial acceleration (direction only, since force magnitude is known)
• Projectile final velocity
• B final velocity
• Projectile displacement
• B displacement
• Projectile/B final position (intersection point)

What we're mostly looking to find is the travel time, the intersection position as well as the direction in which the initial force should be applied.

After consulting many references, it seems like most of them only talk about either hitting a stationary target, or adjusting the initial force applied. However, we would like to make it work with a same given initial velocity.

The solution doesn't have to be analytical, a good approximation would be sufficient as long as it is fast enough to be simulated in real-time in Unity.

Our previous attempts were to calculate the travel time using kinematics equations, then equate the final position for the projectile and the target; however we quickly hit a wall because they required more variables than we had.

Letter subscripts here denote the object, and 0 means it's an initial value.

$$pos_A = pos_B$$ $$pos_{A0} + v_{A0} \cdot t + \frac{1}{2} a_{A0} \cdot t^2 = pos_{B0} + v_{B0} \cdot t + \frac{1}{2} a_{B0} \cdot t^2$$ $$\frac{1}{2}(a_{A0} - a_{B0})\cdot t^2 + (v_{A0} - v_{B0})\cdot t + pos_{A0} - pos_{B0} = 0$$ Let $$a = \frac{1}{2}(a_{A0} - a_{B0})$$, $$b = (v_{A0} - v_{B0})$$, $$c = pos_{A0} - pos_{B0}$$.

$$t_{1,2} = \frac{-b\pm \sqrt{b^2 - 4ac}}{2a}$$

• The role of object $A$ is not clear. Jul 17, 2023 at 12:33
• You can't have constant acceleration without neglecting the air resistance.
– Alv
Jul 17, 2023 at 12:47
• Object A serves as the initial launch point of the projectile. We are neglecting air resistance for now since we figured it was already complicated enough as is, but if anyone wants to include it in their calculations then there is no problem with that. Jul 17, 2023 at 13:19
• I may have misunderstood, but if $A$ and $B$ are subject to the same two constant forces (gravity and wind), why not change frame of reference? The paths of both the projectile and $B$ would be straight lines relative to $A$, wouldn't they? Jul 17, 2023 at 13:37
• $A$ is not subject to gravity and wind, it is simply the starting point of the projectile and has its own initial acceleration. The projectile is subject to those forces. In our context, A is a cannon on a ship moving in the air, the projectile is a cannonball and B is a flying target. Jul 17, 2023 at 13:39

I've found a reference online that I used to find a solution. I will post it here for anyone else who needs it. Here it is if anyone wants to read it. https://docs.google.com/document/d/1TKhiXzLMHVjDPX3a3U0uMvaiW1jWQWUmYpICjIDeMSA/edit?pli=1

## Notation

Subscripts:

• 0: initial value
• 1: final value (at the intersection point)
• A: starting object
• B: target object
• P: projectile

Variables:

• p: position
• v: velocity
• a: acceleration

$$p_{A1} = p_{A0} + v_{A0}t + \frac{1}{2} a_{A0}t^2$$ $$p_{B1} = p_{B0} + v_{B0}t + \frac{1}{2} a_{B0}t^2$$

First, equate the total displacement of the projectile and the relative position between A and B.

$$v_{P0}t + \frac{1}{2}a_{P0}t^2 = p_{B1} - p_{A1}$$

Knowing the initial speed is the magnitude of the initial velocity vector, we isolate the velocity and take the magnitude of both sides of the equation.

$$\|v_{P0}\|= \|\frac{p_{B1} - p_{A1}}{t} - \frac{1}{2}a_{P0}t^2\|$$

At this rate, the initial magnitude of velocity is known and can be substituted in. You can then either use a numerical solver directly, or you can fully expand the equation to a quartic and then solve for time. The time can then be used to find the initial velocity vector by substituting into usual kinematic equations.