Pages

Friday 18 July 2014

Physics with Python

Today I am going to built a class in Python to simulate a famous kind of motion: projectile motion!

I said a "Class" because while trying to find something to build a class on, I noticed that a projectile could fit perfectly. In fact, a projectile, or any other object which when launched, moves along a curved path under the action of gravity only, has some characteristics: speed, mass, etc...
Displaying all these characteristics through a class can be at the same time both fun and useful for practicing with classes.

The basic assumptions of this kind of motion are the following:
- There is no air friction
- The only significant force which acts on the projectile is gravity

Additional assumptions:
- Projectile starts at y = 0 (from ground)


If you'd like to gather more information on this kind of motion, check out wikipedia:
http://en.wikipedia.org/wiki/Projectile_motion



Here are the results:



Here is a video I made with the instance p and the last method:




It would be fun to implement air friction and then compare the data.

If you find incorrect physics terms please let me know or comment, I might not fully remember my physics classes!! :)

3 comments:

  1. Thanks for the code. My professor has assigned me to plot the projectile projected from height(h) = 5m at an angle of 30(deg) to the horizontal with initial velocity 5m/s. I don't know when I will finish that .. :(

    ReplyDelete
  2. Dear Mic, your code is useful for us, and i thanks to you for make and posted them here.

    but i have trouble when run this code with anaconda(python3.6) even python 3.2, the annot is same
    "
    File "", line 84
    plt.show() = Projectile_motion(0,600,np.pi/3)
    ^
    SyntaxError: can't assign to function call
    "

    may you can help me to tell the problem ?

    ReplyDelete
  3. I was wondering what the "a" meant in your code? it's found first on line 38 stating (a*2).

    Thank you

    ReplyDelete