From: alessandro <bom...@gm...> - 2009-04-18 15:58:33
|
I want to rotate 90° around the center objects with an animation. I tried this: from visual import * ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) alfa=0 while alfa < radians(90): rate(20) scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) alfa += radians(1) both the sphere & box rotate but they rotate for not only for 90° but serveral time. Where is the error? |
From: Bruce S. <Bru...@nc...> - 2009-04-18 16:40:40
|
The angle used by rotations must be in radians, not degrees. You want ....rotate(angle=alfa*pi/180, .... Bruce Sherwood alessandro wrote: > I want to rotate 90° around the center objects with an animation. I > tried this: > > > from visual import * > ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) > wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) > alfa=0 > while alfa < radians(90): > rate(20) > > scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) > > alfa += radians(1) > > both the sphere & box rotate but they rotate for not only for 90° but > serveral time. Where is the error? > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Lenore H. <lh...@si...> - 2009-04-18 17:47:58
|
VPython doesn't have a radians command to turn degrees into radians? Shouldn't it squawk when he uses an illegal command? Lenore On Apr 18, 2009, at 11:40 , Bruce Sherwood wrote: > The angle used by rotations must be in radians, not degrees. > > You want ....rotate(angle=alfa*pi/180, .... > > Bruce Sherwood > > alessandro wrote: >> I want to rotate 90° around the center objects with an animation. I >> tried this: >> >> >> from visual import * >> ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) >> wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) >> alfa=0 >> while alfa < radians(90): >> rate(20) >> >> scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) >> >> alfa += radians(1) >> >> both the sphere & box rotate but they rotate for not only for 90° but >> serveral time. Where is the error? >> >> ------------------------------------------------------------------------------ >> Stay on top of everything new and different, both inside and >> around Java (TM) technology - register by April 22, and save >> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >> 300 plus technical and hands-on sessions. Register today. >> Use priority code J9JMT32. http://p.sf.net/sfu/p >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Bruce S. <Bru...@nc...> - 2009-04-18 17:48:17
|
What is there to squawk about? 90 radians is a completely legal angle. Bruce Sherwood Lenore Horner wrote: > VPython doesn't have a radians command to turn degrees into radians? > Shouldn't it squawk when he uses an illegal command? > > Lenore > > On Apr 18, 2009, at 11:40 , Bruce Sherwood wrote: > >> The angle used by rotations must be in radians, not degrees. >> >> You want ....rotate(angle=alfa*pi/180, .... >> >> Bruce Sherwood >> >> alessandro wrote: >>> I want to rotate 90° around the center objects with an animation. I >>> tried this: >>> >>> >>> from visual import * >>> ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) >>> wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) >>> alfa=0 >>> while alfa < radians(90): >>> rate(20) >>> >>> scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) >>> >>> alfa += radians(1) >>> >>> both the sphere & box rotate but they rotate for not only for 90° but >>> serveral time. Where is the error? >>> >>> ------------------------------------------------------------------------------ >>> >>> Stay on top of everything new and different, both inside and >>> around Java (TM) technology - register by April 22, and save >>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>> 300 plus technical and hands-on sessions. Register today. >>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> >> ------------------------------------------------------------------------------ >> >> Stay on top of everything new and different, both inside and >> around Java (TM) technology - register by April 22, and save >> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >> 300 plus technical and hands-on sessions. Register today. >> Use priority code J9JMT32. http://p.sf.net/sfu/p >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> > |
From: alessandro <bom...@gm...> - 2009-04-18 17:50:09
|
OK. now it works. But I must write like this: while alfa < 102*pi/180: rate(30) scene.forward = scene.forward.rotate(angle=-alfa*pi/180, axis=(0,1,0)) alfa += pi/180 why 102 instead of 90? With 90 the rotation in not pi/2 but lesser. Bruce Sherwood ha scritto: > The angle used by rotations must be in radians, not degrees. > > You want ....rotate(angle=alfa*pi/180, .... > |
From: Bruce S. <Bru...@nc...> - 2009-04-18 17:55:13
|
Your code fragment must be miscopied, because if alfa is in radians you shouldn't convert radians again in "angle = -alf*pi/180", you should just say "angle = -alf". I'm assuming that you actually had the latter form in your program. Floating point numbers in computers are expressed in an approximate manner, so when you add up 90 terms, each of which is pi/180, the result may actually be less than 90*pi/180, even though the discrepancy is extremely small. A secure way to handle such things is to use integers in the counting: N = 0 while N <= 90: rate(30) scene.forward = scene.forward.rotate(angle=-N*pi/180, axis=(0,1,0)) N+= 1 Bruce Sherwood alessandro wrote: > OK. now it works. But I must write like this: > > > while alfa < 102*pi/180: > rate(30) > scene.forward = scene.forward.rotate(angle=-alfa*pi/180, axis=(0,1,0)) > alfa += pi/180 > > > > why 102 instead of 90? With 90 the rotation in not pi/2 but lesser. > > > > Bruce Sherwood ha scritto: >> The angle used by rotations must be in radians, not degrees. >> >> You want ....rotate(angle=alfa*pi/180, .... >> |
From: Lenore H. <lh...@si...> - 2009-04-18 18:17:09
|
The command "radians" which he was using to turn his degree angles into radian angles. On Apr 18, 2009, at 12:48 , Bruce Sherwood wrote: > What is there to squawk about? 90 radians is a completely legal angle. > > Bruce Sherwood > > Lenore Horner wrote: >> VPython doesn't have a radians command to turn degrees into >> radians? Shouldn't it squawk when he uses an illegal command? >> Lenore >> On Apr 18, 2009, at 11:40 , Bruce Sherwood wrote: >>> The angle used by rotations must be in radians, not degrees. >>> >>> You want ....rotate(angle=alfa*pi/180, .... >>> >>> Bruce Sherwood >>> >>> alessandro wrote: >>>> I want to rotate 90° around the center objects with an >>>> animation. I >>>> tried this: >>>> >>>> >>>> from visual import * >>>> ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) >>>> wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) >>>> alfa=0 >>>> while alfa < radians(90): >>>> rate(20) >>>> >>>> scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) >>>> >>>> alfa += radians(1) >>>> >>>> both the sphere & box rotate but they rotate for not only for 90° >>>> but >>>> serveral time. Where is the error? >>>> >>>> ------------------------------------------------------------------------------ >>>> Stay on top of everything new and different, both inside and >>>> around Java (TM) technology - register by April 22, and save >>>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>>> 300 plus technical and hands-on sessions. Register today. >>>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>>> _______________________________________________ >>>> Visualpython-users mailing list >>>> Vis...@li... >>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> >>> ------------------------------------------------------------------------------ >>> Stay on top of everything new and different, both inside and >>> around Java (TM) technology - register by April 22, and save >>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>> 300 plus technical and hands-on sessions. Register today. >>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>> _______________________________________________ >>> Visualpython-users mailing list >>> Vis...@li... >>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>> |
From: Bruce S. <Bru...@nc...> - 2009-04-18 20:29:46
|
Oh, now I see your point. I did misread the original question. (I didn't even realize that there is a Visual function "radians"! I better get this into the documentation.) But there's nothing wrong with the radians function: it's doing its job of converting radians(90) into pi/2 radians. The problem is that in the first iteration through the loop the rotation is through 0, the next time through 1 degree, the next time through 2 degrees STARTING FROM A DIRECTION THAT HAD ALREADY BEEN ROTATED 1 degree, so the new direction is 3 degrees away from the original direction. The next rotation will be by 3 degrees, for a total rotation of 6 degrees, etc. So my corrections to those programs should have said ....rotate(angle=radians(1), ..... That way one is always rotating by 1 degree each time through the loop. Bruce Sherwood Lenore Horner wrote: > The command "radians" which he was using to turn his degree angles into > radian angles. > > On Apr 18, 2009, at 12:48 , Bruce Sherwood wrote: > >> What is there to squawk about? 90 radians is a completely legal angle. >> >> Bruce Sherwood >> >> Lenore Horner wrote: >>> VPython doesn't have a radians command to turn degrees into radians? >>> Shouldn't it squawk when he uses an illegal command? >>> Lenore >>> On Apr 18, 2009, at 11:40 , Bruce Sherwood wrote: >>>> The angle used by rotations must be in radians, not degrees. >>>> >>>> You want ....rotate(angle=alfa*pi/180, .... >>>> >>>> Bruce Sherwood >>>> >>>> alessandro wrote: >>>>> I want to rotate 90° around the center objects with an animation. I >>>>> tried this: >>>>> >>>>> >>>>> from visual import * >>>>> ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) >>>>> wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) >>>>> alfa=0 >>>>> while alfa < radians(90): >>>>> rate(20) >>>>> >>>>> scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) >>>>> >>>>> alfa += radians(1) >>>>> >>>>> both the sphere & box rotate but they rotate for not only for 90° but >>>>> serveral time. Where is the error? >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> Stay on top of everything new and different, both inside and >>>>> around Java (TM) technology - register by April 22, and save >>>>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>>>> 300 plus technical and hands-on sessions. Register today. >>>>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>>>> _______________________________________________ >>>>> Visualpython-users mailing list >>>>> Vis...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> Stay on top of everything new and different, both inside and >>>> around Java (TM) technology - register by April 22, and save >>>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>>> 300 plus technical and hands-on sessions. Register today. >>>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>>> _______________________________________________ >>>> Visualpython-users mailing list >>>> Vis...@li... >>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>>> > |
From: Bruce S. <Bru...@nc...> - 2009-04-18 21:47:55
|
Footnote: the "radians" and "degrees" functions actually come from the math module, as do functions such as sin, cos, and sqrt. Visual automatically imports the math module and the array module "numpy" (or the older Numeric for Visual 3). But it makes sense to advertise the radians and degrees functions in the Visual documentation dealing with rotations. Of course radians(x) is equivalent o x*pi/180, and degrees(x) is equivalent to x*180/pi. Bruce Sherwood Bruce Sherwood wrote: > Oh, now I see your point. I did misread the original question. (I didn't even > realize that there is a Visual function "radians"! I better get this into the > documentation.) > > But there's nothing wrong with the radians function: it's doing its job of > converting radians(90) into pi/2 radians. The problem is that in the first > iteration through the loop the rotation is through 0, the next time through 1 > degree, the next time through 2 degrees STARTING FROM A DIRECTION THAT HAD > ALREADY BEEN ROTATED 1 degree, so the new direction is 3 degrees away from the > original direction. The next rotation will be by 3 degrees, for a total rotation > of 6 degrees, etc. > > So my corrections to those programs should have said > > ....rotate(angle=radians(1), ..... > > That way one is always rotating by 1 degree each time through the loop. > > Bruce Sherwood > > Lenore Horner wrote: >> The command "radians" which he was using to turn his degree angles into >> radian angles. >> >> On Apr 18, 2009, at 12:48 , Bruce Sherwood wrote: >> >>> What is there to squawk about? 90 radians is a completely legal angle. >>> >>> Bruce Sherwood >>> >>> Lenore Horner wrote: >>>> VPython doesn't have a radians command to turn degrees into radians? >>>> Shouldn't it squawk when he uses an illegal command? >>>> Lenore >>>> On Apr 18, 2009, at 11:40 , Bruce Sherwood wrote: >>>>> The angle used by rotations must be in radians, not degrees. >>>>> >>>>> You want ....rotate(angle=alfa*pi/180, .... >>>>> >>>>> Bruce Sherwood >>>>> >>>>> alessandro wrote: >>>>>> I want to rotate 90° around the center objects with an animation. I >>>>>> tried this: >>>>>> >>>>>> >>>>>> from visual import * >>>>>> ball = sphere(pos=(-5,0,0), radius=0.5, color=color.red) >>>>>> wallR = box(pos=(6,0,0), size=(0.2,4,4), color=color.green) >>>>>> alfa=0 >>>>>> while alfa < radians(90): >>>>>> rate(20) >>>>>> >>>>>> scene.forward = scene.forward.rotate(angle=alfa, axis=(0,1,0)) >>>>>> >>>>>> alfa += radians(1) >>>>>> >>>>>> both the sphere & box rotate but they rotate for not only for 90° but >>>>>> serveral time. Where is the error? >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> >>>>>> Stay on top of everything new and different, both inside and >>>>>> around Java (TM) technology - register by April 22, and save >>>>>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>>>>> 300 plus technical and hands-on sessions. Register today. >>>>>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>>>>> _______________________________________________ >>>>>> Visualpython-users mailing list >>>>>> Vis...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>>>> ------------------------------------------------------------------------------ >>>>> >>>>> Stay on top of everything new and different, both inside and >>>>> around Java (TM) technology - register by April 22, and save >>>>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>>>> 300 plus technical and hands-on sessions. Register today. >>>>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>>>> _______________________________________________ >>>>> Visualpython-users mailing list >>>>> Vis...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/visualpython-users >>>>> > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |