# Fast computation of gravitational field level lines

1. Jun 19, 2013

### webaba

1. The problem statement, all variables and given/known data

Dear all,

I have to find a fast way to compute changes in the level lines as the result of sudden changes in the local gravitational fields (2D space). (Caused by the destruction of a planet for example). I could recalculate everything but it takes too much time for the device on which the calculation is deployed. The environment has lots of bodies, so an analytical solution is not to consider.

2. Relevant equations

I compute the level lines, picking a initial point and iterating along the gradient of the potential field.

3. The attempt at a solution

I don't really know where to start, but I'm thinking about a local method that only propagates changes on a limited range around the "explosion". If you want to take a look of the origin of the problem, here is a screenshot of the project, and the link to the related iphone game.

https://itunes.apple.com/us/app/astro-fight/id653286727?ls=1&mt=8

Thank you for you help,

Seb

2. Jun 19, 2013

### Simon Bridge

I'm not clear on what you mean by "level line" ... the gradient of the gravitational potential would be the gravitational field. If you started at some point and followed the gradient, then you'd end up drawing the path that a ball would roll "downhill".

I suspect you are also modelling the destruction of a planet by simply removing it's entire mass-energy ... this does not happen IRL: the mass of a completely vaporized planet is still there.

But hey ho - you can quickly compute the gravitational potential at each point on your plane (superposition principle) and get equipotential lines from a contour plot - graphics packages usually have the ability to make contours as a built-in function. I think you just need to explore the graphics library.

3. Jun 20, 2013

### webaba

Hi,

Sorry I mixed up the terminology. What I called level lines is equipotential lines, i draw them by following the direction orthogonal to the local gravitational force. (Sorry for the confusion)

That works well (check the pictures, the grey lines in the background) but takes some time ! I don't use any graphic library. So I guess my question is : once I have the contour plot, and when a planet explods (I assume that planet fragments just fly off the screen so the mass disappears), I need to redraw part of it without freezing the animation. I tried to only redraw a small part of it (considering that the gravitationnal influence fades away quadratically but then my lines are obviously not continuous anymore....

4. Jun 20, 2013

### Simon Bridge

The grey lines in the pic look like trajectories ... but you have described equipotential lines all right.
Basically you should get the libraries for what you want to program, otherwise you will waste a lot of time reinventing the wheel.

IRL - a vaporized planet is an expanding cloud of matter ... the field fades out according to how the matter expands... the long-range field is basically unchanged.

Switch off the gravity at a spot will create a discontinuity that travels outwards at the speed of light. If you accelerate a field source, you get a wave associated with the field ... creates a jagged bit in the field lines. It may be a sensible way to do it on the scale of the pics ... use a rapidly expanding circle around the original location of the planet.

What you want is just t switch from one set of lines to another ... what are the lines used for?
If it is just for display - to make it look cool - then you can just animate the redrawing to work in with what the machine is capable of.

5. Jun 22, 2013

### webaba

Thanks for the answer man, the expanding circle is a great idea !! And yes it's really only to make it look cool. And i don't think there are libraries for iphone that draw level sets of an arbitrary function... I'll try to use an animation and compute the new lines in a different thread to not freeze the game on the iphone.

6. Jun 22, 2013

### Simon Bridge

Sure - since it is mainly for appearance then the answer is to just eat the calculation delay and animate the transition to the result. It's not a hard-physics simulation after all :)

When you program an app, you have to use a programming language and an SDK of some kind. Trust me - libraries have been written for them. Does Apple provide it's own script language or something - I don't have a lot to do with those guys?

7. Jun 24, 2013

### webaba

Apple provides a huge SDK for Iphone, with graphics library but Contour Lines of a function is a mathematical concept that is not likely to be integrated in any sdk that has no primary scientific purpose... But this is not really a problem, I also recoded the optimization Simulated Annealing to code the AI of the game (and now it beat me all the time ;) you should try ! ;)