Re: Object movement..
- Posted by Joe Otto <jotto at NETZERO.NET> Jun 08, 1999
- 521 views
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