Jump to content
• Advertisement

# Calculating trajectories

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

So, I have a tank that fires shells at a certain velocity. I have a target a certain distance from the tank. Is there a friendly way to determine the angle at which to fire the shell in order for it to hit the target. I tried to solve this seemingly simple problem in an earlier game, and now I'm faced with it again. Anybody have any ideas? ps. The tank and target are stationary, no wind/funky stuff.

#### Share this post

##### Share on other sites
Advertisement
Here is a site that I found, that has all sorts of stuff related to your topic. I think you'll be most interested in the section near the bottom, about ballistic trajectories. The site is: http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html

#### Share this post

##### Share on other sites
You might also try here. Ballistics without any air resistance or other effects is actually relatively simple.

#### Share this post

##### Share on other sites
this has troubled me for ages, i understood and implemented the answer only recently.

x,y is the target
j,k is the beginning point
g is gravity
v is velocity
θ is the angle of elevation

b = (x - j)
a = g(b^2) / 2(v^2)
c = k - y + a
d = b^2 - 4ac

if (d < 0) then target is out of range (gravity is too strong, or not enough velocity)

θ_1 = artan((-b + sqr(d)) / 2a)
θ_2 = artan((-b - sqr(d)) / 2a)

the range of artan is restricted to [-pi/2, pi/2], so if the target is 'behind us,' (negative distance) the angle needs to be rotated pi radians (180 degrees)

ie:
if( b < 0 ) then
θ_1 = θ_1 + pi
θ_2 = θ_2 + pi
end if

there are two answers, one is a lob shot, and the other is a direct and faster shot. (you can find the time it takes to hit the target with each angle by using the equation below)
------------------------
EXPLANATION:

the functions that model the horizontal and vertical movement over time are respectively:

(1) x = vt cos θ + j
(2) y = ½ gt^2 + vt sin θ + k

to find θ:

re-arrangle (1) for t:
t = (x - j) / v cos θ

substitute into (2)
y = g(x - j)^2 / 2v^2 cos^2 θ + v sin θ(x - j) / v cos θ + k

using:
sin θ / cos θ = tan θ
1 / cos^2 θ = tan^2 θ + 1

simplify and re-arrange:
0 = [g(x - j)^2(tan^2 θ + 1) / 2v^2] + tan θ(x - j) + k - j

expand a little to get the form 0 = ax^2 + bx + c:
0 = [g(x - j)^2 tan^2 θ / 2v^2] + tan θ(x - j) + k - j + [g(x - j)^2 / 2v^2]

use the quadratic formula to find tan θ

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

how does that look?

[Edited by - phillipj on June 1, 2006 3:02:01 AM]

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009708
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!