VPthon gears

VPython (Visual Python) is a 3D graphics library that allows us to create and visualize three-dimensional objects on the screen. It is primarily used to visualize the impact of physics equations on the objects' motion.

Note: Read more about VPython.

Gears

Gears are mechanical components with teeth that transmit rotation from one shaft to another, often in machinery.

A gear with 11 teeth
A gear with 11 teeth

Syntax

The syntax for creating a VPython gear is as follows:

shapes.gear(parameters)
Syntax for VPython gear

where the parameters are:

  • pos: A 2D vector [x,y][x,y] that defines the circle's position in the two-dimensional plane.

  • radius: A positive value that sets the radius of the gear.

  • n: A positive integer that sets the number of teeth in a gear.

  • addendum: A positive floating point value (ranging from 00 to 11) that sets the thickness of the teeth's tip. The default value for addendum is 0.080.08 times the radius of the gear.

  • dedendum: A positive floating point value (ranging from 00 to 11) that sets the depth of the gap between the teeth. The default value for dedendum is 0.10.1 times the radius of the gear.

Note: Since VPython is a 3D graphic library, we have to extrude the gear object into 3D space using extrusion() method.

Example code

To execute the code shown below, follow the steps mentioned below:

Once you click the "Run" button, follow the encircled link
1 of 4

The following code compares two gears with different measurements:

from vpython import *

g = shapes.gear(pos=[1,0], radius=1)
gear_1 = extrusion(path=[vector(0,0,0), 
                       vector (0,0,0.01)], 
                       shape=g, 
                       color=color.red)

p = shapes.gear(pos=[-2,0], radius=1, addendum=0.01, dedendum=0.7)
gear_2 = extrusion(path=[vector(0,0,0), 
                       vector (0,0,0.01)], 
                       shape=p, 
                       color=color.yellow)
VPython code implement gear object

Code explanation

  • Line 1: Importing VPython library.

  • Line 3: A simple gear object with radius 11 is created at position [1,0][1,0].

  • Lines 4–7: Extruding the 2D gear in a 3D space. path sets the axis of the circle and vector the gear's thickness along the xx, yy, and zz-axis, respectively. The assigned color is red.

  • Line 9: Another gear object with radius 11 is created at [2,0][-2,0] position. This gear has an addendum value 0.010.01 and dedendum value of 0.70.7.

  • Lines 10–13: Extruding the 2D gear in a 3D space. path sets the axis of the circle and vector the gear's thickness along the xx, yy, and zz-axis, respectively. The assigned color is red.

Continue reading

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved