Motion of a Classical Particle in a Box

June 20, 2017—Bhubanjyoti Bhattacharya
We will make an animated picture of our particle moving around inside a box before collision with the walls.

Make the Particle and Walls

The first step is to create a box and a point with given coordinates within the box.
Make a Raster:
In[]:=
mybox[mx_Integer,ny_Integer]:=Graphics[Raster[ConstantArray[1,{ny,mx}]],FrameTrue,FrameTicksNone];​​mybox[20,10]
Out[]=
Make a Raster with a dot:
In[]:=
mybox[{mx_Integer,ny_Integer},{px_Integer,qy_Integer}]:=Graphics[Raster[ReplacePart[ConstantArray[{1,1,1},{ny,mx}],{qy,px}{1,0,0}]],FrameTrue,FrameTicksNone];​​mybox[{20,10},{5,5}]
Out[]=
Make a simple animation of this before collisions with a wall:
In[]:=
Animate[mybox[{20,10},{u,v}],{u,5,8,1},{v,5,8,1},AnimationRunningFalse]
Out[]=
u
v
mybox[{20,10},{5,5}]
Build the above into a single function:
In[]:=
myAnimatedbox[{mx_Integer,ny_Integer},{x0_Integer,y0_Integer},{vx_Integer,vy_Integer}]:=Animate[mybox[{mx,ny},{u,v}],{u,x0,mx,vx},{v,y0,ny,vy},AnimationRunningFalse];​​myAnimatedbox[{20,10},{5,5},{1,1}]
Out[]=
u
v
mybox[{20,10},{5,5}]
Make the animated box more uniform using a single parameter (time):
In[]:=
mytimeAnimatedbox[{mx_Integer,ny_Integer},{x0_Integer,y0_Integer},{vx_Integer,vy_Integer}]:=Animatemybox[{mx,ny},{x0+vxt,y0+vyt}],t,0,Min
mx-x0
vx
,
ny-y0
vy
,1,AnimationRepetitions1;​​mytimeAnimatedbox[{20,10},{5,5},{1,1}]
Out[]=
t
mybox[{20,10},{10,10}]

What Happens after Collision with a Wall?

Examples of the Final Animated Graphics

Can We Make This Work in Three Dimensions?

Examples of the Final Animated Graphics in 3D

Ideas for Things to Do in the Future (Future Explorations)

AUTHORSHIP INFORMATION
Bhubanjyoti Bhattacharya
6/20/17
​