Thursday, January 1, 2009

A bouncing ball

To calculate the formula for a bouncing ball, combine the formula for trajectory with a formula to rotate the turtle every time it hits the ground.


TO BOUNCE :A :V :CE
make "sx 0 make "T 0
WHILE [3 = 3] [
MAKE "T :T + 0.01
SETX (:V * :T * COS :A) + :SX
SETY :V * :T * (SIN :A) - 4.91 * :T*:T
IF YCOR < 0 [
MAKE "T 0
MAKE "V :V * :CE
MAKE "SX XCOR SETY 0
IF :V < 1 [STOP]
]
]

END

Where :A is the starting angle, :V is the starting trajectory, and :CE is the coefficient of elasticity. What is that? It's the thing you multiply velocity by to get the new velocity. CE is the reason when you bounce a ball, it doesn't go straight back up to your hand.
I recomend putting :V at a maximum of 100 and :CE about .9 or .5 at the lowest.

No comments: