# Trajectory, equation

## Main Question or Discussion Point

I have never taken any physics course before, but I am designing a game in which the projectile(bullet) is going to drop over time.

I want to know which equation do I use to calculate the position on a trajectory. Given that I have the angle, and initial velocity.

http://en.wikipedia.org/wiki/Trajectory

From this would it be the Derivation of the equation of motion as it is the only one I can see there that is returning a y value.

Secondly, if this is true, would the black trajectory here:

Represent the kind of output I'm going to see, since (at the moment) I am not incorporating any drag?

## Answers and Replies

Gib Z
Homework Helper
Yes the equation you found indeed gives the height of the trajectory if you know the horizontal displacement. You stated you know the angle and initial velocity, but to get the height you would need either the time is has been travelling or the displacement horizontally. If you have time rather than horiontal displacement, you need a different equation.

And yes, if you are not incorporating any drag it is true that a) The motion will be parabolic and b) the trajectories that reach higher peaks have a longer time of flight.

Oddly enough, I came here to ask a similar question.

I'm trying to implement a similar situation in a game, but I'm having issues coming up with a good formula.

If I have an object starting an an arbitrary point in 2d space (x,y), how can I calculate the trajectory angle needed in order to "throw" an object and ensure it lands at a second point in 2d space. In my scenario gravity is known, initial velocity is known, and the time it takes to get to the second point is irrelevant. I simply need to calculate the angle I need.

Any ideas?

Yeah actually, after a lot of searching I came across this

http://babek.info/libertybasicfiles/lbnews/nl130/proj3d.htm [Broken]

Implemented that in C++, works perfectly.

Last edited by a moderator:
Oddly enough, I came here to ask a similar question.

I'm trying to implement a similar situation in a game, but I'm having issues coming up with a good formula.

If I have an object starting an an arbitrary point in 2d space (x,y), how can I calculate the trajectory angle needed in order to "throw" an object and ensure it lands at a second point in 2d space. In my scenario gravity is known, initial velocity is known, and the time it takes to get to the second point is irrelevant. I simply need to calculate the angle I need.

Any ideas?

Basically, you have a set of simultaneous equations, one for y-displacement and one for x-displacement, and you can solve for independently. You can break the initial velocity into x and y compoments dependent on the angle of fire.

Oddly enough, I came here to ask a similar question.

I'm trying to implement a similar situation in a game, but I'm having issues coming up with a good formula.

If I have an object starting an an arbitrary point in 2d space (x,y), how can I calculate the trajectory angle needed in order to "throw" an object and ensure it lands at a second point in 2d space. In my scenario gravity is known, initial velocity is known, and the time it takes to get to the second point is irrelevant. I simply need to calculate the angle I need.

Any ideas?
(Note that these formulas have the following assumptions: angles in degrees, distance in meters and that the acceleration of gravity is 9.8 m/s2)

Given the initial velocity Vi and the trajectory angle [itex]\alpha[/tex], you have horizontal and vertical components of the initial velocity:
Vix = Vi [itex]\times[/tex] cos([itex]\alpha[/tex]), Viy = Vi [itex]\times[/tex] sin([itex]\alpha[/tex])

Likewise, given the angle [itex]\beta[/tex] and distance D to the target, there is a horizontal and vertical displacement:
Dx = D [itex]\times[/tex] cos([itex]\beta[/tex]), Dy = D [itex]\times[/tex] sin([itex]\beta[/tex])

The time it takes for the projectile to cover the horizontal distance can be found by:
(1) t = $$\frac{D_x}{V_{ix}}$$

The vertical offset over time t, can then be found by:
(2) Dy = $$V_{iy}\cdot t - 4.9 \cdot t^2$$

In your case, the angle [itex]\alpha[/tex] is unknown and therefore, so are Vix and Viy, so substituting equation (1) into equation (2) gives us:
$$D_y = V_{iy} \cdot \frac{D_x}{V_{ix}}-4.9 \cdot \left( \frac{D_x}{V_{ix}} \right)^2$$

$$D_y=\frac{V_{ix} \cdot V_{iy} \cdot D_x}{{V_{ix}}^2} - \frac{4.9 \cdot {D_{x}}^2}{{V_{ix}}^2}$$

$$D_y=\frac{V_{ix} \cdot V_{iy} \cdot D_x - 4.9 \cdot {D_x}^2}{{V_{ix}}^2}$$

$$D_y \cdot {V_{ix}}^2 = D_x \cdot V_{iy} \cdot V_{ix} - 4.9 \cdot {D_x}^2$$

$$D_y \cdot {V_{ix}}^2 + 4.9 \cdot {D_x}^2 = D_x \cdot V_{iy} \cdot V_{ix}$$

Squaring both sides, we get
(3) $${D_y}^2 \cdot {V_{ix}}^4 \; + \; 9.8 \cdot D_y \cdot {D_x}^2 \cdot {V_{ix}}^2 \; + \; 24.01 \cdot {D_x}^4 = {D_x}^2 \cdot {V_{iy}}^2 \cdot {V_{ix}}^2$$

Now, we know that Vix2 + Viy2 = Vi2 and therefore Viy2 = Vi2 - Vix2

substituting into equation (3) gives us:
$${D_y}^2 \cdot {V_{ix}}^4 \; + \; 9.8 \cdot D_y \cdot {D_x}^2 \cdot {V_{ix}}^2 \; + \; 24.01 \cdot {D_x}^4 = {D_x}^2 \cdot ({V_i}^2 \; - \; {V_{ix}}^2) \cdot {V_{ix}}^2$$

Multiplying out and rearranging, we have:
$${D_y}^2 \cdot {V_{ix}}^4 \; + \; {D_x}^2 \cdot {V_{ix}}^4 \; + \; 9.8 \cdot D_y \cdot {D_x}^2 \cdot {V_{ix}}^2 \; - \; {D_x}^2 \cdot {V_i}^2 \cdot {V_{ix}}^2 \; + \; 24.01 \cdot {D_x}^4 = 0$$

$$({D_y}^2 \; + \; {D_x}^2) \cdot {V_{ix}}^4 \; + \; (9.8 \cdot D_y \cdot {D_x}^2 \; - \; {D_x}^2 \cdot {V_i}^2) \cdot {V_{ix}}^2 \; + \; 24.01 \cdot {D_x}^4 = 0$$

But, since Dx2 + Dy2 = D2, we have:
(4) $$D^2 \cdot {V_{ix}}^4 \; + \; (9.8 \cdot D_y \cdot {D_x}^2 \; - \; {D_x}^2 \cdot {V_i}^2) \cdot {V_{ix}}^2 \; + \; 24.01 \cdot {D_x}^4 = 0$$

The equation (4) is a quadratic and Vix is the only unknown variable.

Remember that for quadratics of the form ax2 + bx + c = 0, we solve for x by using the quadratic formula:
$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

$$x = {V_{ix}}^2$$

$$a = D^2$$

$$b = 9.8 \cdot {D_x}^2 \cdot D_y - {D_x}^2 \cdot {V_i}^2$$

$$c = 24.01 \cdot {D_x}^4$$

Solving the quadratic equation is easier done in parts: We already have determined a, b, & c. The value under the radical sign of the quadratic formula (b2 - 4ac) is known as the determinant. Let's call "d" the square root of the determinant. So now you'll have to solve for d:
$$d = \sqrt{b^2 - 4ac}$$

and then plug the rest of the numbers into each of the following equations:

$${V_{ix}}^2 = \frac{-b + d}{2a}$$ and
$${V_{ix}}^2 = \frac {-b - d}{2a}$$

and solve for $$V_{ix}$$ in each case.

Call the results $$V_{ix1}$$ and $$V_{ix2}$$

Having solved for Vix, it is a simple matter to find the required trajectory angle (note that for all angles except 45 degrees, there exists two trajectory angles to reach your target - provided nothing is in the way of one or both of the calculated trajectories):

$$\alpha = cos^{-1}\left( \frac{V_{ix1}}{V_i} \right)$$
or
$$\alpha = cos^{-1}\left( \frac{V_{ix2}}{V_i} \right)$$

$$a = D^2$$

$$b = 9.8 \cdot {D_x}^2 \cdot D_y - {D_x}^2 \cdot {V_i}^2$$

$$c = 24.01 \cdot {D_x}^4$$

Solving the quadratic equation is easier done in parts: We already have determined a, b, & c. The value under the radical sign of the quadratic formula (b2 - 4ac) is known as the determinant. Let's call "d" the square root of the determinant. So now you'll have to solve for d:
$$d = \sqrt{b^2 - 4ac}$$

and then plug the rest of the numbers into each of the following equations:

$${V_{ix}}^2 = \frac{-b + d}{2a}$$ and
$${V_{ix}}^2 = \frac {-b - d}{2a}$$

and solve for $$V_{ix}$$ in each case.

Call the results $$V_{ix1}$$ and $$V_{ix2}$$

Having solved for Vix, it is a simple matter to find the required trajectory angle (note that for all angles except 45 degrees, there exists two trajectory angles to reach your target - provided nothing is in the way of one or both of the calculated trajectories):

$$\alpha = cos^{-1}\left( \frac{V_{ix1}}{V_i} \right)$$
or
$$\alpha = cos^{-1}\left( \frac{V_{ix2}}{V_i} \right)$$
As an example, suppose your target lies 100m away at an angle (alpha) of 36.8699 degrees uphill. Also, suppose your projectile is an arrow with an initial speed of 75 m/s. You need to find the angle of trajectory (beta) needed in order to hit the target.

So, we start with the following values:
D = 100
alpha = 36.8699
Vi = 75

First, we need to determine the horizontal and vertical offsets to our target:
Dx = D x cos(alpha) = 100 x cos(36.8699) = 80
Dy = D x sin(alpha) = 100 x sin(36.8699) = 60

Now, we can find a, b, c, & d:

$$a = D^2 = 100^2 = 10,000$$
$$b = 9.8 \times {D_x}^2 \times D_y - {D_x}^2 \times {V_i}^2 = -32,236,800$$
$$c = 24.01 \times {D_x}^4 = 983,449,600$$

$$d = \sqrt{b^2 - 4ac} = 31,620,773.080998$$

Solve for the 2 equations:

$${V_{ix1}}^2 = \frac{-b + d}{2a}$$ and

$${V_{ix2}}^2 = \frac {-b - d}{2a}$$:

$${V_{ix1}}^2 = \frac{-b + d}{2a} \approx 3192.8787$$

and

$${V_{ix2}}^2 = \frac {-b - d}{2a} \approx 30.8013$$

Take the square roots:

$$V_{ix1} \approx 56.5056$$

and

$$V_{ix2} \approx 5.5499$$

Finally, determine the angles:

$$\alpha_1 = \cos^{-1} \left( \frac{V_{ix1}}{Vi} \right) \approx 41.1136^\circ$$

and

$$\alpha_2 = \cos^{-1} \left( \frac{V_{ix2}}{Vi} \right) \approx 85.7563^\circ$$