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.
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.
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:
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!)
(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.
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.
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.
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.
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.)
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.)
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)
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)