Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ball moving in a circle to calculate pi

View circle_ball_pi.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
from visual import *
 
 
r=2.
ball=sphere(pos=(-r,0,0), radius=0.1, color=color.yellow, make_trail=True)
ball.v=vector(0,0.5,0)
start1=sphere(pos=ball.pos, radius=0.05, color=color.red)
t=0
dt=0.001
rt=ball.pos
a=-norm(ball.pos)*mag(ball.v)**2/r
ball.v=ball.v+a*dt
ball.pos=ball.pos+ball.v*dt
t=t+dt
start=vector(-r,0,0)
print(mag(ball.pos-start))
close=mag(ball.pos-start)
print(close)
run=True
while mag(ball.pos-start) >0.99*close:
rate(1000)
a=-norm(ball.pos)*mag(ball.v)**2/r
ball.v=ball.v+a*dt
ball.pos=ball.pos+ball.v*dt
t=t+dt
print(ball.pos)
ds=mag(ball.pos-start1.pos)
print(ds)
print("pi = ")
C=mag(ball.v)*t+ds
print(C/(2*r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.