//[astronomy](../../../index.md)/[io.github.cosinekitty.astronomy](../index.md)/[GravitySimulator](index.md)
# GravitySimulator
class [GravitySimulator](index.md)
A simulation of zero or more small bodies moving through the Solar System.
This class calculates the movement of arbitrary small bodies, such as asteroids or comets, that move through the Solar System. It does so by calculating the gravitational forces on the bodies from the Sun and planets. The user of this class supplies a list of initial positions and velocities for the small bodies. Then the class can update the positions and velocities over small time steps. The gravity simulator also provides access to the positions and velocities of the Sun and planets used in the simulation.
## Constructors
| | |
|---|---|
| [GravitySimulator](-gravity-simulator.md)
fun [GravitySimulator](-gravity-simulator.md)(originBody: [Body](../-body/index.md), time: [Time](../-time/index.md), bodyStates: [List](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)<[StateVector](../-state-vector/index.md)>)
Creates a gravity simulation object. |
## Functions
| Name | Summary |
|---|---|
| [solarSystemBodyState](solar-system-body-state.md)
fun [solarSystemBodyState](solar-system-body-state.md)(body: [Body](../-body/index.md)): [StateVector](../-state-vector/index.md)
Get the position and velocity of a Solar System body included in the simulation. |
| [swap](swap.md)
fun [swap](swap.md)()
Exchange the current time step with the previous time step. |
| [time](time.md)
fun [time](time.md)(): [Time](../-time/index.md)
Returns the time of the current simulation step. |
| [update](update.md)
fun [update](update.md)(time: [Time](../-time/index.md)): [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)<[StateVector](../-state-vector/index.md)>
Advances the gravity simulation by a small time step. |
## Properties
| Name | Summary |
|---|---|
| [originBody](origin-body.md)
val [originBody](origin-body.md): [Body](../-body/index.md)
The origin of the reference frame. See constructor for more info. |