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.
In VPython, a circle is a closed curve consisting of all points in a plane at a fixed distance (radius) from a central point (center). A circle is a 2D object, which means it lies entirely within a single plane. However, it has to be viewed in a 3D space in VPython.
The syntax for the VPython circle is:
shapes.circle(pos, radius, np, thickness)
where parameters are:
pos
: A 2D vector
radius
: A positive value that sets the radius of the circle.
np
: A positive integer that specifies how circular the circumference contour should be. By default, it is set to
thickness
: A positive floating point value that creates a cavity inside the circle making it a ring.
Note: Since VPython is a 3D graphic library, we have to extrude the circle object into 3D space using
extrusion()
method.
To execute the provided example code, we have to follow the steps mentioned below:
from vpython import * t = shapes.circle(pos=[3,3], radius=3, np=12, thickness=0.6) triangle_1 = extrusion(path=[vector(0,0,0), vector (0,0,0.01)], shape=t, color=color.red) s = shapes.circle(pos=[-2,-1], radius=3, np=34) triangle_2 = extrusion(path=[vector(0,0,0), vector (0,0,0.01)], shape=s, color=color.yellow)
Line 1: Importing VPython library.
Line 3: Creating a circle object with some thickness
and less np
value.
Lines 4–7: Extruding the 2D circle in a 3D space. path
sets the axis of the circle and vector
sets the thickness of the circle along the red
.
Line 10: Creating another circle with np=34
value and no thickness.
Lines 11–14: Extruding the 2D circle in a 3D space. path
sets the axis of the circle and vector
sets the thickness of the circle along the yellow
.
Free Resources