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 are mechanical components with teeth that transmit rotation from one shaft to another, often in machinery.
The syntax for creating a VPython gear is as follows:
shapes.gear(parameters)
where the parameters are:
pos: A 2D vector
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 addendum is
dedendum: A positive floating point value (ranging from dedendum is
Note: Since VPython is a 3D graphic library, we have to extrude the gear object into 3D space using
extrusion()method.
To execute the code shown below, follow the steps mentioned below:
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)Line 1: Importing VPython library.
Line 3: A simple gear object with radius
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 red.
Line 9: Another gear object with radius addendum value
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 red.
Free Resources