In [1]:
from PyGravity import *

In [3]:
# make new particle at position 1,1 with no velocity and mass 10
A = Particle('name',Vector(['1','1']), Vector(['0','0']), 10)
print A
print '\nmoving A\n'
A.move(1)
print A


name: Position: (1,1), Velocity: (0,0), Mass: 10

moving A

name: Position: (1,1), Velocity: (0,0), Mass: 10

In [4]:
#Make a particle with non-zero velocity and move it
B = Particle('B',Vector(['1','1']), Vector(['1','2']), 10)
print B
print '\nmoving b for 1 second\n'
B.move(1)
print B
print '\n moving B for 5 seconds\n'
B.move(5)
print B


B: Position: (1,1), Velocity: (1,2), Mass: 10

moving b for 1 second

B: Position: (2,3), Velocity: (1,2), Mass: 10

 moving B for 5 seconds

B: Position: (7,13), Velocity: (1,2), Mass: 10

In [6]:
#Particle that starts stationary, but is then accelerated
C = Particle('C',Vector(['1','1']), Vector(['0','0']), 10)
print C
print '\naccelerating by 1,1 for 1 second\n'
C.accelerate(Vector(['1','1']), 1)
print C
print '\nmoving a couple times\n'
C.move(3)
print C
print '\nnow comming back to a stop\n'
C.accelerate(Vector(['-1','-1']), 1)
print C
print '\n trying to move again\n'
for i in range(3):
    C.move(1)
print C


C: Position: (1,1), Velocity: (0,0), Mass: 10

accelerating by 1,1 for 1 second

C: Position: (1,1), Velocity: (1,1), Mass: 10

moving a couple times

C: Position: (4,4), Velocity: (1,1), Mass: 10

now comming back to a stop

C: Position: (4,4), Velocity: (0,0), Mass: 10

 trying to move again

C: Position: (4,4), Velocity: (0,0), Mass: 10

In [8]:
#accelerate from rest for 5 seconds
E = Particle('E', Vector(['0','0']), Vector(['0','0']), Vector(['4']))
print E
print '\n accelerating \n'
for i in range(5):
    E.accelerate(Vector(['1','2']),1)
    E.move(1)
    print 'time: ', i
    print E, '\n'
print '\n coming back to a stop\n'
for i in range(5):
    E.accelerate(Vector(['-1','-2']),1)
    E.move(1)
    print 'time: ', i
    print E, '\n'


E: Position: (0,0), Velocity: (0,0), Mass: (4)

 accelerating 

time:  0
E: Position: (1,2), Velocity: (1,2), Mass: (4) 

time:  1
E: Position: (3,6), Velocity: (2,4), Mass: (4) 

time:  2
E: Position: (6,12), Velocity: (3,6), Mass: (4) 

time:  3
E: Position: (10,20), Velocity: (4,8), Mass: (4) 

time:  4
E: Position: (15,30), Velocity: (5,10), Mass: (4) 


 coming back to a stop

time:  0
E: Position: (19,38), Velocity: (4,8), Mass: (4) 

time:  1
E: Position: (22,44), Velocity: (3,6), Mass: (4) 

time:  2
E: Position: (24,48), Velocity: (2,4), Mass: (4) 

time:  3
E: Position: (25,50), Velocity: (1,2), Mass: (4) 

time:  4
E: Position: (25,50), Velocity: (0,0), Mass: (4) 


In [9]:
#plotting the above example
import numpy as np
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()

#4 sets, 2 blue for accelerating, 2 red for decelerating
x = []
y = []
x2 = []
y2 = []
#Space ship
E = Particle(Vector(['1','1']), Vector(['0','0']), 10)
#forward engine
max_forward_engine = Vector(['1','2'])
#reverse engine half as powerful
max_reverse_engine = max_forward_engine*(-.5)

#speeding up
for i in range(10):
    x.append(E.P[0])
    y.append(E.P[1])
    E.accelerate(max_forward_engine,1)
    E.move(1)

#slowing down    
for i in range(20):
    x2.append(E.P[0])
    y2.append(E.P[1])
    E.accelerate(max_reverse_engine,1)
    E.move(1)


plt.scatter(x, y, s=8, c='b', alpha=0.5)
plt.scatter(x2, y2, s=8, c='r', alpha=0.5)
plt.show()


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-a783d173e55d> in <module>()
      2 import numpy as np
      3 import matplotlib.pyplot as plt
----> 4 import mpld3
      5 mpld3.enable_notebook()
      6 

ImportError: No module named mpld3

In [2]:
%matplotlib inline
# plotting 3d
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Time')

#Space ship
E = Particle('space-ship',Vector(['1','1']), Vector(['0','0']), 10)
#forward engine
max_forward_engine = Vector(['1','2'])
#reverse engine half as powerful
max_reverse_engine = max_forward_engine*(-.5)

#speeding up
for i in range(10):
    ax.scatter(float(E.P[0]), float(E.P[1]), i, c='r', marker='o')
    E.accelerate(max_forward_engine,1)
    E.move(1)
    

#slowing down    
for i in range(10,30):
    ax.scatter(float(E.P[0]), float(E.P[1]), i, c='b', marker='o')
    E.accelerate(max_reverse_engine,1)
    E.move(1)

plt.show()



In [ ]: