   Calculating trajectories
  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.   
  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   ;  You might also try here. Ballistics without any air resistance or other effects is actually relatively simple.   ;  this has troubled me for ages, i understood and implemented the answer only recently.x,y is the targetj,k is the beginning pointg is gravityv is velocityθ is the angle of elevationb = (x - j)a = g(b^2) / 2(v^2)c = k - y + ad = b^2 - 4acif (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 + piend ifthere 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 θ + kto 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 θ + kusing:sin θ / cos θ = tan θ1 / cos^2 θ = tan^2 θ + 1simplify and re-arrange: 0 = [g(x - j)^2(tan^2 θ + 1) / 2v^2] + tan θ(x - j) + k - jexpand 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]