Computing space travel

Started by
8 comments, last by ChristerSwahn 11 years, 11 months ago
[color=#333333][font=Georgia, Utopia,]How can a 3D-autopilot be implemented in a space opera game? In other words, how do you compute the optimal trajectory from A to B in a solar system using classical mechanics?[/font]

[color=#333333][font=Georgia, Utopia,][background=rgb(254, 253, 250)]I solved this problem for the game I'm working on. I haven't found any other solution descriptions to this problem so I wrote an article about it in case others might find it of interest.[/background][/font]

[color=#333333][font=Georgia, Utopia,][background=rgb(254, 253, 250)]Also, there are posters here with deep knowledge in physics simulations and it would be very interesting to hear any comments.[/background][/font]

[color=#333333][font=Georgia, Utopia,][background=rgb(254, 253, 250)]Here's the link:[/background][/font]

[color=#333333][font=Georgia, Utopia,][background=rgb(254, 253, 250)]http://mmoarch.blogspot.se/2012/05/computing-space-travel.html[/background][/font]
Advertisement
The "in a solar system" part threw me off, and I thought you were going to have gravitational effects into account (e.g., potential wells and slingshot), which sounds like a really cool problem, but I wouldn't know where to begin. I was a bit disappointed that you don't deal with that at all. :(

[color=#333333][font=Georgia, Utopia,]How can a 3D-autopilot be implemented in a space opera game?[/font]


I didn't go too in-depth with your solution, but if your aim is to simplify it to the point where it's an analytic solution, then you can just use a Hohmann interplanetary transfer orbit, right? Is this not similar to what you did? This paper explains it better than I ever could: http://ocw.mit.edu/c...07F09_Lec17.pdf

And yeah, like alvaro is implying, and as I'm sure you already know, it's a bit more complicated if you want to take a whole lot of bodies into consideration. It's no longer just "a couple of two-body problems stitched together". At best, it would likely mean having to correct your course due to the many minor perturbations that you undergo as you travel from one planet to the other. At worst, it would mean having to postpone launch or taking a highly inoptimal course to ensure that your ship won't run smack dab into some other planet halfway through the journey. Have fun with that. If you succeed, you should probably be working at NASA. ;)

The "in a solar system" part threw me off, and I thought you were going to have gravitational effects into account (e.g., potential wells and slingshot), which sounds like a really cool problem, but I wouldn't know where to begin. I was a bit disappointed that you don't deal with that at all. sad.png


Yes that would be a cool problem! It also sounds like it would be a "complete" solution to projecting trajectories for celestial travel, taking all bodies, their orbits and gravity effects into account. That however would require sophisticated numerical analysis algorithms and is far beyond what's "practical" for my game! That's a "NASA problem" as taby mentions. :-)

Note that the solution is about planning a trajectory in advance; the actual space travel simulation in the game does take gravitational effects into account. But in the game universe the spaceships have strong thrusters, usually providing between 1 and 10 g. That makes the planets' gravity effect almost negligable in practice. (At the altitude of geostationary satellites for example, the earth's gravity is only about 1/36 g.)

As I mention in the article, the trajectory needs to be recomputed regularly to take the destination's velocity changes into account. This also compensates for any gravitational perturbations the travelling spaceship undergoes, as long as it doesn't directly collide with something!



I didn't go too in-depth with your solution, but if your aim is to simplify it to the point where it's an analytic solution, then you can just use a Hohmann interplanetary transfer orbit, right? Is this not similar to what you did? This paper explains it better than I ever could: http://ocw.mit.edu/c...07F09_Lec17.pdf

And yeah, like alvaro is implying, and as I'm sure you already know, it's a bit more complicated if you want to take a whole lot of bodies into consideration. It's no longer just "a couple of two-body problems stitched together". At best, it would likely mean having to correct your course due to the many minor perturbations that you undergo as you travel from one planet to the other. At worst, it would mean having to postpone launch or taking a highly inoptimal course to ensure that your ship won't run smack dab into some other planet halfway through the journey. Have fun with that. If you succeed, you should probably be working at NASA. ;)


Thanks for the link, it's an interesting article! However it seems to deal with the specific case of orbit transfer and has energy conservation as an aim. I needed to develop a solution for the general case, including being able to chase other ships! ;-)
This book looks like the cutting edge of interplanetary travel, but it involves optimal orbit transfers of minimal energy, so it might not appeal to you:
http://press.princeton.edu/titles/7687.html
http://en.wikipedia.org/wiki/Interplanetary_Transport_Network

If you succeed, you should probably be working at NASA. ;)


They were launching craft 50 years ago and doing the math. The computing power I have in my toaster is probably 1000 times what NASA had then. It'd still be a bit of a project to read up the academic papers and figure out how to approach the problem. But even a completely naive implementation would probably run more than fast enough. Especially if it's an autopilot feature for a proper simulation type game, there's nothing wrong with a "plotting autopilot course" wait dialog of a second or two.
[size=2]Darwinbots - [size=2]Artificial life simulation

[quote name='taby' timestamp='1336596762' post='4938776']
If you succeed, you should probably be working at NASA. ;)


They were launching craft 50 years ago and doing the math. The computing power I have in my toaster is probably 1000 times what NASA had then. It'd still be a bit of a project to read up the academic papers and figure out how to approach the problem. But even a completely naive implementation would probably run more than fast enough. Especially if it's an autopilot feature for a proper simulation type game, there's nothing wrong with a "plotting autopilot course" wait dialog of a second or two.
[/quote]

It was a bit of a joke. I honestly believed him when he said that he already had a working solution, and I honestly didn't bother reading his web site beyond the first two paragraphs, and perhaps that was my problem. My first reply assumed he was doing something simple, like a Hohmann transfer. After alvaro posted a more realistic answer, I realized otherwise. Still, I didn't bother to read the guy's web site, and perhaps that was my problem yet again. Anyway, please consider that it took me more than 2 minutes to write my first reply, and even longer to edit it to reflect the new knowledge.

The key word that I was going on was optimal, and the link to the book that I posted seems to be for fairly new theory (~20 years ago, for JAXA and NASA missions). Perhaps I made a mistake when I assumed -- using my new knowledge -- that what he meant by optimal was optimal fuel usage in a chaotic environment, perhaps not. In any case, plotting a course with optimal fuel usage in a chaotic environment requires a bit more than just naivety, as the 220 page count of that book goes to show. Outside of the bounds of chaos (ie. a couple of two-body problems stitched together, such as the Hohmann transfer) where things are reasonably predictable in the long term, yes, calculating ahead to see where the target will be at later is not exactly rocket surgery. Outside of the bounds of optimality and determinism/chaos, where fuel is infinite and/or enemies are unpredictable even in the short term, yes, AI for chasing and evading is most definitely nothing remotely close to rocket surgery. ;)

Thanks for the input either way. I really did learn a ton of stuff from you, and I rated you up for it (yeah, thanks for those Intel fluid simulation links too). ;)
Is it possible to phrase the problem in a way so that we can find the solution numerically, using only some sort of an error function?

Is it possible to phrase the problem in a way so that we can find the solution numerically, using only some sort of an error function?

Yes. You can solve the problem numerically by value iteration, if you describe it as the optimization of the sum of future values of a utility function, with some exponential discount as you go further into the future. You will also need to quantize the space of states somehow to make this work.

I've thought of trying to write precisely what I just described, but I never found the time.

I don't have a good reference to value iteration. It is described on the second volume of this book, but the book is expensive and not particularly readable, so I won't recommend it. If anyone finds a good online reference, please post it.
The working Java implementation of my solution is now on github:

https://gist.github.com/2708736

http://mmoarch.blogs...ementation.html

Input:
- delta position
- delta velocity
- max force (vessel's max thrust)
- mass (vessel's mass)

Output:
An array of trajectory legs, each containing:
- thrust vector
- time to apply the thrust

This topic is closed to new replies.

Advertisement