Member

4

112 Neutral

• Rank
Newbie
1. ## (another) planetary gravity question

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. [CODE] 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) [/CODE] 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
2. ## (another) planetary gravity question

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. [CODE] 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) [/CODE] 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
3. ## (another) planetary gravity question

Ah ok, thanks. It was really wrecking my head trying to figure out where that rotation could come from. adam
4. ## (another) planetary gravity question

Hi, i've looked through a few topics on this but i can't find an answer. I understand - tentatively - how orbital gravity works, i've read and mostly understood the code examples given before. But what i don't understand is how an object such as a satelite when in orbit always retains its orientation relative to the object it is orbiting. Is this artificial or does it happen naturally? And if its natural how would this be incorporated in a script. I realise that i could reorientate based on previous position but if there is a physics explanation then i'd like to incorporate it. adam