Writing a pendulum simulation - ideas and comments please
#1
Posted 14 October 2005 - 11:47 PM
I want to try to write a "simple" physics demo (with user interaction). I have written some ideas (that need work) and would like some comments and other ideas and pointers on the subject of physics simulations.
The idea is having a pendulum in the center of the screen (2d). Then there will be 2 events, Force Left and Force Right, wich will apply a force in one of those directions (2d movement). The pendulum will also have gravity.
So the user will be alloweed to give the pendulum some movement trough the events wich will set make the pendulum move.
Example:
start ) the pendulum is stopped in it's lowest possition
then ) the user presses the LEFT event key, pendulum will start moving left
end ) the pendulum enters it's left-right-left movement until it stops (stop action - there is no air speed to counter the gravity).
Note 1: keeping it simple, that force that the user applies is not continuos (that is, the user doesn't keep pushing the object, he just gives a little touch that starts the movement).
Note 2: for now forces (other than grvity) while there is movement will be ignored.
The loop could look like
loop
// calculate time
// apply some formula to get the new position of the object -
// taking the current forces in consideration and the time
redrawObject ( x, y );
Then the code would also write a line that represents the string and maybe some liens representing the aceleration vectors.
As for the stop action, I was thinking of reducing the acelleration (not at once) so it stops in a smooth fashion.
Now I will to try to find a way, trough physics rules, to update x and y so the object can be drawn in a "realistic" pendulum motion. Any suggestions?
If you think a pendulum should not go as the first physical simulation writen, please give other ideas that are better to start.
Thanks.
#2
Posted 15 October 2005 - 02:05 AM
corey
#3
Posted 15 October 2005 - 11:32 PM
The question actually is: where can I start gathering information about this? Any Suggested articles? Howto "program physics"?
Thanks.
#4
Posted 16 October 2005 - 10:32 AM
http://www.d6.com/us...er/dynamics.htm
The acceleration will smooth automatically as the gravity will progressively decrease the initial speed.
MJ
#5
Posted 22 October 2005 - 01:36 AM
MJeannig said:
Without friction, the pendulum will never stop, the gravity won't remove energy from the system. The gravity will just convert potential energy to kinetic energy and so on.
#6
Posted 28 October 2005 - 03:15 AM
Faelenor said:
Shouldn't it be possible to add code that adds a negative value to the forces in motion to slow it down gently. By looking at a real pendulum swing it seems to get slower after every swing.
I guess that wouldn't be using any cool physics stuff, but it would be a rough hack if you couldn't get it completed before the deadline :yes:
#7
Posted 28 October 2005 - 07:07 AM
VividHazE said:
A real pendulum will slow down due to frictional forces. It is pretty simple to just multiply it's total energy (or just speed) by some constant factor each timestep. Probably the multiplyer will be some large number still smaller than 1, so maybe 0.99
This is not a physically accurate model technically, but it is close enough that not even a physics student would probably notice :)
#8
Posted 30 October 2005 - 04:45 AM
T = 2(Pi) Radical(L / G) - Only works for under 15 degrees over vertical
T = The time it takes the pendulum to travel through its motion
Pi = 3.14
Radical - can't type a radical..
L = the length of the suspending string
G = 9.8 mps -Gravitational constant
Friction = Friction coefficient for air to metal(-I don't know this off the top of my head google it) * the normal force ( gravity * mass) -this will give you the force of friction working against the pendulum.
V = D / T - D = distance, t = time v = velocity
Acceleration = Change in V / Change in T
Force = Mass * acceleration
The pendulum will stop moving when the net force on the bob is equal to zero. Beginning Force - Air resistance * Time.
-I hope this helps and is some what clear.
#9
Posted 06 April 2006 - 12:14 AM
#10
Posted 07 April 2006 - 12:40 PM
If anyone's interested I wrote an inverted pendulum and double inverted pendulum demo in Delphi which uses Runge Kutta to solve the differentiall equations (it works as a non-inverted pendulums too). The double pendulum is a challenging and fun game.
http://atlas.walagat...one/Balance.zip (includes source)
I used mathematica to convert the 3 coupled second order differential equations of the double pendulum into 6 coupled first order equations so it could be solved using runge kutta.
#11
Posted 09 April 2006 - 01:19 AM
#12
Posted 09 April 2006 - 01:39 AM
#13
Posted 09 April 2006 - 01:49 AM
#14
Posted 09 April 2006 - 02:46 PM
http://drewk.net/pro.../ipendulum.html
Here's the derivations of the double pendulum model written in a control theory paper.
http://www.tf.uni-ki..._isic_zhong.pdf
Here's the mathematica resulting first order equations for the single and double pendulums
http://img.photobuck...tedpendulum.gif
http://img.photobuck...edpendulum2.gif
It took mathematica nearly 1 minute to calculate the double pendulum equations so doing it on paper would be totally impractical.
I'm guessing the Runge-Kutta-Nystrom method solves systems of second order equations. I think I looked into it but couldn't work out how to do it or something. I probably thought it would just be easier to follow the same principles used in that first link.
I should have said how to control it. The force on the cart is proportional to the distance of the cursor from it (horizontally).
You can't get the double pendulum to rotate over the top? I don't really understand. Maybe you just don't have the knack.
BTW, here's my top score on the double
http://img.photobuck.../proof_337s.gif
and here's an advanced trick. Rotating the bottom pole while keeping the upper pole upright and then back into a balance
http://atlas.walagat...e_sim_trick.avi
and here's why I made the program in the first place. I wanted to learn it in real life and practicing on a 2D version made it easier to learn.
http://www.jugglethi...sit.php?lid=168
#15
Posted 09 April 2006 - 07:53 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











