# 2D Parabolic Arc between dynamic A-B

This topic is 1906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,
I have a problem and I'm not smart enough to work out a solutions.

I want to achieve a throw, a bomb between two points, and so it travels as an arc from point A, to point B. Point B is known and the bomb must land on point B

if the distance between the two positions AB is dynamic and the horizontal distance changes, the vertical distance may also change.

How can we know the initial vertical velocity in which to throw the object to make it art exactly on to position B?

How can I calculate it so my bomb moves in an arc from whatever point A is, so that it hits point B in an ARC. I have no idea, using other istes this is what I tried, i tried at least...then realized I have no idea for how long to run the loop for, and have no idea how to hit point b exactly.

tagetTilePosition is a vector ( 0 , 0 )
 double startX = bombPosition.x; // initial position double startY = bombPosition.y; // of the object float angle = 45.0f * Mathf.Deg2Rad; const double g = 9.8; // gravity (meters/s^2) double velocity =20.0; double Vx = velocity * Mathf.Cos(angle); // x (horizontal) component of velocity double Vy = velocity * Mathf.Sin(angle); // y (vertical) component of velocity Vector2 distance = ( bombPosition2 - tagetTilePosition ); //guessing double endTime = ( distance.x + distance.y ) / velocity ; for(double wait = 1; wait <= endTime ; wait += 1f) { /* float v_v; double g = 9.8f float s; float t = wait; s = bombPosition.y; t = d / v_h v_v = (0.5f * g * (t * t) + s) / t; */ double t = wait; double x = startX + Vx * t; double y = startY + Vy * t - 0.5 * g * t * t; bombPosition.x = (float) x; bombPosition.y = (float) y; // bombPosition.x = centre.x += ( 60 * Mathf.Cos ( (float) wait ) ); //bombPosition.y = centre.y -= ( 60 * Mathf.Sin ( (float) wait) ); bomb.transform.position = bombPosition; } 

##### Share on other sites
Assuming gravity is the only force on the bomb, and is strictly downwards, and that point [eqn]B[/eqn] does not move while the bomb is in the air (obviously) and that there are no obstacles to consider, then you can in fact work out the exact initial velocity vector needed to hit point [eqn]B[/eqn]. First, let [eqn]A[/eqn] be at coordinates [eqn](a_x, a_y)[/eqn] and [eqn]B[/eqn] at coordinates [eqn](b_x, b_y)[/eqn].

Then, using some kinematics, the position of the bomb at any time [eqn]t[/eqn] will be:

[eqn]\displaystyle \left (a_x + v_x t, ~ a_y + v_y t + \frac{1}{2} g t^2 \right )[/eqn]

So for the bomb to hit [eqn]B[/eqn] somehow, we need the coordinates of the bomb to satisfy:

[eqn]a_x + v_x t = b_x[/eqn]
[eqn]a_y + v_y t + \frac{1}{2} g t^2 = b_y[/eqn]

For some [eqn]t[/eqn]. Rearranging:

[eqn]v_x = \frac{b_x - a_x}{t}[/eqn]
[eqn]v_y = \frac{b_y - a_y- \frac{1}{2} g t^2}{t}[/eqn]

Simplifying:

[eqn]v_x = \frac{b_x - a_x}{t}[/eqn]
[eqn]v_y = \frac{b_y - a_y}{t} - \frac{1}{2} g t[/eqn]

This is a parametric equation in [eqn]t[/eqn], which basically gives a bigger and bigger velocity vector as you decrease the time (the faster you shoot, the less time gravity has to effect the bomb, so at infinite speed you can pretty much just aim towards B and shoot). As you increase the time [eqn]t[/eqn], gravity becomes more important (see the gravity term in the equation) and the direction itself matters less, so you get an increasingly large arc. Here's a rough plot of the parametric I made with a throwaway program:

If you need the bomb to stay a certain amount of time in the air, just plug the correct [eqn]t[/eqn] in, and you have your velocity vector! If you need your velocity vector to be a certain length (for instance, the amount of force with which the bomb is launched), you can use that information to deduce [eqn]t[/eqn] as well. You could also calculate the energy requirements for a given [eqn]t[/eqn] and compare them with whatever energy your bomb cannon has to select the correct one, if you wanted to get really fancy.

N.B. This can be generalized to any gravity vector and to higher dimensions by modifying the kinematics accordingly, but for the sake of simplicity and without loss of generality, only gravity in the vertical direction for the two-dimensional case is considered. Edited by Bacterius

##### Share on other sites
For completeness, I provide the fully generalized version in this post (since I guess someone will eventually ask). Let [eqn]\bold{A}[/eqn] be the initial position vector [eqn]\left ( \mathrm{A}_1, \mathrm{A}_2, \cdots, \mathrm{A}_n \right )[/eqn] and [eqn]\bold{B}[/eqn] the final position vector [eqn]\left ( \mathrm{B}_1, \mathrm{B}_2, \cdots, \mathrm{B}_n \right )[/eqn]. We want to find an initial velocity vector [eqn]\bold{v} \left ( v_1, v_2, \cdots, v_n \right )[/eqn] such that a projectile fired from [eqn]A[/eqn] with this velocity vector will collide with [eqn]B[/eqn] when subject to some constant force [eqn]\vec{F}[/eqn] producing an acceleration [eqn]\bold{a} \left (a_1, a_2, \cdots, a_n \right )[/eqn] on it. Note if the projectile has mass [eqn]m[/eqn], then [eqn]\vec{F} = m \bold{a}[/eqn] as expected.

Let [eqn]\bold{P}_t \left (\mathrm{P}_{1, t}, \mathrm{P}_{2, t}, \cdots, \mathrm{P}_{n, t} \right )[/eqn] be the position of the projectile at time [eqn]t[/eqn] after launch. Then from kinematics, for [eqn]1 \leqslant i \leqslant n[/eqn] we have:

[eqn]\mathrm{P}_{i, t} = \mathrm{A}_i + v_i t + \frac{1}{2} a_i t^2[/eqn]

And for the projectile to collide with [eqn]\bold{B}[/eqn], its position must satisfy [eqn]\bold{P}_t = \bold{B}[/eqn] for some time [eqn]t \geqslant 0[/eqn], so:

[eqn]\mathrm{B}_i = \mathrm{A}_i + v_i t + \frac{1}{2} a_i t^2[/eqn]

[eqn]v_i t = \mathrm{B}_i - \mathrm{A}_i - \frac{1}{2} a_i t^2[/eqn]

[eqn]\displaystyle v_i = \frac{\mathrm{B}_i - \mathrm{A}_i}{t} - \frac{1}{2} a_i t[/eqn]

Yielding a family of solutions for [eqn]\bold{v}[/eqn] for any positive [eqn]t[/eqn]. Negative [eqn]t[/eqn] works too, but it makes little sense since the intersection would have occurred before the projectile was launched, extrapolating its trajectory into the past - though you will notice flipping the sign of [eqn]t[/eqn] flips the sign of [eqn]v_i[/eqn] and thus simply inverts the direction of [eqn]\bold{v}[/eqn] anyway. This is a very nice and flexible result.

--------------------------------

What about nonconstant forces? Suppose [eqn]\vec{F}[/eqn] varies with time, so [eqn]a_i = f_a(i, t)[/eqn]. The force/mass relationship still works, of course. Perhaps this could take into account gravity as well as wind (possibly via some sinusoidal function to simulate atmospheric fluctuations). Can we still predict the correct velocity vector? The answer is, surprisingly, yes, but we must use calculus. We must integrate this acceleration function with respect to time once to obtain velocity, and once again to obtain displacement, which results in the following trajectory for [eqn]P_t[/eqn]:

[eqn]\displaystyle \mathrm{P}_{i, t} = \mathrm{A}_i + v_i t + \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t[/eqn]

With the same criterion as before, this gives:

[eqn]\displaystyle \mathrm{B}_i = \mathrm{A}_i + v_i t + \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t[/eqn]

And rearranging as we did before:

[eqn]\displaystyle v_i = \frac{\displaystyle \mathrm{B}_i - \mathrm{A}_i}{t} - \frac{\displaystyle \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t}{t}[/eqn]

Which, interestingly enough, is a parametric solution in [eqn]t[/eqn]. Now, actually evaluating the double integral is probably the hardest part, especially if you're using some complex function such as perlin noise as the acceleration, but if worst comes to worst, approximations exist. Besides, it's likely your predicted trajectory doesn't have to be perfect, but just close enough.

Let's try and pick some relatively simple time-varying function and see if it works. For instance, let's say in our hypothetical world, gravity is modulated by a sinusoidal function. Kind of weird, but hey. So for instance, we have [eqn]f_a(i, t) = a_{i, 0} \sin{t}[/eqn]. Then the double integral is easy enough to calculate (remember those are definite integrals):

[eqn]\displaystyle\int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t = a_{i, 0} \left ( t - \sin{t} \right )[/eqn]

So let's plug everything into our parametric equation and see what we get:

[eqn]\displaystyle v_i = \frac{\mathrm{B}_i - \mathrm{A}_i}{t} - a_{i, 0} \left ( 1 - \frac{\sin{t}}{t}} \right )[/eqn]

The resulting trajectory for some [eqn]t[/eqn] is illustrated below:

What about a different time-varying function, let's say [eqn]f_a(i, t) = a_{i, 0} \left ( 1 - \sin^2{\pi t} \right )[/eqn]. Then the double integral is more complicated but still tractable:

[eqn]\displaystyle\int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t = a_{i, 0} \frac{1}{8} \left ( 2t^2 + 1 - \cos{2 \pi t} \right )[/eqn]

Which gives the following trajectory for some [eqn]t[/eqn] (this is not a parabola):

--------------------------------

Note if [eqn]f_a(i, t) = a_{i, 0}[/eqn], then the double integral becomes [eqn]\frac{1}{2} a_{i, 0} t^2[/eqn], and we get back the familiar kinematics equation. If [eqn]f_a(i, t) = 0[/eqn] then you just get back [eqn]\bold{v} = \frac{\bold{d}}{t}[/eqn] as you would expect. It's also possible to make the force vary on position instead of just time, but you need more integrals and it just gets messy and tedious to calculate, so we'll leave it at that.

--------------------------------

Additional note: if [eqn]\mathrm{B}[/eqn] happens to be moving, you can also take that into account (isn't math wonderful) by changing the [eqn]\mathrm{B}_i[/eqn] term - which is a position - into a function of time [eqn]t[/eqn]. If you want a time-varying force to be applied to [eqn]\mathrm{B}[/eqn], you can use the same methods as above, which involve another double integral. However at this point, the problem essentially boils down to finding a parameterized intersection of two differential curves, which might be better tackled by other methods involving more specialized forms of calculus. Edited by Bacterius