A strange outcome !

30 views
Skip to first unread message

陳冠榮

unread,
Oct 14, 2021, 3:50:04 AM10/14/21
to Glowscript Users
Hi:
I use the following code to show the Biot-Savart law and the B-field of a long-straight current-carrying wire (thanks to Ruth Chabay).


It works correctly but the last drawn green arrow !
If I set the last rateval to 20, everything is fine (the left part of the picture), but if it is 200, something goes wrong (the right part of the picture).
I cannot figure out what's going on. Please help me.

未命名.jpg
Message has been deleted

Bruce Sherwood

unread,
Oct 14, 2021, 4:10:56 PM10/14/21
to Glowscript Users
Replace line 67, 

Bframe1, Bframe2, dtheta = compound(Barrows[0:80]), compound(Barrows[80:]), 0.5*pi/N

with this:

Bframe1 = compound(Barrows[0:80])
sleep(0.1)
Bframe2 = compound(Barrows[80:])
dtheta = 0.5*pi/N

You have uncovered a previously unknown problem with compound. The Bframe2 statement should of course not be executed before the Bframe1 statement has been fully processed, including freeing up the vertex objects used to create the Bframe1 compound, to be re-used in creating the Bframe2 object, but that's what I think is happening, and somehow sleeping for a short time fixes the problem.

A very minor point is that "display" (the old VPython 5 name) should be replaced with "canvas". 

Bruce

陳冠榮

unread,
Oct 14, 2021, 9:05:11 PM10/14/21
to Glowscript Users
Yes, the problem is solved !
Thanks a lot !

Bruce Sherwood 在 2021年10月15日 星期五上午4:10:56 [UTC+8] 的信中寫道:

Bruce Sherwood

unread,
Oct 16, 2021, 7:44:06 PM10/16/21
to Glowscript Users
After a lot of thrashing around, I made a very simple version of the program which fails:

GlowScript 3.1 VPython
scene.background = color.white
scene.range = .2
    
Barrows = []
r = 0.1
for theta in arange(0, 2*pi, pi/8):
    Barrows.append(arrow(pos=vec(0,-r*sin(theta),r*cos(theta)), color=color.green, axis=vec(0,0,0)))

for B in Barrows:
    B.axis = vec(0,0.02,0)

console.log('before Bframe1')
scene.pause()
Bframe1 = compound(Barrows[0:80])
console.log('after Bframe1')
Bframe1.pos = vec(0.1,0.03,0)

If one comments out the scene.pause() statement, and turns on debugging (shift-ctrl-j), you see the failure. Including scene.pause or sleep(0.1) makes the program work. I currently do not understand what's going on.

Bruce Sherwood

unread,
Oct 16, 2021, 7:50:53 PM10/16/21
to Glowscript Users
A further minor simplification is to replace Barrows[0:80] with Barrows.

Bruce

Bruce Sherwood

unread,
Oct 18, 2021, 7:42:23 PM10/18/21
to Glowscript Users
Your original program now works properly. Thanks for reporting the problem.

Bruce

陳冠榮

unread,
Oct 21, 2021, 8:29:21 AM10/21/21
to glowscri...@googlegroups.com

Thanks again.

 

CKJ

 

Windows 郵件傳送

 

寄件者: Bruce Sherwood
傳送時間: 20211019 7:42
收件者: Glowscript Users
主旨: [glowscript-users] Re: A strange outcome !

 

Your original program now works properly. Thanks for reporting the problem.

 

Bruce

 

--

---
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 on the web visit https://groups.google.com/d/msgid/glowscript-users/de66129b-a264-4a2e-aa05-0f33b9051c13n%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages