Moon earth sun orbit - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Moon earth sun orbit (/thread-5323.html) Pages:
1
2
|
Moon earth sun orbit - newfoundme - Sep-28-2017 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 RE: Moon earth sun orbit - nilamo - Sep-28-2017 Some code tags, so that code can actually be read, would be helpful. So would the errors you're getting. RE: Moon earth sun orbit - sparkz_alot - Sep-28-2017 (Sep-28-2017, 05:37 PM)newfoundme Wrote: from visual import * Does this even exist anymore? RE: Moon earth sun orbit - newfoundme - Sep-29-2017 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? RE: Moon earth sun orbit - sparkz_alot - Sep-29-2017 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. RE: Moon earth sun orbit - buran - Sep-29-2017 (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. RE: Moon earth sun orbit - sparkz_alot - Sep-29-2017 @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. RE: Moon earth sun orbit - buran - Sep-29-2017 I just remembered that few months ago there was similar thread regarding visualisation of the planets and the Sun. Never used the package myself RE: Moon earth sun orbit - newfoundme - Sep-29-2017 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. RE: Moon earth sun orbit - sparkz_alot - Sep-29-2017 (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? |