# Gravity and the Solar System...

How would you make a gravity/Solar System type simulation? Using python and accurate formulas, i would think. Ive tried and it kinda works.

I can remember 2 distinct threads quite some time ago, that discussed the issue, and produced a few interesting demos.

These threads are actually very old, so I doubt that the links to the .blends are still up and running, but you can always PM the people who initially posted the links, and ask them to PM one back to you if they can.

Ooo, I wrote a GL frontend for someone who was trying to simulate satellite orbits a while back. The actual calculation is done in a separate module, so you can alter it/use elsewhere, I’ll post a link if you want, it’s all in python using pyOpenGL and GLUT.

I would like to see that.

Also, I’m pretty sure he wants the whole thing to run from a python script inside blender itself. So you might want to do a little formula porting, but it shouldn’t be anything all that difficult.

I modified the following script for taking coordinate of one object as a central point.

It works following the classical physic formula simplified for a 2 object system (it’s not a recursive differential algorythm) : meaning if you take the object “OBSun” as central point and you link your objects OBPlanet.00x to the script, you 'll have orbiting planet around the sun but not interracting each other as it would with real gravity …

Also, I never made a “Solar System” with it, so it could be not realy usable for “stable” Solar system … I use it more like a “gravitational magnet” for behaviors …

tweak it at your ease, I think we can say it’s public domain …

# use one (Z-axis) component of the vectors to calc gravity

import Blender
from Blender import *
from math import *
import GameLogic

scene = GameLogic.getCurrentScene()
center = scene.getObjectList()[“OBCube.001”]
#zero_vector = [0.0,0.0,0.0]
zero_vector = center.getPosition()

# set gravity-point to origin

gravity_point = zero_vector

g = GameLogic

# So that we can use our gravity script below on a frame by frame basis

c = g.getCurrentController()
o = c.getOwner()

mass = 200.0
#mass = o.getMass()
pos = o.getPosition()

G = 9.81

# subtract pos from gravity-point

gv = [gravity_point - pos, gravity_point - pos, gravity_point - pos]

# calc absolute distance ( based on C^2 = A^2 + B^2 )

d = sqrt((gv * gv) + (gv * gv) + (gv * gv))

# calc force of gravity

f = G * mass/(d*d)

# gravity vector

gv = [(f/d)*gv,(f/d)*gv,(f/d)*gv]

# “gvector” is a motion actuator logic brick for this object

fv = c.getActuator(“gvector”)

# set the force vector of gravity for this object

fv.setForce(gv,gv,gv,False)