java - Bring Ball To A Stop -


i have following methods in program keep ball continuously bouncing. have tried modifying can't seem ball stop @ bottom of gui. main goal have methods simulate if bouncing real ball.

private void updatedelta() {         final int minimummovement = 5;         final int maxextra = 10;         deltay = minimummovement + (int) (math.random() * maxextra);     }      public void verticalbounce(container container) {          // controls vertical ball motion         if (updown) {             y += deltay;              if (y >= getheight()) {                 updown = false;                 updatedelta();             }         } else {             y += -deltay;             if (y <= 0) {                 updown = true;                 updatedelta();             }         }      } 

update:

ball bounces , stops @ bottom of gui.

public void verticalbounce(container container) {      deltay = deltay - gravity;     y = y + deltay;      if (y > getheight()) {         y = getheight(); // reset location         deltay = (int) (deltay * -0.9); // slows down ball     }  } 

none of code looks correct. need implement equation(s) of rectilinear motion:

http://en.wikipedia.org/wiki/linear_motion

the 1 need s = ut + 0.5 * * t * t, where

s = distance u = initial velocity - regard speed @ hits ground  = acceleration due gravity (you can have pretty arbitrary) t = time 

you reverse sign of a on way up.

to simulate lossy bouncing, reduce u taking factor of energy e out of system:

new_u * new_u = (1 - e)u * u.

(this comes formula kinetic energy of moving body).

i can see question capable of implementing this, won't provide code; physics.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -