• HOME
  • YEAR 9
    • Assessment System
    • Inheritance
    • Plants >
      • Kitchen Garden Project
    • Acids and Alkalis
    • Energetic Reactions
    • Energy Resources
    • Mechanics
    • Environmental Science
  • IGCSE
    • Forces and Motion
    • Energy and Energy Resources
    • Solids, Liquids and Gases
    • Waves
    • Astrophysics
    • Electricity
    • Magnetism
    • Nuclear Physics
    • IGCSE revision
  • Physics I
    • Kinematics >
      • Variables and Units
      • Describing Motion
      • Equations of Motion
      • Problem Solving
      • Projectiles
      • Kinematics Animations
    • Dynamics >
      • Forces
      • Static Equilibrium
      • Newton's Laws
      • Friction
      • Advanced Problems
    • Gravitation and Orbits >
      • Circular Motion
      • Vertical Circles
      • Universal Gravitation
      • Orbits
      • Circular Motion Animation
    • Energy >
      • Work
      • Springs
      • PE and KE
      • Conservation of Energy
      • Work-Energy Theorem
    • Linear Momentum >
      • Impulse
      • Conservation of Momentum
      • Types of Collision
      • 2-D Collisions
    • Simple Harmonic Motion >
      • Mass on Spring
      • Pendulums
      • SHM Animations
    • Rotational Mechanics >
      • Torque
      • Rotational Kinematics
      • Rotational Dynamics
      • Angular Momentum
      • Rotational Energy
    • Mechanical Waves >
      • Waves on a String
      • Sound
    • AP-1 Revision
    • AP Physics C (Mechanics)
  • Physics II
    • Fluid Mechanics
    • Thermal Physics
    • Electrostatics
    • Magnetic Fields >
      • EM Induction
    • Interference and Diffraction
    • Optics
    • Modern Physics
    • AP 2 Revision
  • OCEANOGRAPHY
    • The World Ocean >
      • What is Oceanography
      • History
      • Lat and Long
      • Size and Origin
      • Plate Tectonics
    • Seawater >
      • A Salty Sea
      • Measuring Salinity
      • Thermal Properties
      • Density Profiles
      • Drinking Seawater
    • Circulation and Climate >
      • Global Heating
      • Coriolis Effect
      • Surface Currents
      • Vertical Motion
      • Thermohaline Circulation
      • El Nino
      • Carbon Cycle
    • Waves and Tides >
      • Wave Motion
      • Formation of Waves
      • Beaches
      • Tsunamis
      • Tides
    • Observation Systems >
      • Challenges
      • The CTD
      • Moorings
      • Sound Waves
      • Robotics
      • Satellites
    • Weather and Navigation >
      • Weather Systems
      • Weather Forecasting
      • Hurricanes
      • Navigation
      • Life at Sea
    • Oceans and Mankind >
      • Ocean Acidification
      • Pollution
      • Fish Stocks
      • Climate Change
      • Energy Resources
    • Atlantic Explorer Cruise
    • ROVs
  • COLLEGE
    • College Physics I
    • College Physics II
  • CONTACT
Island Physics

CODING FOR PHYSICS

Home >> Coding >> PhysGL Animations

Using PhysGL to Produce Animations

PhysGL is an online editor that can code physics simulations.  It appears to be pretty easy to use.  Open up the website and move the code, graphics and control panes so that you can see them.
Picture
Vectors:  all positions, velocities, forces and accelerations are stated as a vector of <x, y, z> as this can be a 3-D animation.  For the time being we are going to ignore the z-direction so the final value will always be set to zero.  
Picture
ACTIVITY
Enter this kinematics code into the code pane and then press RUN.  You will see a red sphere starting at the left side that accelerates to the right.  Try to change the following - in no particular order:
  • colour of the sphere
  • size of sphere
  • starting position
  • acceleration
  • direction
  • dimension - up and down
  • time intervals
  • 2-D:  start the sphere moving to the right but accelerating downwards
******  TOP TIP - once you have some code working nicely COPY it to a Word or GoogleDoc file ******
(along with a paragraph explaining what it does!)
Adding a trace to show the path followed by the ball
Add another line under the "draw_sphere" command to draw another sphere that is smaller, but add the word 'true' at the end of the bracket.  
Picture
Adding the Vectors
Here we can use some commands to draw the vector arrows and their components.  The default vectors are very large and clumsy, so you need to set the vector scale to at least 0.5 to shrink them down a bit.
The vector is defined by where its tail is and how long it is - in this case set by the magnitude of the velocity.
Picture
Plotting a Graph
We can add graphs using new_graph("x-axis" , "y_axis") before the while animate loop and adding go_graph(t, variable) before the end of the loop.
We can add more axes by using the new_multi_graph("x-axis" , "variable 1" , "variable 2" , etc) and the corresponding go_multi_graph(t, x.x, v.x, a.x) in the loop.  Note that normally graphs cannot plot a vector - so has to be a magnitude or a component.  Use Pythagoras to determine the magnitude of the vector.  In the example below I have included the camera angle and lighting angle.  The camera is located using a single position vector.  The lighting needs two vectors, one to locate the lamp and the other to show the direction it is pointing in.  It is worth playing with these a bit.  If you want to get fancy, add the camera line inside the loop and set the x component of its location to match that of the projectile - camera(<x.x, 70, 250>,<0,0,0>) * this means the camera scrolls around while still focused on the centre of the axes.)
Picture
Using other parameters to control the program
You do not have to use TIME to control the while loops.  You can also use the object's position.  For example to stop the animation when the ball hits the 'ground' you could use 'while x.y >= 0 animate'. 
If there is a change to the motion, say a ball is rolling along a table and drops off, you can use a set of IF THEN commands to change the motion variables.  For example, if the edge of the table is located at x.x = 0, then you could set up a statement inside the loop like:
if x.x <= 0 then
     a = <0,0,0>  *** i.e. not accelerating
end
if x.x > 0 then
     a = <0,-10,0> *** free fall
end

To Draw Stuff 
The easiest way is to use the draw_box function.  draw_box(<one corner> , <opposite corner>, "colour", true). The true is key to the box staying there after the first step in the animation.

To draw a line, use the draw_line function.  draw_line(<start point> , <end point> , "colour", thickness, true)

Picture
Online reference book
  • HOME
  • YEAR 9
    • Assessment System
    • Inheritance
    • Plants >
      • Kitchen Garden Project
    • Acids and Alkalis
    • Energetic Reactions
    • Energy Resources
    • Mechanics
    • Environmental Science
  • IGCSE
    • Forces and Motion
    • Energy and Energy Resources
    • Solids, Liquids and Gases
    • Waves
    • Astrophysics
    • Electricity
    • Magnetism
    • Nuclear Physics
    • IGCSE revision
  • Physics I
    • Kinematics >
      • Variables and Units
      • Describing Motion
      • Equations of Motion
      • Problem Solving
      • Projectiles
      • Kinematics Animations
    • Dynamics >
      • Forces
      • Static Equilibrium
      • Newton's Laws
      • Friction
      • Advanced Problems
    • Gravitation and Orbits >
      • Circular Motion
      • Vertical Circles
      • Universal Gravitation
      • Orbits
      • Circular Motion Animation
    • Energy >
      • Work
      • Springs
      • PE and KE
      • Conservation of Energy
      • Work-Energy Theorem
    • Linear Momentum >
      • Impulse
      • Conservation of Momentum
      • Types of Collision
      • 2-D Collisions
    • Simple Harmonic Motion >
      • Mass on Spring
      • Pendulums
      • SHM Animations
    • Rotational Mechanics >
      • Torque
      • Rotational Kinematics
      • Rotational Dynamics
      • Angular Momentum
      • Rotational Energy
    • Mechanical Waves >
      • Waves on a String
      • Sound
    • AP-1 Revision
    • AP Physics C (Mechanics)
  • Physics II
    • Fluid Mechanics
    • Thermal Physics
    • Electrostatics
    • Magnetic Fields >
      • EM Induction
    • Interference and Diffraction
    • Optics
    • Modern Physics
    • AP 2 Revision
  • OCEANOGRAPHY
    • The World Ocean >
      • What is Oceanography
      • History
      • Lat and Long
      • Size and Origin
      • Plate Tectonics
    • Seawater >
      • A Salty Sea
      • Measuring Salinity
      • Thermal Properties
      • Density Profiles
      • Drinking Seawater
    • Circulation and Climate >
      • Global Heating
      • Coriolis Effect
      • Surface Currents
      • Vertical Motion
      • Thermohaline Circulation
      • El Nino
      • Carbon Cycle
    • Waves and Tides >
      • Wave Motion
      • Formation of Waves
      • Beaches
      • Tsunamis
      • Tides
    • Observation Systems >
      • Challenges
      • The CTD
      • Moorings
      • Sound Waves
      • Robotics
      • Satellites
    • Weather and Navigation >
      • Weather Systems
      • Weather Forecasting
      • Hurricanes
      • Navigation
      • Life at Sea
    • Oceans and Mankind >
      • Ocean Acidification
      • Pollution
      • Fish Stocks
      • Climate Change
      • Energy Resources
    • Atlantic Explorer Cruise
    • ROVs
  • COLLEGE
    • College Physics I
    • College Physics II
  • CONTACT