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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Programming gravity wells ?!

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    My Mood
    Stressed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Unhappy 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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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,
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    My Mood
    Stressed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default 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. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default 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.

Similar Threads

  1. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  2. [SOLVED] gravity in 2d game
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 23rd, 2012, 07:40 AM
  3. Blackjack programming error (programmer is new to programming)
    By JSingh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 09:13 PM
  4. android programming vs game programming using java
    By vgoel38 in forum Android Development
    Replies: 4
    Last Post: September 8th, 2012, 05:48 PM
  5. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM

Tags for this Thread