# Programming gravity wells ?!

• May 10th, 2013, 06:41 AM
DanielJamesCollier
Programming gravity wells ?!
okay so i have been working on a particle system using the light weight java game library but i now want to add gravity wells. by that i mean a way of attracting all the particles to a central point( the well) am not really sure about the maths behind it. thanks :)
• May 10th, 2013, 08:19 AM
Norm
Re: Programming gravity wells ?!
You need to find the algorithms you need before trying to write any code for the project. Once you have the algorithms then if you have any questions about how to write a code for a specific part of the algorithm, post them here,
• May 11th, 2013, 12:41 PM
DanielJamesCollier
Re: Programming gravity wells ?!
how could i get an angle from a particle with an x and y position to the gravity well that has an x and y position and then is it possible to turn that into a velocity ?

--- Update ---

its fine now i have figured it out myself i am using inverse tan to get theta :D
• May 11th, 2013, 05:42 PM
pbrockway2
Re: Programming gravity wells ?!
Quote:

i am using inverse tan to get theta
I'm glad you've got that sorted out. To answer your other question... you can't turn that direction into a velocity. "Real" gravity wells work like this: the distance of the particle to the well (Pythagoras' theorem) gives the acceleration of the particle.

Wikipedia, or a friendly physics student should be able to fill in the details. You are then stuck with the computational problem: what do you do with the acceleration once you've calculated it? If you divide "time" in your universe into small steps you can use the particle's calculated acceleration to update its velocity. (the change in velocity will be proportional to the acceleration - much as you use velocity to update position) This means, of course, that particles may well have instance variables representing velocity as well as position.