python - Rotate multiple objects at different rates in VPython at the same time -
i practicing coding physics , little stuck on following problem:
"using facilities provided visual package, create animation of solar system shows...sun , planets spheres in appropriate positions , sizes proportional actual sizes...and motion of planets move around sun (by making spheres of planets move)."
a table provided gives radii of 6 innermost planets , sun radii of planets' orbits , period of orbits (approximating circular).
i able first part okay creating arrays values given in table (plus picking constant make planets visible in given scale) , creating array of spheres.
it's motion part hung on. can make planets rotate @ same angular speed @ same time. or can make planets rotate @ different speeds (proportional given periods), goes 1 @ time. there way make animations happen simultaneously in vpython? using vpython 6.11 , python 2.7.13. code below (this version runs them sequentially @ different rates).
from visual import sphere,rate,color math import cos,sin,pi numpy import arange,array,empty #sun s0 = sphere(radius=45e6,pos=[0,0,0],color=color.yellow) #given data r = array([57.9e6,108.2e6,149.6e6,227.9e6,778.5e6,1433.4e6],int) r_plan = array([2440,6052,6371,3386,69173,57316],int) r_plan = r_plan*3000 #adjusting scale period = array([88.0,224.7,365.3,687.0,4331.6,10759.2],float) period = (88.0/period)*.8 #adjusting scale s = empty(6,sphere) #creating planets n in range(6): s[n] = sphere(radius=r_plan[n],pos=[r[n],0]) #prettifying different planets s[0].color = color.magenta s[2].color = color.green s[3].color = color.red s[4].color = color.cyan s[5].color = color.blue #orbital motion n in range(6): m = period[n] theta in arange(0,10*pi,m): rate(30) x = r[n]*cos(theta) y = r[n]*sin(theta) s[n].pos = [x,y]
got it! future readers, last code looks like:
#orbital motion frame in range(1000): n in range(6): theta = period[n] * frame rate(60) x = r[n]*cos(theta) y = r[n]*sin(theta) s[n].pos = [x,y]
something this:
for frame in range(1000): n in range(6): theta = angular_speed[n] * frame ...
Comments
Post a Comment