Jump to content

Trajectories, solving for theta when range is known.


Amram

Recommended Posts

A project of mine has run face first into a wall at mach 7, due to my inability to resolve what is likely a fairly straightforward math problem.

I'll preface with a video that does a rather good job of explaining most of the problem.

What im trying to do, is code up an AI script for another game. I've been working on improving the bombing scripts, but i've encountered an issue. if I know what angle I plan to release the weapon at, given my speed, altitude, and target altitude, its fairly easy to find the range of 'impact'. Repeated testing against various online calculators confirms im doing that much correctly. Problem is, how do you know the release angle ahead of time?

To give an example, If I am flying at 10km alt, my target is at 50m, my velocity is 257m/s, and I release on a -32° descent angle, and ignoring air drag as the game doesn't consider it, I find a range of 7247.148m. 13,300.637m if +32°

in python

x = ((v * cos(theta)) / g) * (v * sin(theta) + sqrt(pow(v,2) * pow(sin(theta),2) + 2 * g * y))

g = 9.80665

v = 257

y = 9950 (my alt - tgt = 10000 - 50 = 9950)

theta = ± 32 in given examples. In all cases its release angle.

What i can't figure out for the life of me, is how to get back to the original angle with precision. if i know g, v, y, and x, what is theta?

I found an answer on wikipedia, but it confuses me somewhat, and tends to make both my calculator and python angry(math domain errors), plus when I get it working in special cases, the math doesn't work out.

So I did more digging, and I found a forum post, which i've misplaced, so I can't link it, but I have the math used.

theta1 = atan((pow(v,2) + sqrt(abs(pow(v,4) - g * (g * pow(x,2) + 2 * y * pow(v,2)))))/(g * x))

theta2 = atan((pow(v,2) - sqrt(abs(pow(v,4) - g * (g * pow(x,2) + 2 * y * pow(v,2)))))/(g * x))

That should provide me the correct two possible values for theta. However. It causes math domain errors if g*y is positive. I've been feeding it negative y, as I assume that given y is positive when I work top down, and im now working bottom up, y should be flipped right?

When I got this far, I thought I was home free. but doing an theta == theta1 results in False, even when I invert the sign to make it appear correct. So I suspect its a rounding issue, and the result isn't lining up quite right.

if I use those values to compute a new range, to compare against the old one, I get 4 results because I am currently testing both theta's as positive and negative to cover my bases as im not sure the correct step from here. So here's the full output from my script.

theta 32

Popup Range Calc 13300.637m

theta1 -32.000000

theta2 -21.200409

theta -32.000000

range = 7044.423

theta -21.200409

range = -5443.860

theta 32.000000

range = 13240.912

theta 21.200409

range = -12178.599

The first and second passes differ, 13300.637 vs 13240.912(theta value 3).

if I attempt to replicate the video's results:

theta 20

Popup Range Calc 160.244m

theta1 -38.033894

theta2 -20.000000

theta -38.033894

range = 102.637

theta -20.000000

range = 30.819

theta 38.033894

range = 159.635

theta 20.000000

range = 99.248

I get his answers if I work it by hand, so I think its merely a precision error, the script isn't rounding where we are.

as a final confirmation, I tested against the game's approximation, it uses:

t_flight = math.sqrt(0.20394324 * (own_alt_m - tgt_alt))

release_range_m = t_flight * own_speed_mps

if i set theta to zero, I get the exact same results to how ever many digits i care to show, so in level bombing im every bit as accurate. Thing is, the game has no capacity to loft/dive on targets while bombing, which is what im out to improve upon.

So, anyone willing to take a crack at it?

What is screwing me, if I understand correctly, is that I have two unknowns, and im not sure how to reformulate to solve for one of them. Theta, and time. I can solve for one or the other, if I know the other one. But i can't figure out how to get back to theta from range.

I presume that given that I can solve for range and time if given theta to work with, that its possible to go in the other direction and figure out time, and then theta if given range instead, i just can't figure out how.

if its relevant, i never did graduate so be wary of throwing all sorts of symbols at me without defining them too, as it is im currently in the middle of upgrading(math-10 as a refresher atm, math-20 starts in january), but something tells me this is well beyond what i'll be taught for a while yet. I learn quick, math always was my strong suit(er, case in point, getting as far as I have is WAY beyond math 10 stuff, I know, I'm just finishing it now), I just never finished it the first time round.

Edited by Amram
slightly more concise link for video
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...