VISUAL PHYSICS ONLINE

 

DOING PHYSICS WITH MATLAB

 

SECRETS OF COMPUTER GAMES, GRAPHICS AND ANIMATIONS

 

How is it possible to create animations for computer games and graphics?

For realistic motion of objects about a computer screen we need to know the physics related to describing and predicting the motion of objects.

 

A full description of the realistic motion of any object in two-dimensions is given by the three vectors: position vector (displacement), velocity and acceleration.

     Displacement vector                   

     Velocity vector                          

    Acceleration Vector                 

 

 The motion of object of an object of mass m is governed by the net force acting on that object as described by Newton’s Second Law

         

 

Hence, if you know the net force acting on the object, you can predict the acceleration, velocity and displacement at all times. We can perform these calculations assuming the acceleration a is constant during a small time interval. We start with initial values for the velocity and displacement and then calculate the velocity and position of the object at each successive time interval  using

      

        

 

Thus, if we know the position of a collection of objects as a function of time, it is a simple matter to write the code to make an animation of the motion.

 

Consider the movement of five balls confined to a two-dimensional box. When a ball strikes a wall of the box, the ball is reflected. We want to construct a realistic model to animate the motion of all the balls. The Origin is the point (0, 0). The initial position of the five balls and their initial X and Y velocity components are shown in the figure below:

 

Predict Observe Explain (POE) #1

The force acting on each ball is zero except when a ball collides with a wall of the box. Predict the motion of each ball and state the physical principles that you needed to make your predictions. Observe the animated gif.. Compare predictions with the observations and account for any discrepancies.

 

 

 

 

Predict Observe Explain (POE) #2

A gravitational force acts on each ball. Predict the motion of each ball and state the physical principles that you needed to make your predictions. Observe the animated gif. Compare predictions with the observations and account for any discrepancies. Comment on the path of each ball, and their velocities and accelerations.

 

 

 

 

 

Predict Observe Explain (POE) #3

Assume each ball carries the same positive electric charge and the box is placed inside a uniform electric field that is in the +X direction. Predict the motion of each ball and state the physical principles that you needed to make your predictions. Observe the animated gif.. Compare predictions with the observations and account for any discrepancies. Comment on the path of each ball, and their velocities and accelerations.

 

 

 

 

 

 

 

MATLAB

       

Matlab download directory

 

Download and run the script cg001.m. Carefully inspect the script to see how the motion of five balls confined to a two-dimensional box can be realistic modelled.

In Matlab, a [2D] vector can be represented as a complex number. The real part gives the x-component of the vector and the imaginary part the y-component. For example, the displacement as a complex number can be expressed as   

 

 

 

If you have any comments, corrections, suggestions or additions please email

   Ian Cooper

  matlabvisualphysics@gmail.com