Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Programming gravity wells ?!

1. ## 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

2. ## 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,

3. ## 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

4. ## Re: Programming gravity wells ?!

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.