1. 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     » topic index » view message » categorize

2. Re: Object movement..

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 message » categorize

3. Re: Object movement..

This sounds like a physics problem from way back when...

The only way the other objects can influence the primary object's velocity
is to exert a force on it.  Since you want the force to be inversely
proportional to distance, it should be k/d or even k/d^2 where k is a
constant associated with a specific object.  It may be worthwhile to
associate a mass with each object and use Newton's Law, F=GMm/d^2, to
calculate the force between the two objects.  The gravitational constant G
= 6.67 ? 10^-11 N m^2 kg^-2 would be the number to change to tweak how
strongly objects interact.

Remember though, the force between two objects is dependent on their mass
and distance - not on their velocity.

Once you've calculated the force on the primary object by all other
objects, you can add the force vectors to arrive at a net force.  Now,
since F=MA and you know F and M (the mass of the primary object), you can
rewrite it as A=F/M and figure out A, how much the force accelerates the
object.

Now you can use simple motion equations to calculate the new position and
velocity:

        Pnew=P+Vt+A(t^2)
        Vnew=V+At

If you arbitrarily make your time interval t=1, the multiplies fall right
out.  I'll leave the vectorization of these equations to you...  :)

Hope this helps...

Joe

-----Original Message-----
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.

________________________________________________________
NetZero - We believe in a FREE Internet.  Shouldn't you?
Get your FREE Internet Access and Email at
http://www.netzero.net/download/index.html

new topic     » goto parent     » topic index » view message » categorize

4. Re: Object movement..

Oops!    G = 6.67 * 10^-11 N m^2 kg^-2
Also, you'll need to negate the force vector for a repelling object.

-----Original Message-----
From:   Joe Otto [SMTP:jotto at NETZERO.NET]
Sent:   Tuesday, June 08, 1999 12:47 AM
To:     EUPHORIA at LISTSERV.MUOHIO.EDU
Subject:        Re: Object movement..

This sounds like a physics problem from way back when...

The only way the other objects can influence the primary object's velocity
is to exert a force on it.  Since you want the force to be inversely
proportional to distance, it should be k/d or even k/d^2 where k is a
constant associated with a specific object.  It may be worthwhile to
associate a mass with each object and use Newton's Law, F=GMm/d^2, to
calculate the force between the two objects.  The gravitational constant G
= 6.67 ? 10^-11 N m^2 kg^-2 would be the number to change to tweak how
strongly objects interact.

Remember though, the force between two objects is dependent on their mass
and distance - not on their velocity.

Once you've calculated the force on the primary object by all other
objects, you can add the force vectors to arrive at a net force.  Now,
since F=MA and you know F and M (the mass of the primary object), you can
rewrite it as A=F/M and figure out A, how much the force accelerates the
object.

Now you can use simple motion equations to calculate the new position and
velocity:

        Pnew=P+Vt+A(t^2)
        Vnew=V+At

If you arbitrarily make your time interval t=1, the multiplies fall right
out.  I'll leave the vectorization of these equations to you...  :)

Hope this helps...

Joe

-----Original Message-----
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.

________________________________________________________
NetZero - We believe in a FREE Internet.  Shouldn't you?
Get your FREE Internet Access and Email at
http://www.netzero.net/download/index.html
________________________________________________________
NetZero - We believe in a FREE Internet.  Shouldn't you?
Get your FREE Internet Access and Email at
http://www.netzero.net/download/index.html

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu