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.

Trajectory

To make the trajectory a missle would follow (assuming no wind resistance), enter:


to fire :a :v
make "s Distance [0 0] make "t 0 make "h 0 make "l 0 make "q 0
until [ycor<0]>.001 ift [seth (arctan ycor-:l xcor-:h)]
end


Where "a" is the angle it launches at and "v" is the starting velocity. You can shoot your missle from anywhere, as long as it starts on the x-axis. The missle will also point in the direction it is shooting. I used the formulas for trajectory:

velocity times the amount of time which has passed times the sine of the the starter angle will equal the current distance forward. The velocity times the time times the cosine of the starting angle, all subtracted by time squared times gravity (which is 4.905 meters per second) will give you the current height.
I recomend putting :v at a maximum of 100, and :a at whatever you like. Negative angles are angles which point to the left instead of to the right.

Shapes

Shapes with sides of the same length are generally easy to make. In fact, there is one, solve-all formula which you can use. It is:

TO POLYGON :length :sides
REPEAT :sides [FD :length RT 360.0/:sides]
END

Type in polygon, the length you want the sides to be, and then how many sides you want, and boom, you have yourself a square or a triangle or a decagon or chiliagon (1,000 sides) , depending on what you entered.