Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the VPython program shown below. (a) An important skill is being able t

ID: 1406009 • Letter: C

Question

Consider the VPython program shown below. (a) An
important skill is being able to read and understand an existing
program, in order to be able to make useful modifications. Before
running the program, study the program carefully line by line,
then answer the following questions: (1) What is the initial
velocity of the particle? (2) Is the particle initially located in
front of the box or behind it? (3) In which line of code is the
position of the particle updated? (4) What is the value of the time
stept? (5) Will the particle bounce off of the red box, or travel
through it? (b) Now run the program, and see if your answers
were correct. (c) Modify the program to start the particle from
an initial position on the +x axis, to the right of and in front of
the red box. Give the particle a velocity that will make it travel
to the left, along the x axis, passing in front of the box.
from visual import *
box(pos=vector(0,0,-1),
size=(5,5,0.5),
color=color.red,
opacity = 0.4)
particle = sphere(pos=vector(-5,0,-5),
radius=0.3,
color=color.cyan,
make_trail = True)
v = vector(0.5,0,0.5)
delta_t = 0.05
t = 0
while t < 20:
rate(100)
particle.pos = particle.pos + v * delta_t
t = t + delta_t

Chabay, Ruth W.; Sherwood, Bruce A. (2014-12-23). Matter and Interactions, 4th Edition: 1-2 (Page 43). Wiley. Kindle Edition.

Explanation / Answer

1)

This line indicates the initial velocity of the particle as vector with the initial values on each axis x,y,z respectively:

v = vector(0.5,0,0.5)

2)

Box position: box(pos=vector(0,0,-1)

Particle's position: particle = sphere(pos=vector(-5,0,-5)

As we can see the particle is behind the box since it has lower coordinates on the x and z axis

3)

The particle's position updates at this line:

particle.pos = particle.pos + v * delta_t

as you can see it iterates

4)

The time step can be seen on this line:

delta_t = 0.05

is 0.05 s

5)

The initial position of the particle is (-5,0,-5) and radius=0.3, the box is box(pos=vector(0,0,-1) and size=(5,5,0.5) this means that the particle is lower on the z axis it will travel through the box (more specifically under it)

If we want the particle to be to the right of and in front of the red box, the position must be:

particle = sphere(pos=vector(5,5,-1),
radius=0.3

and if we want it to move only to the left, the velocity should be:

v = vector(-0.5,0,0)

This way there's only motion on the x axis