Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to find firing angle given initial and destination positions?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Portable591   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 July 2001 - 07:24 AM

Ok, I''m not sure if this is possible, but is there a way to find a firing angle for a gun if you are given the initial velocity from the gun, initial position of the gun, and an exact distance to a target? Assume the gun and target are on a level plane. I know there could be multiple "correct" angles, but I want the one with the smallest "time to target". Thanks.

Sponsor:

#2 pi_pirate   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 July 2001 - 08:53 AM

If you only know the position of the gun and its distance form the target, but you do not know the position of the target then you do not have enough information to solve this problem. This would mean you only know that the target is somewhere on circle, around the gun. You can’t hit a target if you do not know where it is.

If you do know the position of the target and the both the target and gun are stationary, then the solution would be:

Gun is at: (Gx, Gy) and Target is at: (Tx, Ty) then:

Angle from the horizontal axis = arctan ((Ty-Gy)/(Tx-Gx))

Note: If you use the Win32 function: atan() to calculate the arctan, remember the results are in radians not degrees. If you want to derive this equation just look at the properties of trigonometric functions.

If either the target or the gun is moving, this solution will not work. Let me know if you want the solution for moving objects.


#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 08 July 2001 - 09:53 AM


Assuming a level (horizontal?) plane:

Known:

Velocity (vx is x velocity, vy is y velocity)
Distance to target (dx is x distance, dy is y distance)

Unknown:

Angle

Basic formulas:

vx = vel * cos(angle)
vy = vel * sin(angle)
time = d/v = dx/vx = dy/vy

angle = acos(vx / vel)

vx = dx/time;

angle = acos( (dx/time) / vel);

Problem with this, is we must pick a time to solve for angle.

Oh well, hopefully this is a good starting point.





#4 johnb   Members   -  Reputation: 347

Like
Likes
Like

Posted 08 July 2001 - 11:19 PM

This is easy if you add both the angle and time to your calculations. E.g.

time = t
angle = a
speed = v
gravity = g

Horizontal motion: x = vt cos (a)
Vertical motion: y = vt sin (a) - 0.5 * g * t * t

It hits the ground when y = 0, so

y = vt sin (a) - 0.5 * g * t * t = 0

Solving this quadratic gives this happens when
t = 0
and
t = 2v sin (a) / g

The first value is when it is fired, so it hits when

t = 2v sin (a) / g

putting this into the x equation gives

x = 2v*v sin (a) cos (a) / g

or

x = v*v sin (2a) / g

so

sin (2a) = (g * x) / (v * v)

if (g * x) / (v * v) < 1 this has two solutions, one less than 45 degrees and one greater than 45 degrees. The one with smallest time t is the smallest angle, i.e. the one less than 45 degrees,which then is:

a = 0.5 * arcsin ((g * x) / (v * v))

#5 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 08 July 2001 - 11:25 PM

Good job! I was busy considering x- and y-axis velocities, which left me with an inconclusive answer (I was lacking just one term), so I didn''t post it.

**Hurriedly scribbles down solution.

#6 Portable591   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 July 2001 - 05:27 AM

Thank you so much. I was thinking along the same lines as Oluseyi. But this works very well.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS