Created
January 29, 2014 23:18
-
-
Save rhettallain/8699358 to your computer and use it in GitHub Desktop.
ball bounce with zero energy loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from visual import * | |
g=vector(0,-9.8,0) | |
ball=sphere(pos=(0,1,0), radius=0.05, material=materials.shiny) | |
ball.p=vector(0,0,0) | |
ball.m=0.1 | |
t=0 | |
dt=0.001 | |
floor = box(length=1, width=1, height=0.05, pos=vector(0,0,0), color=color.blue) | |
while True: | |
rate(1000) | |
F=ball.m*g | |
ball.p=ball.p+F*dt | |
ball.pos=ball.pos+ball.p*dt/ball.m | |
if (ball.pos.y+ball.radius)<(floor.pos.y +floor.height/2): | |
ball.p=-ball.p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment