Calulating launch angles
I''m trying to calculate the launch angle for a mortar-like weapon for an RTS game I''m working on. In the 2D case:
Given a target (x, y) a launch velocity v and gravity g, what is the angle required to shoot a projectile from (0, 0) to hit the target?
I worked out the solution for hitting a target at (x, 0):
2*angle = asin((g*x) / (v^2)) but I''m stumped as to the solution for the general case.
Any help would be appreciated.
This signature has intentionally been left blank.
yet again another physics question i think the following equations are correct
@ = theta is the angle
V = velocity
g = gravity
t = time
Vy and Vx are velocities in x and y direction
horizontal velocity component
Vx= Vx0= V cos @ = constant
vertical velocity component
Vy = Vy - g*t = V sin @ -gt
horizontal position component
x = Vx*t = (V cos @)t
vertical position component
y = Vy*t - .5gt^2 = (V sin @)t - .5gt^2
@ = theta is the angle
V = velocity
g = gravity
t = time
Vy and Vx are velocities in x and y direction
horizontal velocity component
Vx= Vx0= V cos @ = constant
vertical velocity component
Vy = Vy - g*t = V sin @ -gt
horizontal position component
x = Vx*t = (V cos @)t
vertical position component
y = Vy*t - .5gt^2 = (V sin @)t - .5gt^2
Those equations are correcty but you seem to have missed the point of my post. I''m trying to find theta given a target (x, y) and a launch velocity. What you''ve posted gives the velocity components for a known angle.
This signature has intentionally been left blank.
If the velocity remains constant, it will look quite funny when the target is close to the tank.. The tank will shoot *very* high shots
. I''m not sure if you really want that.
I suggest using constant angle (eg. 45'') and a varying velocity. And it''s very easy to implement too since the flying distance is:
R=(v0^2*sin (2*angle))/g
Solving v0 leads to
v0=sqr(R*g/sin (2*angle))
![](smile.gif)
I suggest using constant angle (eg. 45'') and a varying velocity. And it''s very easy to implement too since the flying distance is:
R=(v0^2*sin (2*angle))/g
Solving v0 leads to
v0=sqr(R*g/sin (2*angle))
Check over my algebra before you use my final answer exactly... sort of odd to do this sort of thing without pencil and paper. Could lead to careless mistakes
.
Otherwise, this is the kind of logic you need to use, along with a trigonometric identity, and finally the quadratic equation to separate the two possible firing solution angles. (Which happen to converge in some special cases.)
given: (0,0) -> (x,y) && v, -g | find: @_1, @_2
V_x = V*cos(@)
x = V_x*dt
dt = x/V_x = (x)/(V*cos(@))
V_yi = V*sin(@)
V_y = V_yi -g*dt = V*sin(@) -g*dt
y = V*sin(@)*dt -.5*g*(dt)^2
y = V*sin(@)*[(x)/(V*cos(@))] -.5*g*[(x)/(V*cos(@))]^2
y = x*tan(@) -(.5*g*x)/(V*cos(@))^2
identity:
tan^2(@) + 1 = sec^2(@)
0 = x*tan(@) -(.5*g*x*tan^2(@))/(V) -(.5*g*x)/(V) -y
tan(@) = (-x +- sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)
@ = tan^-1[(-x +- sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
therefore:
@_1 = tan^-1[(-x + sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
@_2 = tan^-1[(-x - sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
![](wink.gif)
Otherwise, this is the kind of logic you need to use, along with a trigonometric identity, and finally the quadratic equation to separate the two possible firing solution angles. (Which happen to converge in some special cases.)
given: (0,0) -> (x,y) && v, -g | find: @_1, @_2
V_x = V*cos(@)
x = V_x*dt
dt = x/V_x = (x)/(V*cos(@))
V_yi = V*sin(@)
V_y = V_yi -g*dt = V*sin(@) -g*dt
y = V*sin(@)*dt -.5*g*(dt)^2
y = V*sin(@)*[(x)/(V*cos(@))] -.5*g*[(x)/(V*cos(@))]^2
y = x*tan(@) -(.5*g*x)/(V*cos(@))^2
identity:
tan^2(@) + 1 = sec^2(@)
0 = x*tan(@) -(.5*g*x*tan^2(@))/(V) -(.5*g*x)/(V) -y
tan(@) = (-x +- sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)
@ = tan^-1[(-x +- sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
therefore:
@_1 = tan^-1[(-x + sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
@_2 = tan^-1[(-x - sqrt(x^2 +((g^2*x^2)/V^2) +(2*g*x*y)/V)/((-g*x)/V)]
Well,
I''m not quite sure on how this game works, ie is it overhead? If your trying to hit a target on a plain, I would work in vectors. You seem to have the x direction worked out, all I would do is use the same formula, switch y for x and that would be my answer with respect to y. Then add the x and y vectors together, that will give you location.
I''m not quite sure on how this game works, ie is it overhead? If your trying to hit a target on a plain, I would work in vectors. You seem to have the x direction worked out, all I would do is use the same formula, switch y for x and that would be my answer with respect to y. Then add the x and y vectors together, that will give you location.
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};
Why is it called a hot water heater? Isn't it cold when it goes in the tank?
[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement