[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1833.0. "Inertia Algorithm" by WRKSYS::ARUMUGHAM () Tue Jan 11 1994 13:47

    A friend of mine is looking for an algorithm to calculate inertia. Does
    anybody have one?
T.RTitleUserPersonal
Name
DateLines
1833.1STAR::ABBASIand the computer said mate in 23!Tue Jan 11 1994 17:154
    is this different from calculating the mass of an object ?
    
    \nasser
          
1833.2WRKSYS::ARUMUGHAMTue Jan 11 1994 20:263
    Well, this person wants a marble to move when you move the mouse in a
    program, but the marble needs to realistically accelerate and
    decelerate with the mouse movement... 
1833.33D::ROTHGeometry is the real life!Tue Jan 11 1994 21:1333
>    Well, this person wants a marble to move when you move the mouse in a
>    program, but the marble needs to realistically accelerate and
>    decelerate with the mouse movement... 

   If you specify the force exerted on the marble, its's a straightforward
   initial value problem and you can use any of a number of ordinary
   differential equation solvers.

   You'll need specify the state of the marble - it's x and y position
   and x and y components of velocity - as initial conditions.  Then
   Newton's second law, force = mass * acceleration defines the
   path of the marble.

   Actually, even the simplest first order solver will probably suffice.

   Try updating your position and velocity with

   loop:

	Px = Px + Vx * dt
	Py = Py + Vy * dt

	Vx = Vx + (Fx / Mass) * dt
	Vy = Vy + (Fy / Mass) * dt

	goto loop

   More accurate solvers are expansions on this trivial idea.

   You may want to add friction, which is another component of
   force proportional to velocity, to the model above.

   - Jim
1833.4Attaching it to the mouseWIBBIN::NOYCEDEC 21064-200DX5 : 130 SPECint @ $36KWed Jan 12 1994 14:4715
You might want to model the "current mouse position" as being attached to
the marble via a spring (or rubber band).  The force exerted by a spring
stretched to length L is proportional to L.

So, if (Px,Py) represents the marble's position, and (Mx,My) represents the
mouse position, then L=SQRT( (Mx-Px)**2 + (My-Py)**2 ) is the spring's length,
and
	Fx = K*L*(Mx-Px)/L
	Fy = K*L*(My-Py)/L
are the x- and y- components of the spring's force, for some "spring constant"
K.  (Note that the L's cancel out, so no need to compute them.)  Experiment
with different values for K to get behavior you like.

PS- you'll want to add some friction, or you'll get oscillation that's very
hard to control!
1833.5if nobody has a canned algorithm handy...ICARUS::NEILSENWally Neilsen-SteinhardtWed Jan 12 1994 15:0829
.2>    Well, this person wants a marble to move when you move the mouse in a
>    program, but the marble needs to realistically accelerate and
>    decelerate with the mouse movement... 

I will temporarily stifle my impulse to ask why.  I suspect this is one of those
user requirements which has a different actual requirement behind it.

I can see several ways to make the marble move "realistically."

The simplest way would be to let the mouse move an acceleration cursor on an
acceleration grid, and then plug the acceleration into equations like those
in reply 3.  Problem is that this is contrary to the usual mouse-cursor 
metaphor.  As I remember, early computer games used this method, and it was 
quite frustrating.  To stop the "marble," you had to apply just the right 
deceleration, and then hold the acceleration cursor at the zero point of 
its grid.

Another way would be to allow the mouse to control a cursor in the space of the
marble.  This cursor, which would be controlled by the mouse in the usual way, 
would be tied to the marble by an ideal spring.  In other words, the force
and acceleration on the marble would always be proportional to the distance
between the marble and the cursor.  Again the equations in reply 3 could be
used to model the marble's position.  If you did just this, you would find that
the marble would never settle down once it started moving.  It would just
oscillate around the current position of the cursor.  As reply 3 suggests,
you might want to add some kind of frictional force, perhaps decreasing velocity
as the marble moves away from the cursor.

By now, this is really a physics problem.
1833.6(-:AUSSIE::GARSONHotel Garson: No VacanciesMon Jan 24 1994 04:144
    re .0
    
    Calculating *moment of* inertia is more interesting mathematically. Is
    it required that the rolling of the marble be accounted for?
1833.7FORTY2::PALKAMon Jan 24 1994 15:138
    re .6
    
    Especially if you want to allow for friction between the marble and the
    surface it moves on (I.e. can it roll with slipping ?), and rolling
    resistance (so that it eventually stops when you stop moving the
    mouse).
    
    Andrew