Absolute Angle Rotation

336 views
Skip to first unread message

Navæéd Ålæm

unread,
May 15, 2014, 2:56:39 PM5/15/14
to vpytho...@googlegroups.com
Is there a way to rotate an object using absolute angle?
Now an object e.g. a ring rotates more by an amount "angle".
I do not know how to reset the rotation angle either.

Thanks.

Kevin Karplus

unread,
May 15, 2014, 4:18:30 PM5/15/14
to vpytho...@googlegroups.com
If you just want to set the orientation of a ring, set its axis attribute.


--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kevin Karplus   kar...@soe.ucsc.edu    http://www.soe.ucsc.edu/~karplus
Professor of Biomolecular Engineering, University of California, Santa Cruz
Program Chair and Undergraduate Director, Bioengineering
Undergraduate Director, Bioinformatics
Editorial Board, Bioinformatics (Oxford University Press)
Senior member, IEEE
life member (LAB, Adventure Cycling, American Youth Hostels)
Effective Cycling Instructor #218-ck (lapsed)
Affiliations for identification only.

Geoff Tovey

unread,
May 15, 2014, 5:45:26 PM5/15/14
to vpytho...@googlegroups.com
You can use the axis attribute of the object if it has one, or failing that, put the object in a frame and set the axis of the frame.   HOWEVER I have been trying that myself and had problems.  See my recent posts.   I found a workaround to the problems when using a frame was to  ensure that its up attribute pointed in the direction of the axle.   I have successfully created an animation of a sewing machine using it.

To use the axis attribute, you have to be aware of how the up attribute works too.  I think I know, but nobody has confirmed that I am right.             

Bruce Sherwood

unread,
May 15, 2014, 11:40:51 PM5/15/14
to vpytho...@googlegroups.com
The bug you've identified with axis and rotate doesn't affect most programs because most of the VPython objects are axially symmetric, which is why the bug hasn't been previously identified as serious. It would be useful for Navæéd Alæm to provide us with a simple test case to explain what problem has been encountered.

Geoff Tovey

unread,
May 16, 2014, 6:22:04 AM5/16/14
to vpytho...@googlegroups.com


In answer to the reply by Bruce Sherwood.  It seems to assume that most programs do not use frames.   Frames are necessary for example where several objects are to be rotated together.  Can that be so rare?  Where frames are used  the contents are less likely to be axially symmetric.   Perhaps the bug has not been reported as serious because people prefer to use a workaround. It seems a shame to ignore it for that reason.                

Naveed Alam

unread,
May 16, 2014, 7:25:43 AM5/16/14
to vpytho...@googlegroups.com
From a user point of view absolute rotation is more important than rotating an object "more" when "angle" is passed.
I would still be happy if there were another function that could accept absolute rotation for "every" primitive.

I don't know if there are performance issues with putting things in a frame just to achieve absolute rotation.

Nevertheless, I will give it a try speculating why has it not been considered from the very first version.


On Fri, May 16, 2014 at 12:22 PM, Geoff Tovey <griggy...@gmail.com> wrote:


In answer to the reply by Bruce Sherwood.  It seems to assume that most programs do not use frames.   Frames are necessary for example where several objects are to be rotated together.  Can that be so rare?  Where frames are used  the contents are less likely to be axially symmetric.   Perhaps the bug has not been reported as serious because people prefer to use a workaround. It seems a shame to ignore it for that reason.                

--
You received this message because you are subscribed to a topic in the Google Groups "VPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vpython-users/z60sWqURwc4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vpython-user...@googlegroups.com.

Naveed Alam

unread,
May 16, 2014, 7:29:28 AM5/16/14
to vpytho...@googlegroups.com
I agree that most of the primitives are axially symmetric but things change when a texture is applied.

Bruce Sherwood

unread,
May 16, 2014, 9:49:27 AM5/16/14
to vpytho...@googlegroups.com
Geoff, the problem isn't being ignored. I've been updating the bug report at GitHub as you've provided more information. You're right, it's an important issue. The only question is when it gets dealt with. I myself am at the moment pretty consumed with finishing the fourth edition of a textbook and associated supplementary materials.

As for "absolute" rotation, I don't know what that would look like in 3D. In 2D, yes, one can specify an absolute angle for positioning something, but in 3D there isn't a meaning to the sentence "Place this object at 35 degrees". Instead, an "absolute rotation" consists of specifying a 3D vector as an axis (and optionally a 3D vector for "up"). Can you be more specific about what other meaning can be given to the term "absolute rotation"?

Geoff Tovey

unread,
May 16, 2014, 9:51:53 AM5/16/14
to vpytho...@googlegroups.com
Nearly all primitives DO have axis and up attributes, so their orientation can be set absolutely (if it worked correctly).
My guess is that objects such as a curve do not have those attributes because they have no intrinsic axes.  By putting them in a frame you are telling VPython which directions you want it to consider the major and minor axes. (It needs those in order to orient the object).   I am a user like you. I have no inside information. 
 
  

Geoff Tovey

unread,
May 16, 2014, 10:05:50 AM5/16/14
to vpytho...@googlegroups.com
Hi Bruce.
"Absolute rotation" is the term used by the OP. I am sure he means setting the absolute orientation.  I agree that in 3D setting an angle is not sufficient; setting "axis" and "up" are satisfactory (although I do not like the terminology) .      

Naveed Alam

unread,
May 16, 2014, 10:33:47 AM5/16/14
to vpytho...@googlegroups.com
By absolute rotation, I mean defining a 3D vector and rotating the object around it.
By default, it can be the same as the axis vector.
It can be modified to pierce through or be at a distance from the object.

Thus, an object should accept the rotation vector and the rotation angle.

After it has been created, it should be the non-rotated position i.e. the zero rotation angle state.

It should be rotated afterwards by the rotation angle around the rotation axis.

For example,
A sphere with rotation vector piercing through it will not lead to visual changes after rotation.
A sphere with rotation vector at a distance from it will lead it to follow a circular trajectory.

I think, it is doable now but looks like a "basic" requirement for every "rotatable" object.

As a beginner, this is what I can add for a while.


On Fri, May 16, 2014 at 4:05 PM, Geoff Tovey <griggy...@gmail.com> wrote:
Hi Bruce.
"Absolute rotation" is the term used by the OP. I am sure he means setting the absolute orientation.  I agree that in 3D setting an angle is not sufficient; setting "axis" and "up" are satisfactory (although I do not like the terminology) .      

--

Naveed Alam

unread,
May 16, 2014, 10:42:33 AM5/16/14
to vpytho...@googlegroups.com
Correction:
A sphere with rotation vector piercing through its center will not lead to visual changes after rotation.

Bruce Sherwood

unread,
May 16, 2014, 11:10:28 AM5/16/14
to vpytho...@googlegroups.com
I guess I still don't understand. The rotate function for objects lets you specify an origin and axis as well as an angle (which I'll call angle1). While it is true that if you execute another of these statements you need to specify an angle2 relative to where the object now is, it's pretty trivial to save the original angle (angle1) and specify a rotation in the form of angle2 = newangle-angle1, so I don't see what the difficulty is. Note that if the second rotation is about a different axis than the first rotation was, an "absolute" meaning to "angle" is impossible.

Naveed Alam

unread,
May 16, 2014, 12:06:57 PM5/16/14
to vpytho...@googlegroups.com
Thanks for the tip about saving the earlier rotation to get the total rotation till a specific point.
Now it makes sense.

What I wanted was to rotate relative to a fixed rotated position (I will call that as position at angle=0).
By keeping track of how much has the object been already rotated, it is doable.

For example,
What I wanted was similar to moving clock hand to 3, 12, 4.
By keeping track of the previous rotations about a fixed axis it can be done.


On Fri, May 16, 2014 at 5:10 PM, Bruce Sherwood <bruce.s...@gmail.com> wrote:
I guess I still don't understand. The rotate function for objects lets you specify an origin and axis as well as an angle (which I'll call angle1). While it is true that if you execute another of these statements you need to specify an angle2 relative to where the object now is, it's pretty trivial to save the original angle (angle1) and specify a rotation in the form of angle2 = newangle-angle1, so I don't see what the difficulty is. Note that if the second rotation is about a different axis than the first rotation was, an "absolute" meaning to "angle" is impossible.

--

Geoff Tovey

unread,
May 16, 2014, 12:50:31 PM5/16/14
to vpytho...@googlegroups.com
I am glad you are satisfied with Bruce Sherwood's tip.  What he is suggesting is that you use a RELATIVE angle of rotation - which is what rotate()  does.  "Relative" means depending on the previous angle.   

You can ignore my replies because they answered your original question which was  "Is there a way to rotate an object using ABSOLUTE angle?".  ("Absolute" means NOT depending on the previous angle).      

The disadvantage of using only the rotate function is that you have keep a running total of the angle - and approximations  accumulate.

By the way, a vector does not have a position, it has only a direction and magnitude.  That is why  rotate() needs you to specify a point on the axle, as well as its direction.  


 

Naveed Alam

unread,
May 16, 2014, 12:59:18 PM5/16/14
to vpytho...@googlegroups.com
What I was asking was actually relative rotation; relative to the starting state.
I agree, absolute is not a proper word here. It was used to differentiate it from "delta angle" to "total angle" from a specific position.

But now you have opened another question:
After 2*pi radians of rotation, the 3D object should be exactly at the same state as I started. Right? Take pi/180 as the step (angle).
Will the approximations accumulate in such kind of rotation if something is continuously rotated around a fixed axis and origin?


--

Geoff Tovey

unread,
May 16, 2014, 1:31:15 PM5/16/14
to vpytho...@googlegroups.com
I do not understand your first paragraph.

Yes, when you use relative rotations approximations accumulate.  rotate() knows only the current angle and the change,
and adds them.  It does not know what the absolute angle of the result should be.   The amount of  error depends on how many times you call rotate().    If you call it a lot, you can avoid the error getting too big by periodically setting the angle to an ABSOLUTE value in the way I described in my previous posts (setting the axis attribute).  You would also have to reset your running total of course.                

Naveed Alam

unread,
May 17, 2014, 2:26:32 PM5/17/14
to vpytho...@googlegroups.com
Now, I see. It looks like the best approach is to set the axis and then the angle every time I want to update the angle. In that case, the angle will always be relative to the axis set state. It may look as a glitch in the graphics though because the rotation is reset every time.

Is there is a way to freeze the 3D display and thaw it after the "rotate" call is finished?



--

Bruce Sherwood

unread,
May 17, 2014, 2:40:01 PM5/17/14
to vpytho...@googlegroups.com
I'm not sure what problem you're trying to solve. If you don't make any change in the objects, there won't be any change in the display. If you want the object to rotate smoothly instead of jumping instantaneously to the new position, carry out the rotation slowly, like this:

theta1 = 0
thetat2 = 1.2
dtheta = 0.01
while theta1 < theta2:
    rotate(100)
    obj.rotate(angle=dtheta, axis=?, origin=?)
    theta1 += dtheta

I encourage you to run many of the example programs that are installed with VPython to see more examples of how to make 3D animations.
Reply all
Reply to author
Forward
0 new messages