Circles in VPython

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.

Circles

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.

Syntax

The syntax for the VPython circle is:

shapes.circle(pos, radius, np, thickness)
Syntax for creating a cirlce in VPython

where 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 circle.

  • np: A positive integer that specifies how circular the circumference contour should be. By default, it is set to 6464.

  • 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.

Code execution

To execute the provided example code, we have to follow the steps mentioned below:

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

Example code

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)
Sample code for creating a circle in VPython

Code explanation

  • 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 xx, yy, and zz-axis, respectively. The assigned color is 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 xx, yy, and zz-axis, respectively. The assigned color is yellow.

Continue reading

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved