# Efficient Gravitational Field Implementation

I am basically looking for an efficient way to implement gravitational fields.

I have a huge 2D space, with thousands of objects in it. I then need to simulate how these objects are effected by each other's gravity.

I thought it'd be possible to sort the objects into collections, and check every object outside that collection against that collection, and not every individual object inside of it. I soon came to the realization that this simply wasn't possible. The gravitational field of multiple objects cannot represented as one uniform field, calculated with only one mass and distance.

Every object inside the simulation can be considered a sphere. I am fine with approximations, as long as it looks reasonably realistic.

-

You could try using a library that implements the Fast Multipole Method (FMM), which should drastically reduce the amount of memory you need and will decrease the complexity of matrix-vector products from $\mathcal{O}(N^{2})$ to $\mathcal{O}(N)$. It is difficult to implement, but there should be some libraries out there.