loops don't stop when time step decreased

16 views
Skip to first unread message

Michael Burns-Kaurin

unread,
Mar 13, 2025, 10:21:11 AMMar 13
to glowscri...@googlegroups.com
I have a loop that runs for 2Ms.  Previously it ran fine with a time step of 10 s.  Today, it runs fine at time step 10,000 but will not step for time step 1000 s.  

What is a possible cause?  This happens both in trinket.io and glowscript.org.

Michael Burns-Kaurin

Michael Burns-Kaurin

unread,
Mar 13, 2025, 10:48:59 AMMar 13
to glowscri...@googlegroups.com
Um, now it works, when a minute ago it did not.  Speed test says internet connection is quite fast.

I've had this sort of inconsistency happen before.  Any ideas?

Steve Spicklemire

unread,
Mar 13, 2025, 11:39:35 AMMar 13
to 'Jim D.' via Glowscript Users, Steve Spicklemire
Can you provide a simple example that exhibits this behavior?

thanks,
-steve
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/glowscript-users/CAJ5waeMB7sZVhKERLiNGabMc-T39XdmBGZONstQFmoc0DkL6KQ%40mail.gmail.com.

Michael Burns-Kaurin

unread,
Mar 13, 2025, 1:10:40 PMMar 13
to glowscri...@googlegroups.com, Steve Spicklemire
Web VPython 3.2

# create and initialize variables for
# position and speed of all objects
# at time that asteroid hits Earth
dSun = 1.47e11  
posSun = vec(0,-dSun,0)  
posEarth = vec( 0, 0, 0)  

vE = 2.978e4  
velEarth = vec(-vE, 0, 0)
omegaE = vE / dSun
REarth = 6.378137e6

posAst = vec(0, REarth, 0 )    
vA = 1e4  
velAst = vec(0, -vA, 0)    

dMoon = 3.84e8    
posMoon = vec(  dMoon, 0, 0)  # at collision time
vMoonEarth = 1e3
velMoon = vec( -vE, vMoonEarth, 0 )  # half-moon at collision
omegaM = vMoonEarth / dMoon

# create and initialize variables for masses and G
mAst = 5e9
mEarth = 5.97e24
mSun = 1.99e30
mMoon = 7.35e22

G = 6.67e-11

# set time 0 at collision, run backwards
t = 0
dt = -10

# choose amount of time to run backwards
tf = 2e6

# set up the loop to run time backwards
# use Euler-Cromer method
while t >= -(tf):

# Motion of Earth
#   use function
  posEarth = posSun + dSun*vec(-sin(omegaE*t),
        cos(omegaE*t),0)

# do the same for Moon
  posMoon = posEarth + dMoon*vec(cos(omegaM*t),
      sin(omegaM*t),0)

# asteroid motion using gravity and Euler-Cromer  
  Sun2Ast = posAst - posSun
  gSunAtAst = -G*mSun*norm(Sun2Ast)/(mag(Sun2Ast))**2
  Earth2Ast = posAst - posEarth
  gEarthAtAst = -G*mEarth*norm(Earth2Ast)/(mag(Earth2Ast))**2
  Moon2Ast = posAst - posMoon
  gMoonAtAst = -G*mMoon*norm(Moon2Ast)/(mag(Moon2Ast))**2
  velAst = velAst + (gSunAtAst + gEarthAtAst + gMoonAtAst) * dt
  posAst = posAst + velAst*dt
 
  t = t + dt

# print the result, which will be the initial
#    conditions for asteroid approaching Earth
print("At time", t, "s")
print("Asteroid position", posAst, "m \n and velocity", velAst, "m/s")
print("Earth position", posEarth, "m \n and velocity", velEarth, "m/s")
print("Moon position", posMoon, "m \n and velocity",velMoon,"m/s")

Steve Spicklemire

unread,
Mar 13, 2025, 7:48:42 PMMar 13
to 'Jim D.' via Glowscript Users, Steve Spicklemire
It looks OK to me. Were you using the same browser each time?

Note that Web VPython programs do not *run* in the cloud, they are only stored there. Execution of the program is happening locally in your browser. The speed of the internet connection only affects loading the program, and editing, not execution. It’s possible that different browsers, using different Javascript implementations, will produce different results or behaviors.

Curious!

thanks,
-steve

> On Mar 13, 2025, at 10:48 AM, Michael Burns-Kaurin <burnsk...@gmail.com> wrote:
>

Michael Burns-Kaurin

unread,
Mar 15, 2025, 8:04:09 PMMar 15
to glowscri...@googlegroups.com
Thank you for replying.

Same browser, Chrome.  Happens rarely, but I've wasted lots of time trying to identify infinite loops which did not actually exist.  Quite annoying.

Reply all
Reply to author
Forward
0 new messages