01-C Motion with Constant Velocity

Create an Object and Make it Move

Because of VPython’s default autoscaling behavior, it is easier to interpret the motion of an object if there is at least one other, stationary object in the display. The following program fragment creates an image of the Diddle Arena floor using a box object named floor that will create this reference background.

# Use a box object to model the Diddle Arena floor.  
#
# The size of regulation basketball floor is 94 ft x 50 ft
#   https://https://www.recunlimited.com/blog/diagrams-basketball-courts/
#
# The floor at Diddle Arena has borders on the sides and ends that we will 
# approximate as 3 ft along the long sides and 4 ft on the end courts.  
# Adding these extra borders makes
# for a dimension of 102 ft x 56 ft.
#
# We will place the origin at the enter of the court and will use our standard
# coordinate system with x and z horizontal and y vertical.  The x-axis
# will be along the long dimension and the z-axis will be along midcourt.

floor = box(pos=vector(0,-0.01,0), length=102, width=56, height=0.01, texture="https://i.imgur.com/ZH6eZFl.png")

# Rotate the camera so that we are looking down on the floor from up above.
# In this view the origin will be at center court, the +x axis will be to the
# right, and the + z aixs will be along the center court line toward the top of the canvas display.

scene.forward=vector(0,-1,0)
scene.up =vector(0, 0, -1)
scene.camera.pos = vector(0, 25,0)

# Adjust the scene size and background color to make the animation more visible
scene.width = 1400
scene.height = 800
scene.background = vector(0.6, 0.6, 0.6)

Before the Loop

  • Read the comments in the code above to understand the coordinate system used.
  • Draw an object of your choice at the top-right corner of the playing area of the court.  Make it large enough that it is easily visible.  Be sure to give your object a name so you can assign it attributes.
  • Give your object an attribute of .v to specify its initial velocity.  Make this velocity have magnitude of 10 ft/s and direction such that it is aimed at the lower-left corner of the floor.

Inside the Loop

  • Create a loop that will run until your object gets to the left edge of the court.
  • Use the position update formula to make the object move with the constant velocity specified above across the floor.