Rotating in two directions simultaneously

30 views
Skip to first unread message

kblack...@googlemail.com

unread,
Feb 17, 2017, 8:34:59 PM2/17/17
to Glowscript Users
I would like to rotate a compound diagonally but it has a strange path. Do you know what I have done wrong?

Much appreciated


GlowScript 2.4 VPython

#set camera
scene.center=vec(0,20,0)

#create pendulum
rod = cylinder(pos=vec(0,0,0), axis=vec(0,20,0), radius=0.1)
mass = sphere(pos=vec(0,0,0), radius=1.2)
pendulum = compound([rod, mass])


dt = 0.01

while True:

    rate(1/dt)
   
   
    pendulum.rotate( angle=pi/180, axis=vec(0,0,1), origin=vec(0,20,0))
    pendulum.rotate( angle=pi/180, axis=vec(1,0,0), origin=vec(0,20,0) )

Bruce Sherwood

unread,
Feb 17, 2017, 9:14:06 PM2/17/17
to Glowscript Users
Many thanks for this very clear report. Something is seriously wrong with rotating a compound, which unfortunately had not turned up in previous tests. The following kludge works by eliminating the compound:

GlowScript 2.4 VPython
#set camera
scene.center=vec(0,20,0)
#create pendulum
rod = cylinder(pos=vec(0,0,0), axis=vec(0,20,0), radius=0.1)
mass = sphere(pos=vec(0,0,0), radius=1.2)
dt = 0.01
while True:
    rate(1/dt)
    rod.rotate( angle=pi/180, axis=vec(1,0,1), origin=vec(0,20,0) )
    mass.rotate( angle=pi/180, axis=vec(1,0,1), origin=vec(0,20,0) )

Note that you don't need a rotating around the <0,0,1> axis and the <1,0,0> axis, it's sufficient to rotate around the <1,0,1> axis. However, the following does also work:

#set camera
scene.center=vec(0,20,0)
#create pendulum
rod = cylinder(pos=vec(0,0,0), axis=vec(0,20,0), radius=0.1)
mass = sphere(pos=vec(0,0,0), radius=1.2)
dt = 0.01
while True:
    rate(1/dt)
    rod.rotate( angle=pi/180, axis=vec(0,0,1), origin=vec(0,20,0) )
    rod.rotate( angle=pi/180, axis=vec(1,0,0), origin=vec(0,20,0) )
    mass.rotate( angle=pi/180, axis=vec(0,0,1), origin=vec(0,20,0) )
    mass.rotate( angle=pi/180, axis=vec(1,0,0), origin=vec(0,20,0) )

Bruce Sherwood

unread,
Feb 17, 2017, 9:21:32 PM2/17/17
to Glowscript Users
I note that your original program does work with GlowScript versions 2.1, 2.2, and 2.3, but not 2.4. The bug is likely to be associated with the changes to make axis and up always be at right angles to each other, which did involve many changes.


kblack...@googlemail.com

unread,
Feb 18, 2017, 5:09:04 AM2/18/17
to Glowscript Users


On Saturday, 18 February 2017 02:21:32 UTC, Bruce Sherwood wrote:
I note that your original program does work with GlowScript versions 2.1, 2.2, and 2.3, but not 2.4. The bug is likely to be associated with the changes to make axis and up always be at right angles to each other, which did involve many changes.

Thanks that worked perfectly, much appreciated :) . By the way vpython and glowscript is absolutely awesome, amazing work. It makes doing simulations so much easier for me.

kblack...@googlemail.com

unread,
Feb 18, 2017, 7:41:20 AM2/18/17
to Glowscript Users
Using the two methods gives different rates. If you run them both concurrently having them separated seems to run quicker. I set the 1/dt to 1 second and the angle to 360/60*pi/180 and timed them both with a stop watch. the first option seems to be correct but having them separated does not give the same result. Any ideas how I could correct this? The reason I am interested in this is because the angle increase might be different for the x and z axis.

Bruce Sherwood

unread,
Feb 18, 2017, 8:59:23 AM2/18/17
to Glowscript Users
I would expect the two methods to give slightly different results, due to the way that successive rotations work in 3D, but for the results to approach each other as the angle is made smaller. So use the method that gives the desired results.

Bruce Sherwood

unread,
Feb 22, 2017, 9:52:45 PM2/22/17
to Glowscript Users
The bug displayed by the program has been fixed, and the program now works properly in GlowScript VPython. Thanks again for the helpful report.
Reply all
Reply to author
Forward
0 new messages