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

What did you draw?
User avatar
wtg62
Posts: 173
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

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

Postby wtg62 » Sat Jul 11, 2015 6:07 pm

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.
This message has been brought to you by wtg62, duh!

A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

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

Postby A Random Player » Sat Jul 11, 2015 7:14 pm

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: 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
$1 = 100¢ = (10¢)^2 = ($0.10)^2 = $0.01 = 1¢ [1]
Always check your units or you will have no money!

User avatar
testtubegames
Site Admin
Posts: 1007
Joined: Mon Nov 19, 2012 7:54 pm

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

Postby testtubegames » Wed Jul 15, 2015 9:00 pm

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.

tirespider
Posts: 1
Joined: Sat Mar 08, 2014 1:48 pm

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

Postby tirespider » Sat Nov 25, 2017 1:52 pm

was this code moved from Dropbox? the link no longer works. how can i get the last revision to try?

User avatar
wtg62
Posts: 173
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

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

Postby wtg62 » Mon Dec 04, 2017 7:38 pm

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
This message has been brought to you by wtg62, duh!


Return to “Gravity Simulator”

Who is online

Users browsing this forum: No registered users and 1 guest