Here is simple harmonic motion simulation with a spring and a bouncing ball.
Springs are a classic example of harmonic motion, on Wikipedia you can get a grasp of the basics. Among other assumption, in my simulation I’ve assumed an ideal spring and that there is no friction (and therefore the motion will not stop by itself) however, if you like, you can implement friction easily.
Here is the spring simulation
Below is the bouncing ball:
A simpler example of simple harmonic motion with a spring (video):
Hope this was interesting.
Thanks. I'd like to write an animation program that simulates the forces of gravitational attraction between two bodies. First have to learn how to use animate.
ReplyDeleteThanks for reading Marty!
Deletep1 = [position(fun(counter))[0][0],position(fun(counter))[0][1]] can i know what does this line do ? im new to python , i search for plt.gca and i still dun get it
ReplyDeleteThat's some horribly inefficient and convoluted code on my behalf I'm afraid! :D that line simply returns p1 from the position function, you could replace it with p1 = position(fun(counter))[0]. p1 is one of the four points you need to draw a rectangle.
Deleteplt.gca does nothing, it's a comment.
please if possible explain the meaning of
Deletep1 = [position(fun(counter))[0][0],position(fun(counter))[0][1]]
p2 = [position(fun(counter))[1][0],position(fun(counter))[1][1]]
p3 = [position(fun(counter))[2][0],position(fun(counter))[2][1]]
p4 = [position(fun(counter))[3][0],position(fun(counter))[3][1]]
This comment has been removed by the author.
ReplyDeletehey i'm having a problem programing a spring with potential and gravitational energy using the formula (1/2)Kx^2 + (1/6)Yx^3, i know we have to derive that to get force but i can't seem to add it up to create a cubic or more cubic graph. please help!!!!
ReplyDeleteThanks for the lovely simulation codes, man.
ReplyDelete