Re: Object movement..

new topic     » goto parent     » topic index » view thread      » older message » newer message

Sounds like you're essentially wanting to add vectors. I'm not an
expert in this area, so there may be a mathematically better way of
doing this, but the following should work as a hack...

First, assume the moving object is M, and the attracting/repelling
objects are R[1], R[2], etc. Each R should have a base strength of
attraction, either zero (for none at all), negative (for repulsion),
or positive (for attraction.)

Now, subtract M's {x,y} coordinates from M's {x,y} velocity, and then
from the {x,y} coordinates of each element of R. This "moves" M to
{0,0}, making things a bit easier to work with.

Next, calculate the physical distance between M and each R, and plug
the distances into the formula you're going to use to scale the
attraction strength. For gravity, you'd want to use an inverse-squares
formula; a linear formula may work for something like a spring. Record
these distances.

For every element in R, take R[x]'s attractive force on M (after the
distance formula is taken into account), and divide it by the
already-calculated distance of R[x] from M. For example, if the force
is 2, and the distance is 5, you should get 2/5, or 0.4. Multiply this
number by R[x]'s new {x,y} coordinates. The final result is the vector
representing the effect R[x] has on M. In order to make it work out,
you'll probably need to set your units of measurement up so that a
force of 1 unit will move M exactly 1 unit distance.

Now, sum R's force vectors, then add the result to M's "moved" velocity,
and there you have it... M's new velocity. Once all of this is done,
add M's original {x,y} coordinates to the final result to "move" M back
back to it's original location.

That should do the trick, although I warn you I didn't test this
before posting. I must say, I'm very curious as to how you're planning
on using all this.... blink

By the way, if you're looking for a specific formula to use, I don't
remember any off the top of my head. You *could* just fudge it, and
fiddle with linear (force = constant * baseforce/distance) or
inverse-square (force = constant * baseforce/(distance * distance))
formulas until you find something that looks right. But if you're
simulating planets and stars, you'll probably save a lot of time just
finding the gravitational equation in a physics textbook and scaling
it to your measurements.

Hope this helps,

Rod Jackson

----------
From:   Liquid-Nitrogen Software[SMTP:nitrogen_069 at hotmail.com]
Sent:   Monday, June 07, 1999 1:55 AM
To:     EUPHORIA at LISTSERV.MUOHIO.EDU
Subject:        Object movement..

Hi, anyone got any ideas on the following:

I have an object with a position {x,y} and velocity {x,y}

i also have other objects with position {x,y} these other objects attract or
repell the first object, how do i caluclate a value to add to the first
objects velocity so that it will be pushed directly away from a repelling
object, or pulled toward an attracting object? The force should be less
further away from the object.

Thanks,
    -Mark.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu