Page 2 of 2

Re: So I tried to see if I could do something like GSim in J

Posted: Sat Jul 11, 2015 6:07 pm
by wtg62
testtubegames wrote: For merging, you just need to worry about (a) Conservation of Mass, and (b) Conservation of Momentum (mass*velocity). So make sure the new planet has the sum of the old masses (which I imagine you're already doing). And then sum up the momenta before, and use that to figure out the momentum (and thus velocity) afterwards.
For some reason this didn't work, and that was the first thing I tried... hmm... I'll figure it out.
A Random Player wrote: True! You just need to remember that cos = x/d, and sin = y/d (soh-cah-toa anyone?), and replace it. So in general,
vx += x / d * f(d)
vy += y / d * f(d) Also Andy has a tweet's characters more than twice my post count - 828 vs 484. Also the digits are all powers of 2, and mine is 22^2!
DOH! Haha, neat-o. I'll definitely work on this.

Re: So I tried to see if I could do something like GSim in J

Posted: Sat Jul 11, 2015 7:14 pm
by A Random Player
wtg62 wrote:
testtubegames wrote: For merging, you just need to worry about (a) Conservation of Mass, and (b) Conservation of Momentum (mass*velocity). So make sure the new planet has the sum of the old masses (which I imagine you're already doing). And then sum up the momenta before, and use that to figure out the momentum (and thus velocity) afterwards.
For some reason this didn't work, and that was the first thing I tried... hmm... I'll figure it out.
So I wanted to get 1000th post in this subforum (who didn't?), but didn't want to just spam a random post in here ("1000th post in Gravity Simulator!"), so here's some tips and ideas.
SPOILER
SPOILER_SHOW
There's not actually much more than adding the masses, and adding the velocities weighted by (multiplied by) the masses. Some things which might have happened are:

- Not deleting old things, or when you delete them, indexes aren't updating exactly (which is why you can't just delete certain indexes in order).

- Accidentally multiplying/dividing by something when you don't need to (ex. multiplying by mass twice? or multiplying and then dividing by mass? Or something similar with velocity?). I've done something like this before, so I doubt it's uncommon. Make sure you know what expression represents force and which acceleration (and energy, moment of inertia, etc).

- Letting the objects get too close before they merge. If the densities are too large, the objects would be separate in one instance, but pull themselves together so strong they don't have a frame where they are actually touching. I noticed a ridiculous acceleration with the two smallest planets in the original setup, so this might be a cause.
- - Additionally, they might touch in an instance, but be so close that their velocities are ridiculous (I really like this word, right? :P); then, when you try to merge them, the resulting velocity is weird.*

*Or will they? Hint - See the 3rd law.
Additionally, remember you can just ignore conservation of energy for collisions. (It would technically be dissipated into shockwaves or heat or something.)
A Random Player wrote: True! You just need to remember that cos = x/d, and sin = y/d (soh-cah-toa anyone?), and replace it. So in general,
vx += x / d * f(d)
vy += y / d * f(d) Also Andy has a tweet's characters more than twice my post count - 828 vs 484. Also the digits are all powers of 2, and mine is 22^2!
DOH! Haha, neat-o. I'll definitely work on this.
The formula is definitely a lot neater with r^-2, though :P

Re: So I tried to see if I could do something like GSim in J

Posted: Wed Jul 15, 2015 9:00 pm
by testtubegames
Haha - well done on that 1000th post -- stood right out to me when I loaded up the forums. Also, nice list of the possible things that can go wrong with merging. It's amazing how many issues can crop up for even what seems like a basic operation.

Re: So I tried to see if I could do something like GSim in JS

Posted: Sat Nov 25, 2017 1:52 pm
by tirespider
was this code moved from Dropbox? the link no longer works. how can i get the last revision to try?

Re: So I tried to see if I could do something like GSim in JS

Posted: Mon Dec 04, 2017 7:38 pm
by wtg62
tirespider wrote:was this code moved from Dropbox? the link no longer works. how can i get the last revision to try?
Dropbox disabled directly linking to HTML pages and disabled public folders a while back and it's been a major inconvenience to me.
You can find it here: https://dl.dropbox.com/s/vx2j77rmt1w91eh/gravsim.html