www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/03:10:51

Date: Sun, 2 Feb 1997 02:54:50 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Pyro Technic <invid AT dmv DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Bouncing
In-Reply-To: <32F44C1B.2E7B@dmv.com>
Message-ID: <Pine.GSO.3.95.970202021725.24151A-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

On Sun, 2 Feb 1997, Pyro Technic wrote:

> How would I get a ball to bounce realisticly. The constant velocity and
> four directions I have noe just just. Do I need an algorithim,
> logirithm, or some other thing a newbie like myself has never heard of.
> Thanks a lot.
> 
> 	Pyro
> 

The simplest way would be to use classical physics.  Consider the
following two formulas relating velocity, acceleration, distance, and
time:
	2*a*d = v_final^2 - v_initial^2
	d = v_inital * t + 0.5 * a * t^2
The maximum height can be determined by using the first equation and
setting v_final to equal zero.  And for any given time the position can be
determined from the second equation.  You'll have to play around with an
appropriate distance scaling factor for the monitor and an acceleration
that produces the desired effect (not necessarily -9.8 m/s^2).  There is
also something known as the coefficient of restitution, which is basically
the ratio of the maximum height reached during two consecutive bounces.
Thus, a substance with a coefficient of restitution of 1 (impossible, of
course) would bounce forever, while a coefficient of restitution of zero
implies that it does not bounce at all.  Again, you need to play around
with values so that it looks reasonable.
	Now, to actually use these calculations, it seems simplest to me
to use constant time.  If your program simply uses uclock() or another
function to keep track of time, then it can use that time during each
iteration to calculate the position and velocity of the ball.  When the
ball hits the wall or ground, then calculate the final velocity at that
moment and this will give you a start for the inital velocity, which will
equal:
	v_initial = -v_final * coefficient_of_restitution;
You're now ready to plug this into your formulas to calculate your updated
position.  I'm not much of a graphics programmer, but this should give you
a start for one method of doing what you ask.


						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019