Jump to content

  • Log In with Google      Sign In   
  • Create Account


(another) planetary gravity question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 adamdaly   Members   -  Reputation: 112

Like
0Likes
Like

Posted 24 January 2012 - 03:28 PM

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

Sponsor:

#2 RulerOfNothing   Members   -  Reputation: 1148

Like
0Likes
Like

Posted 24 January 2012 - 03:33 PM

If you are talking about artificial satellites always facing Earth, that is because they had a little bit of rotation put in by maneuvering thrusters to do so. If you are talking about Earth's moon, then the reason for it always having the same side face Earth is because of tidal effects.

#3 japro   Members   -  Reputation: 887

Like
0Likes
Like

Posted 24 January 2012 - 03:36 PM

In general the orbit and the rotation of objects is independent of each other. The planets also rotate in their orbit around the sun... In case of satellites their orientation towards earth is intentional. Large enough bodies like the moon that are in relatively close orbit are a somewhat special case since tidal forces cause an energy transfer between rotation and orbital velocity. In the case of the Moon that lead to the moons rotation being coupled with it's orbit...

#4 adamdaly   Members   -  Reputation: 112

Like
0Likes
Like

Posted 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

#5 adamdaly   Members   -  Reputation: 112

Like
0Likes
Like

Posted 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

#6 japro   Members   -  Reputation: 887

Like
0Likes
Like

Posted 26 January 2012 - 05:04 PM

You don't have to apply any force other than gravity. you just give the object an initial velocity and then energy conservation keeps it going (there is no atmosphere or friction to dissipate energy) and the gravitational force keeps it on its orbit.

But you need a correct integration scheme. location + force doesn't even make sense physically speaking.
The simplest way to do this is Euler integration:
v += dt*F/m
x += dt*v


#7 adamdaly   Members   -  Reputation: 112

Like
0Likes
Like

Posted 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

#8 h4tt3n   Members   -  Reputation: 963

Like
0Likes
Like

Posted 28 January 2012 - 11:48 AM

gravity_force = ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())
planet_v += ( gravity_force / planetMass) * dT
star_v   += (-gravity_force / starMass )  * dT

this should work. If the planets repel each other, swap the minus sign.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS