Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moon earth sun orbit
#1
Dear,

I found this code years ago on the internet; it used to work perfectly fine for what I needed it.
Now I want to run it again in more recent Python versions and it doesnt't work anymore.

I tried older versions of Python and I tried a virtual PC with WinXP installed on it, but nothing works.

Can someone see my problem?

I used to be able to change the value of i in

i = 0 * pi /180 #inclination of the moon's orbit

I contacted Rodney Dunning as well, but I haven't received an answer yet.


Regards,
Bert




from visual import *

"""
Rodney Dunning
Longwood University


An animation of the Moon's orbit about the Earth,
as the later orbits the Sun. The animation makes
clear why we do not have a lunar and solar eclipse
each month.

Moon orbital parameters:

a = 0.3844E+6 km
e = 0.0549
i = 5.145 degrees (relative to the ecliptic)
T = 29.53 days (synodic)

Earth orbital parameters:

a = 149.6E+6 km
e = 0.017
i = 0 (definition)
T = 365.23 days (synodic)

"""

#--------------------------------------------------
# Orbital parameters
#--------------------------------------------------

a = 1 # Earth semi-major axis
e = 0.017 # Earth eccentricity

ma = 0.0025695 # Moon semi-major axis
me = 0.0549 # Moon eccentricity

##i = -5.145 * pi /180 #inclination of the moon's orbit
i = 0 * pi /180 #inclination of the moon's orbit


#--------------------------------------------------
# Scene attributes and functions
#--------------------------------------------------

scene.title = "The Moon's orbit"
scene.x = 0
scene.y = 0
scene.width = 600
scene.height = 600
scene.range = (1.5*a*(1+e),1.5*a*(1+e),1.5*a*(1+e))
scene.autoscale = 0 ##0 means autoscaling is OFF
scene.userzoom = 1 ##0 means user cannot zoom
scene.userspin = 1 ##0 means user cannot spin
scene.lights = [vector(0,0,1)]
scene.ambient = 0.5
scene.label = label(visible=1,
pos=(0,0,0),
xoffset = 0,
yoffset = 0,
text = "The Moon's orbit--not to scale!\n"
"Click to begin.")
##scene.mouse_label = label(visible=1,
## pos=(0,100,0),
## text=("Mouse position"))

def return_mouse_pos(scene):
scene.mouse_label.text = ("mouse\n x: %3.2f y: %3.2f"
%(scene.mouse.pos.x, scene.mouse.pos.y))

def check_for_pause(scene): #checks for pause request
if scene.mouse.clicked:
scene.mouse.getclick()
pause(scene)

def pause(scene):
while 1:
## return_mouse_pos(scene)
if scene.mouse.clicked:
scene.mouse.getclick()
break

#---------------------------------------------------------
# Variables for keeping up with the elasped time
#---------------------------------------------------------

t = 0 # elapsed time
t_max = 20 # the Earth will complete ten full orbits

dt = 0.0005

pi = arccos(-1.0)

fe = 1 # frequency of the Earth's orbit
fm = 12.368 # frequency of the Moon's orbit

#---------------------------------------------------------
# Create the Earth, Moon, and Sun
#---------------------------------------------------------

"""
The sun is always centered in the animation window.

"""



sun = sphere(pos=vector(0,0,0),
radius = 0.1*a,
color = color.yellow)

earth_moon = frame(pos = vector(a,0,0))

print "earth_moon.axis= ",earth_moon.axis

earth = sphere(frame = earth_moon,
pos=vector(0,0,0),
radius = 0.05*a,
color = color.blue,
orbit = curve(color=color.white))

moon = sphere(frame = earth_moon,
pos=vector(200*ma,0,0),
radius= 0.03*a,
color = color.white,
orbit = curve(frame = earth_moon,
color=color.red))

ecliptic_plane = box(pos = sun.pos,
height = 3,
length = 3,
width = 0.001,
color = color.green)


line_of_nodes = box(pos = earth_moon.pos,
height = 0.01,
length = 1.25,
width = 0.01,
color = color.red,
axis = (0,1,0))

#---------------------------------------------------------
# Animation
#---------------------------------------------------------

ready = 0
while not ready:
ready = scene.mouse.getclick()
scene.label.visible = 0
scene.label.text = "Finished."

while t < t_max:
rate(100)
check_for_pause(scene)
t += dt

moon.pos.x = 150*ma*cos(2*pi*fm*t)
moon.pos.y = 150*ma*sin(2*pi*fm*t)

#Rotate the x,y postion of the moon

x = moon.pos.x
y = moon.pos.y

moon.pos.x = x * cos(i)
moon.pos.z = -x * sin(i)

earth_moon.pos.x = a*cos(2*pi*fe*t)
earth_moon.pos.y = a*sin(2*pi*fe*t)

moon.orbit.append(pos=moon.pos)

line_of_nodes.pos = earth_moon.pos

scene.label.visible = 1
Reply


Messages In This Thread
Moon earth sun orbit - by newfoundme - Sep-28-2017, 05:37 PM
RE: Moon earth sun orbit - by nilamo - Sep-28-2017, 06:17 PM
RE: Moon earth sun orbit - by sparkz_alot - Sep-28-2017, 07:59 PM
RE: Moon earth sun orbit - by newfoundme - Sep-29-2017, 04:22 AM
RE: Moon earth sun orbit - by sparkz_alot - Sep-29-2017, 01:21 PM
RE: Moon earth sun orbit - by buran - Sep-29-2017, 02:00 PM
RE: Moon earth sun orbit - by sparkz_alot - Sep-29-2017, 02:12 PM
RE: Moon earth sun orbit - by buran - Sep-29-2017, 02:17 PM
RE: Moon earth sun orbit - by newfoundme - Sep-29-2017, 03:44 PM
RE: Moon earth sun orbit - by sparkz_alot - Sep-29-2017, 08:34 PM
RE: Moon earth sun orbit - by newfoundme - Sep-30-2017, 05:10 AM
RE: Moon earth sun orbit - by sparkz_alot - Sep-30-2017, 01:08 PM
RE: Moon earth sun orbit - by newfoundme - Sep-30-2017, 06:07 PM
RE: Moon earth sun orbit - by Lamarre - Oct-01-2017, 10:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Google Earth Engine Authorization Asmaalashin 0 502 Feb-06-2024, 08:40 PM
Last Post: Asmaalashin
  VPython - Trying to make orbit simulation totalnoob 2 5,718 Sep-13-2017, 03:59 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020