Advertisement

Aiming ranged weapon with gravity

Started by February 20, 2015 12:30 PM
2 comments, last by alvaro 9 years, 11 months ago

So I have a following problem to solve.

I have a firing position a.

I know projectile will have scalar velocity v, but I don't know the vector, because..

..I'm aiming at target which it at position b at the time of firing and has a constant known vector velocity of w. I assume it will be constant, that is.

There is one more factor to count in, however. Gravity. The projectile is affected by gravity vector g.

Now how do I solve this?

I noticed the following thing:

after time t, the projectile will be anywhere on the surface of the sphere with its middle in a + gt^2/2 and radius of vt.

that has to be equal with the position of target after time t, which would be b + wt

with sphere equation it would look like this a + gt^2/2 - b - wt = v^2t^2

Now this is a quartic. It is solveable. Its very complex however. Has anyone got any simlper idea of solving this? My current code doesn't even work apropriatly yet, so I'm not even sure I got this right.

I'll break down my solution. I solve the following for every coordinate.

First, i get my quartic right. Anyone can do this on his own. I have a plain quartic. Now I get the depressed quartic as described at http://en.wikipedia.org/wiki/Quartic_function.

So then I try to get two quadratics from it, as described in said article. I then solve a cubic for a p^2 and get a solution. I take a single solution, which comes from real root of unity and I get my two quadratics. They give me up to 4 real solutions. After appropriate conversion they should give me good results. I am not certain they do. When I have the minimum time of collision, aiming is trivial. Just aim at b + wt - gt^2/2

You can solve a quartic numerically, for instance using Newton's method. It shouldn't be too hard to do.
Advertisement

I think I figured out the quartic, but the algorithm itself doesn't seem to work. I get three quartics for three coordinates and then find identical roots for them. Is this actually a good idea? Would there be more reliable way?

No, you solve for a single variable: Time. From there it should be easy to figure out the rest.

This topic is closed to new replies.

Advertisement