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.
Syntax
The syntax for creating a VPython gear is as follows:
shapes.gear(parameters)
where the parameters are:
pos: A 2D vectorthat 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 fromto ) that sets the thickness of the teeth's tip. The default value for addendumistimes the radius of the gear. dedendum: A positive floating point value (ranging fromto ) that sets the depth of the gap between the teeth. The default value for dedendumistimes 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:
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)Code explanation
Line 1: Importing VPython library.
Line 3: A simple gear object with
radiusis created at position . Lines 4–7: Extruding the 2D gear in a 3D space.
pathsets the axis of the circle andvectorthe gear's thickness along the, , and -axis, respectively. The assigned color is red.Line 9: Another gear object with
radiusis created at position. This gear has an addendumvalueand dedendum value of . Lines 10–13: Extruding the 2D gear in a 3D space.
pathsets the axis of the circle andvectorthe gear's thickness along the, , and -axis, respectively. The assigned color is red.
Continue reading
Free Resources