VPython - Trying to make orbit simulation - 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: VPython - Trying to make orbit simulation (/thread-4918.html) |
VPython - Trying to make orbit simulation - totalnoob - Sep-13-2017 This is the code I have tried with the aim of one sphere accelerating towards the other as it would by F=G*M*m/r^2. This is one of the first things I've tried in glowscript and I can't find the issue with the code. When I run it the smaller sphere disappears as soon as the time changes so I assume the problem is within the while loop. GlowScript 2.6 VPython M=sphere(pos=vec(0,0,0),radius=10,color=color.yellow) m=sphere(pos=vec(-50,0,0),radius=2.5,color=color.red) ## distances in x and y Rx=M.pos.x-m.pos.x Ry=M.pos.y-m.pos.y ## initial velocities mvx=vec(-5,0,0) mvy=vec(0,10,0) ## accelerations in x and y Ax=1/(mag(Rx)**2) Ay=1/(mag(Ry)**2) ## time and timestep t=0 dt=0.01 ## loop while t<10: rate(2) t=t+dt ## s=x+ut+0.5at^2 m.pos.x=m.pos.x+mvx*dt+0.5*Ax*dt**2 m.pos.y=m.pos.y+mvy*dt+0.5*Ay*dt**2 RE: VPython - Trying to make orbit simulation - PySam - Sep-13-2017 Ok, I got this!! Maybe.... So I did a basic orbital program, 1 sun, and 1 planet that orbits it using proper orbital formulas (I think). Catch is, it's in QBASIC (QB64 specifically)! Haha.. However I'm hoping you'll be able to tell what the concept is and it might help you along, since it's MOSTLY math formulas that do the dirty work here: (you can use the arrow keys to gently 'shift' the sun around and cause chaos!) Quote:CLEAR RE: VPython - Trying to make orbit simulation - micseydel - Sep-13-2017 You might get more help in a more specialized forum - https://groups.google.com/forum/?fromgroups#!forum/glowscript-users |