There are many games with a strong emphasis on gravity, and at times even multibody trajectory simulations. However they all seem to be based on spherical geometry (as planets are shaped by gravity), but other shapes should create interesting trajectories. As torus has rotational symmetry its gravity field can be modelled on a 2D crosssection. In this project torus' field is estimated in 3D, projected to 2D and interpolation functions are fitted. The space and timeefficient model could be used in a game to do physics simulation in real time.
Instead of using numerical integration this simpler method was used as I wasn't sure I wouldn't introduce unintended biases when defining the integral over the volume of a torus. The process starts from generating random points within the torus (shown as blue in Figure 1) and outside it (shown in red). For each point outside the torus the gravitational field's force vector is estimated. These are then projected to a 2D crosssection, as shown on the right side of Figure 1. 3D plots of fields are shown in Figure 2. It can be seen to decay towards zero (as expected) at greater distances, but interestingly field goes to zero also at the origin due to the symmetry.
After 3D coordinates have been rotated to the 2D crosssection plane, coordinates are transformed logpolar coordinates. These are shown in Figure 3 (forces along xaxis) and Figure 4 (forces along yaxis). Their cartesiancoordinate counterparts are shown in Figure 5. Shape of these graphs is a bit more apparent if they were seen in a rotating 3D animation. Red dots are correct values and blue values are forecasted by the fitted interpolation model. There is some residual error but it shouldn't be apparent in a gamelike simulation.
The model for the force along axises have the following forms:

F_{x}(α, d; p) ≈ (p_{1}cos(α)+ p_{2}cos(2α)+p_{3}) ·
exp(p_{4} · d^{p6}) + p_{5} d + p_{7}
(1)

F_{y}(α, d; p) ≈ (p_{1}sin(α) + p_{2}sin(3α)) ·
exp(p_{3} · d^{p4} + p_{5}cos(α) + p_{6}cos(2α))
(2)
Values for p at these two functions have the following values:
 F_{x}: [2.1924 0.1201 0.3083 3.6119 5.4967e04 0.2802 0.0073]
 F_{y}: [15.0000 1.4790 0.1457 5.5883 0.2798 0.1553]
This geometry creates a field which have some interesting properties, when compared to the "standard" inverse square law (1/r^{2}) of a spherical planet or a star. Four examples of these are shown in figures 6  10. There seems to exist various classes of nonclosed trajectories as one could say torus has two degrees of "freedom" instead of just the one on spheres. I was happy to discover that there exists orbits which go through the hole in the middle (figures 9 and 10).
Trajectories were estimated by running the differential equation through the standard midpoint method with a suitably small timestep. Most trajectories seem to be fairly chaotic and unstable, so simulating additional bodies such as moons might have noninteresting results. It would be interesting to simulate an atmosphere consisting of ideal gas but I have no prior experience on that even on a spherical body. It would also be worth studying gamemechanics on the FPS genre, and why not also for a platformer?
Related blog posts:








