Home

   Overview of Python & VPython

  "Welcome to VPython" tutorial

  Introductory Videos

  Pictures of 3D objects

  

  

  

  VPython 7 web site
  VPython license

Rotating an Object

The following statement will rotate the object named "obj" through an angle (measured in radians) about an axis relative to an origin (it also rotates "up" to remain at right angles to the axis):

obj.rotate(angle=a,
           axis=vec(x,y,z),
           origin=vector(xo,yo,zo))

If the origin is not given, rotation is relative to obj.pos:

# relative to obj.pos:
obj.rotate(angle=a, axis=vector(x,y,z))

If neither the axis nor the origin is specified, rotation is about obj.axis, relative to obj.pos:

# about obj.axis, relative to obj.pos:
obj.rotate(angle=a)

The rotate function applies a transformation to the specified object (sphere, box, etc.). The transformation is a rotation of angle radians, counterclockwise around the line defined by origin and origin+axis. By default, rotations are around the object's own pos and axis.

There are functions for converting between degrees and radians, where there are 2*pi radians in 360 degrees:

radians(360) is equal to 2*pi

degrees(2*pi) is equal to 360

Also see the rotation function available for vectors.