Results 1 to 6 of 6
- 12-10-2011, 04:18 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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
- 12-10-2011, 04:23 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-10-2011, 05:10 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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?
- 12-10-2011, 05:21 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Re: I need help with a gravity simulator!
There is not much coding involved; as a bare bones minimum your simulation looks like this:
kind regards,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 }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-10-2011, 05:45 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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
- 12-10-2011, 06:40 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Java Network simulator.
By priya deshpande in forum NetworkingReplies: 4Last Post: 02-18-2012, 03:55 PM -
Building a HSM Simulator
By stunnaz101 in forum Advanced JavaReplies: 0Last Post: 03-23-2010, 10:01 AM -
how to apply gravity in tossing an egg
By santhoshnanjappa in forum New To JavaReplies: 1Last Post: 07-01-2009, 02:26 PM -
simulator program with RS232
By john wooo in forum NetworkingReplies: 7Last Post: 02-11-2009, 02:26 PM -
Traffic simulator
By dirtycash in forum New To JavaReplies: 1Last Post: 03-12-2008, 03:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks