Jump to content

  • Log In with Google      Sign In   
  • Create Account

adamdaly

Member Since 24 Jan 2012
Offline Last Active Apr 14 2014 08:37 AM

Posts I've Made

In Topic: (another) planetary gravity question

28 January 2012 - 11:36 AM

Japro thanks for the help. I've implemented an integration method and it seems to be working well. I also wanted the objects to effect each other so i've added the equation f=ma.

import bpy
import mathutils
import math
import decimal
for i in bpy.app.handlers.frame_change_pre:
    bpy.app.handlers.frame_change_pre.remove(i)
star = bpy.data.objects['star']
planet = bpy.data.objects['planet']
planet.location = mathutils.Vector((-8, 12, 0))
star.location = mathutils.Vector((0, 0, 0))
starMass = 600#3.42 * math.pow(10, 23)
planetMass = 1#2.03 * math.pow(10, 30)
dT = 1 / 24
G = -0.01#6.67300 * math.pow(10, -11)
planet_v = mathutils.Vector((0.8, -0.2, 0))
star_v = mathutils.Vector((0, 0 ,0))
def iterator(self):
    frame = str(bpy.data.scenes['Scene'].frame_current) + ' '
    global planet_v
    global star_v
   
    r = (planet.location - star.location)
    planet_f = starMass * ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())
    star_f = planetMass * ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())
   
    planet_v += planet_f * math.pow(dT, 2)
    star_v += star_f * math.pow(dT, 2)
   
    planet.location += planet_v
    star.location += star_v
bpy.app.handlers.frame_change_pre.append(iterator)

To get the f=ma equation to work i've had to use the mass of the other object. It looks right once i run the simulation but is it correct.

adam

In Topic: (another) planetary gravity question

26 January 2012 - 04:57 PM

Right i've created a bit of code to create an orbiting planet. The values are just guess' at the minute, i'm not looking for accuracy yet.

import bpy
import mathutils
import math
for i in bpy.app.handlers.frame_change_pre:
    bpy.app.handlers.frame_change_pre.remove(i)
star = bpy.data.objects['star']
planet = bpy.data.objects['planet']
planet.location = mathutils.Vector((0, 8, 0))
starMass = 40.0
planetMass = 1.0
G = math.pow(6.67300, 11)
def iterator(self):
   
    r = (planet.location - star.location) * 100000
   
    f = ((-G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2) * r.copy().normalized())
   
    tangental_force = r.copy().normalized().cross(mathutils.Vector((0, 0, 1)))
    print(tangental_force / 1000000)
   
    planet.location += f
    planet.location += tangental_force
    #planet.location += r_cross
	   
bpy.app.handlers.frame_change_pre.append(iterator)

I've given the object a force that is constantly tangential to the force of gravity but i don't think that's the correct way to do this. If an asteroid was moving through space it wouldn't be able to apply a force tangential to gravity because it would have nowhere to get this force. Am i right?

adam

In Topic: (another) planetary gravity question

24 January 2012 - 03:50 PM

Ah ok, thanks. It was really wrecking my head trying to figure out where that rotation could come from.

adam

PARTNERS