Python Forum
VPython - Trying to make orbit simulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VPython - Trying to make orbit simulation
#1
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
Reply


Messages In This Thread
VPython - Trying to make orbit simulation - by totalnoob - Sep-13-2017, 12:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I try to import Vpython and I get a "ZeroDivisionError" Jon2222 16 2,903 Jul-26-2023, 07:37 AM
Last Post: Jon2222
  Help with simulation Geeseball 0 2,119 Oct-18-2018, 12:19 PM
Last Post: Geeseball
  Vpython Delay in plotting points SohaibAJ 0 2,115 Jul-30-2018, 08:44 PM
Last Post: SohaibAJ
  Anaconda / Spyder / VPython mwatson87 3 105,528 May-24-2018, 01:51 PM
Last Post: snippsat
  Moon earth sun orbit newfoundme 13 10,820 Oct-01-2017, 10:14 AM
Last Post: Lamarre

Forum Jump:

User Panel Messages

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