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. by F1LT3R by GeneralJ, but quite a bit added on by demobobin.

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.

from this thread :
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 …

Point Gravity

For planar gravity (Blender GE gravity), simply

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

In your initialization script place the following line:


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()

Gravity value: 9.81 or whatever.

G = 9.81

Calc vector from object to gravity-point.

subtract pos from gravity-point

gv = [gravity_point[0] - pos[0], gravity_point[1] - pos[1], gravity_point[2] - pos[2]]

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

d = sqrt((gv[0] * gv[0]) + (gv[1] * gv[1]) + (gv[2] * gv[2]))

calc force of gravity

f = G * mass/(d*d)

apply the force of gravity to the vector to create a

gravity vector

gv = [(f/d)*gv[0],(f/d)*gv[1],(f/d)*gv[2]]

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

fv = c.getActuator(“gvector”)

set the force vector of gravity for this object


Activate it


ya. But what is the gravitational constant again. i forget
[edit] this was meant for after social’s last post

What are you trying to do? First, how can you model a multibody gravitational system with a formula which is only valid for the case of two bodies? Already a three body system behaves nearly chaotic as you can see if you iterate it over time using the formulas of the Poincare conjecture.

Nuff tech talk. Use IPOs.

by the way I agree with 3d-Penguin : if you try to “visualize” (and not “accurately simulate”) some solar system, you have better chance to use IPO, … less problem, better control …

ok i reviewed my physics and i dont believe it can be done cuz you cant get gravitational constant without measurements.