Results 1 to 6 of 6
  1. #1
    Karly_Kute_X is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default I need help with a gravity simulator!

    Hey Guys,

    I'm trying to write a game-like program which simulates an object falling to the ground, while I can do all the physics and maths behind this I really really
    suck at java at this level :( if any of you guys could help me out with this I'd be forever grateful ^_^

    Thanks,

    Karly Xx

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: I need help with a gravity simulator!

    Per unit of time the velocity v increases with a value a (due to gravity) so at a time t+1 the velocity becomes v+a; the distance to the ground decreases by a distancve v, so the distance at t+1 becomes d-v. Repeat until d <= 0 and start your simulation at a height d0 and an initial velocity v0

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Karly_Kute_X is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: I need help with a gravity simulator!

    That's cool I just have no idea how to code that :( are there any examples of such a code here or if not do you know where I can find code examples?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: I need help with a gravity simulator!

    Quote Originally Posted by Karly_Kute_X View Post
    That's cool I just have no idea how to code that :( are there any examples of such a code here or if not do you know where I can find code examples?
    There is not much coding involved; as a bare bones minimum your simulation looks like this:

    Java Code:
    double d= d0; // initial height
    double v= v0; // initial velocity
    
    while (d > 0) { // while no impact yet
       v+= a; // adjust velocity
       d-= v; // adjust height
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Karly_Kute_X is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: I need help with a gravity simulator!

    Ahh that makes more sense - although I need to represent the initial and final positions as vectors - I understand I need to use arrays to do this - I just don't know how to make the program do this, also I need to allow the user to alter the mass of whats being dropped and the mass of the planet :(:(

    Grrr confuzzled! :\

    K x

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: I need help with a gravity simulator!

    Vectors only make sense in the calculations if there is a horizontal component in the speed (vx, vy), otherwise the first component of these vectors will always be zero. The force applied to the falling body only infuences the vertical speed component. The mass of the planet only influences component 'a' in the calculations (i.e. the gravity factor)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Java Network simulator.
    By priya deshpande in forum Networking
    Replies: 4
    Last Post: 02-18-2012, 03:55 PM
  2. Building a HSM Simulator
    By stunnaz101 in forum Advanced Java
    Replies: 0
    Last Post: 03-23-2010, 10:01 AM
  3. how to apply gravity in tossing an egg
    By santhoshnanjappa in forum New To Java
    Replies: 1
    Last Post: 07-01-2009, 02:26 PM
  4. simulator program with RS232
    By john wooo in forum Networking
    Replies: 7
    Last Post: 02-11-2009, 02:26 PM
  5. Traffic simulator
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 03-12-2008, 03:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •