**1**

# Computing space travel

###
#1
Members - Reputation: **198**

Posted 09 May 2012 - 02:12 PM

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.

Also, there are posters here with deep knowledge in physics simulations and it would be very interesting to hear any comments.

Here's the link:

http://mmoarch.blogspot.se/2012/05/computing-space-travel.html

###
#2
Crossbones+ - Reputation: **17784**

Posted 09 May 2012 - 02:50 PM

###
#3
Members - Reputation: **569**

Posted 09 May 2012 - 02:52 PM

How can a 3D-autopilot be implemented in a space opera game?

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. ;)

**Edited by taby, 09 May 2012 - 03:08 PM.**

###
#4
Members - Reputation: **198**

Posted 10 May 2012 - 12:56 AM

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.

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! ;-)

###
#5
Members - Reputation: **569**

Posted 10 May 2012 - 02:07 AM

http://press.princeton.edu/titles/7687.html

http://en.wikipedia.org/wiki/Interplanetary_Transport_Network

###
#6
Members - Reputation: **501**

Posted 11 May 2012 - 04:27 PM

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.

###
#7
Members - Reputation: **569**

Posted 11 May 2012 - 05:46 PM

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.

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). ;)

**Edited by taby, 11 May 2012 - 06:57 PM.**

###
#9
Crossbones+ - Reputation: **17784**

Posted 11 May 2012 - 09:41 PM

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.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?

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.

**Edited by alvaro, 11 May 2012 - 09:44 PM.**

###
#10
Members - Reputation: **198**

Posted 16 May 2012 - 04:29 AM

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