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
#2
Some code tags, so that code can actually be read, would be helpful.  So would the errors you're getting.
Reply
#3
(Sep-28-2017, 05:37 PM)newfoundme Wrote: from visual import *

Does this even exist anymore?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
Thanks for your help so far guys.

I am a complete noob to python; only thing I know is that it did work, during several years; I haven't used it in the last 6-7 years though.

To me it looks like new Python versions can't run it anymore but as I said older versions in my virtual WinXP PC can't either; they do however state 'completed calculations' but show no animation. Does this help you in any way?
Reply
#5
Your OS shouldn't be a problem (though XP...really?), the program was probably written in Python 2.x. A quick glance at the program shows the majority of calculations are basic math, so even converting to Python 3 should not be that big of an obstacle. Your major problem is the "visual" module, which as I mentioned, doesn't seem to exist anymore. The closest is on GitHub and that dates back several years for any activity.

As to accuracy, a lot has been learned over those intervening years and measurements have become a lot more accurate. So if you are interested in accuracy you might want to start with Brandon Rhodes' jplephem or the community project astropy. Your major problem will be to replace the "visual" module. If you want to do it "on the cheap", you could even use matplotlib.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
(Sep-29-2017, 01:21 PM)sparkz_alot Wrote: Your major problem is the "visual" module, which as I mentioned, doesn't seem to exist anymore. The closest is on GitHub and that dates back several years for any activity.

http://vpython.org/
https://pypi.python.org/pypi/vpython/7.1.3

that is the replacement VPython6, used by the OP. it says
Quote:This is documentation for Classic VPython (VPython 6), which continues to be available but is no longer supported. See vpython.org for information on installing VPython 7 or using GlowScript VPython. Documentation is available at glowscript.org by clicking Help.
Reply
#7
@buran, OK, I took a cursory look at this before and dismissed it. Took another, closer look after your post, at some of the sample programs and see that they do indeed import it as "visual". Good catch.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#8
I just remembered that few months ago there was similar thread regarding visualisation of the planets and the Sun. Never used the package myself
Reply
#9
Ok, thanks to you all for your help.

I was thinking: maybe I can run this module somewhere one more time, take som escreen recordings and done; I don't have the time and certainly not the knowledge to get any deeper into this.

Does anyone know an old school kind of software where I can run this?

Accuracy isn't the biggest issue here; I just want to explain my students why there isn't a solar/lunar eclips every single month. This script did the job.

Thanks.
Reply
#10
(Sep-29-2017, 03:44 PM)newfoundme Wrote: I just want to explain my students why there isn't a solar/lunar eclips every single month

Wouldn't a youtube video suffice?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Google Earth Engine Authorization Asmaalashin 0 384 Feb-06-2024, 08:40 PM
Last Post: Asmaalashin
  VPython - Trying to make orbit simulation totalnoob 2 5,603 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