🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Calculating Launch Angles for a Projectile With a Constant Wind Force

Started by
5 comments, last by JohnnyCode 3 years, 4 months ago

I'm trying to find a way to calculate the azimuth (`a`) and elevation angle (`e`) to have a projectile with a velocity of magnitude `v` hit an arbitrary point (`P_t`) from the origin.

So the velocity vector would be expressed as

v * [cos(a) cos(e), sin(a)*cos(e), sin(e)]

I have a constant x-y acceleration acting on the projectile `W` in addition to gravity, so the acceleration vector acting on the projectile would be

[W_x,  W_y , g]

My intuition was to use the displacement equation in each of the three axes and solve the system, but I'm not quite sure how to go about solving it. Is there a way that this can be solved or approximated?

Advertisement

Given that you want these forces to be constant, and you don't seem to be calculating drag, this is very easy! (no offense) All of the components of your problem can be calculated independently (same as any projectile) then superposed (just added) to give the final answer. Specially if you say your initial velocity is (vx, vy, vz), and your accelerations are (ax, ay, az). A particle in one dimension experiencing constant acceleration can be found by integrating (don't worry if that sounds hard, I'll do it explicitly) the velocity function with respect to time. You can ask Wolfram Alpha, but I'll just tell you here

v = a t + v0, Implies p = ½ a t^2 + v0 t + x0.

Now you can calculate flight time by z's equation (assuming you're starting at the origin)

z = ½ az t^2 + vz t + 0 = 0, Implies t (initial)= 0 or t(impact) = = - 2 vz / az.

Now substitute that value for t into x's and y's equations

x(impact) = ½ ax (t (impact))^2 + vx t(impact).

vx = x(impact) / t(impact) - ½ ax * t(impact).

Expand this (and the condition on vy) in terms of a and e. These give you two conditions on a and e in terms of px, py, Wx, Wy, g, and v. Use inverse trig to find a and e!

I considered v to be fixed since that seemed to be your question. Given this there is no guarantee of a solution, since you'll have some maximum range. This is actually pretty hard to consider in your problem since it isn't just a circle around the target, but skewed by Wx and Wy. The best way that I can think of estimating this is either calculating your range directly into the wind (using the same calculation as above) and using that as the radius of your circle, or guessing that 45 degrees elevation is the optimal firing angle and seeing whether you can overshoot your target.

Cheers!

@mtlk I didn't specify that the delta z was 0, so you can't use the first step to calculate t. The best way to solve for t would be to use the quadratic formula, but then it gets quite ugly I'm afraid. I was able to implement gradient descent for this, but its quite expensive and seems unnecessary.

@undefined Two things:

First, a change in elevation is easily incorporated into the geometric problem. You're saying the best way to solve for t is using the quadratic formula, which means you have most of the machinery already. It gets ugly, but that's because the express form needn't be pretty.

Second, is is definitely unnecessary to treat this problem as an optimization problem (i.e. using gradient descent) …. except maybe. You can express the square of the distance from the target (upon contact with the ground) as a quantity, then take the gradient and set to zero then find the extrema. That's actually a really clever way of dealing with the range problem. You don't need to treat the optimization problem numerically (i.e. using gradient decent).

Quick question, what language are you using? (I assume Python.)

@mtlk I'm using C++ in Unreal, otherwise I would just use something like scipy to solve it. I played around for a while in Mathematica with this (since my algebra is kinda crap) and I'm not certain that an algebraic solution exists.

I'm not quite sure what you mean by not treating the optimization problem numerically though. Gradient descent is just a way of finding the minimum of a function, which currently I have as the distance away from the target.

One simplification I thought to make is to combine x and y into 1 coordinate as the distance from the origin, then it becomes a system of 2 equations and 2 unknowns which is a little bit easier to work with.

I'm trying to find a way to calculate the azimuth (`a`) and elevation angle (`e`) to have a projectile with a velocity of magnitude `v` hit an arbitrary point (`P_t`) from the origin.

That equation exists, for single number of angle and defined power, or, other way around.

It was in my schools book of physics, in " mechanics of point" chapter.

It was an equation derived from check if point is part of curve defined by angle, power, and gravity vector.

This topic is closed to new replies.

Advertisement