Andis BallMenuTM
|
||||
|
Balls movement
Every ball with ball-number
Notice that these are equations for vectors, so for each equation here we have to write two equations in a JavaScript program for the
Notice: If there is no force (always
Simplification: In Andis BallMenu we used the following simplifications: All balls have the same mass ( Elastic impact on window borderWe can compare the coordinates to the window coordinates WindowTop, WindowRight, WindowBottom, and WindowLeft. For example if
then we have to change the direction of the current velocity in x-direction
but leave the velocity in y-direction unchanged. We check accordingly for the other 3 borders.
Tip: Under certain conditions the program runs more stable if we explicitly choose the sign by
Implementation Notice: In Andis BallMenu the coordinates
Elastic impact between balls
First we have to check, if two balls touch each other. We use the Pythagorean theorem to check if two balls i and j with coordinates x and y and a radius r touch each other.
If
Next we form a unit vector pointing in the direction from ball i to ball j
Now the following calculation applies to equal masses
We exchange the normal components of the velocities of the two balls, but keep the tangential components.
Notice: If the masses are not equal, then we have to use the center-of-mass frame, and the calculation gets a little bit more difficult.
Implementation Notice: In Andis BallMenu the balls are also displaced without force so that they never overlap each other:
FrictionSince we have always the same time-step Δt=1, friction is most easily and in a very stable way implemented by multiplying the velocity by a number < 1 at each time step. For example with friction=0.995 we can set
Earth gravityThe force always points "downwards". This is quite easily implemented in our formalism. It means we have a constant force
with
Notice: On earth the value of the
standard acceleration of gravity is g = 9.806
Planetary gravityThis is a force between two balls. We use the law of universal gravitation by Newton which is given by
This can be written in terms of vectors. Again we use the unit vector
Notice: The
Newtonian constant of gravitation is given by
Implementation notice: The displacement routine above at elastic impact increases the total energy of the system, thus breaking conservation of energy. The effect is that balls get faster and faster after elastic impacts under central gravitation. This can be accounted for by an additional energy correction. Therefore we have to subtract the energy gain
The physics-related JavaScript code can be found
in
ballnavigation.js.
Notice about my JavaScript Code: You are free to use the cross-browser specific part of my code in browserspecific.js. If you want to use the JavaScript physics engine ballnavigation.js or the menu-preparation-module menupreparation.js, I kindly ask you to notify me and put a link on your web-page pointing to this web-site (strange.itp.tuwien.ac.at/~ipp). Formula TypeSet Converted by Mathematica
|
|||
|