Monday 6 August 2012

Teething Problems

The first draft of Fizzbox gravity is done - here it is in all its glitchy badness! Click in the box to make a planet.


There are loads of annoying problems to sort out, some I understand, some I don't.
I promise you won't need to understand much physics to enjoy most of my sims, but some boring geeks like me might want to know what's gone wrong. Non geeks could skip to 'Good Things to Come'.

Ping Effect: Make two planets very close together. You can do that by clicking twice in the same spot relatively quickly. The planets will accelerate towards each other before shooting off, sometimes too fast to see. This is to do with the Integration technique, Euler Integration. A thousand times a second this program calculates the force of gravity due to each planet on every other planet. When two planets become very close, the force of gravity between them is very strong causing huge acceleration. In a thousandth of a second the virtual planet will shoot past its partner to a point were gravity is weaker, and fly off. 

In our Universe, this obviously doesn't happen, for two main reasons. Unlike those above, real planets aren't point sources of gravity - they have a size. Unless two point sources come together, there's no problem. Secondly, there's no time delay between 'simulation steps' in the real world. You could think about the Universe doing an infinite number of calculation sets every second, rather than a measly thousand. Alternatively you could just accept that the Universe doesn't bother to do integration, it just happily physicses along physicsly.

I've put in two fudgey fixes to this problem:
  • Gravity 'switches off' when planets come within a certain distance of each other. You might be able to see this if you watch a collision carefully. This is a horrible fix and I hope I can get rid of it asap, possibly by allowing planets to bounce off each other. I wonder if I could just spread the mass through  the disk of the planet instead - more like the real case?
  • Planets start with random initial speed. You can see this by clicking once - the planet will move even though there are no other planets to interact with. That makes two planets less likely to cross paths. This isn't bad physics, since the Universe didn't just start out as a bunch of stationary planets wanting to interact.
There are more problems which I don't get. I'm not convinced that all the planets 'notice' each other. Some just don't seem to interact. Fix to come soon (hopefully!).

Good Things to Come: After a few hours of bug fixing there are a few cool things I can do to make this way more interesting. Watch out for the next draft in a day or two:

  • Choose the mass of a planet. I think this would be done by the user holding the mouse button down as the planet grows.
  • Set initial velocity. This should let you set up interesting orbits.
  • Set up our solar system. I'm hoping to set up a sim with real data to model our system. That way you'll be able to edit it and see how things would go if something were different.
  • Planets that aren't just red dots! Expect to see the sim looking a bit less boring next time.


5 comments:

  1. Looking good Simon! :) Are you just doing it in Python or do you plan to try it in other languages too?

    I love your "it just happily physices along physicsly" btw haha!

    Jo (your cousin) x

    ReplyDelete
    Replies
    1. Thanks Jo. I've abandoned python altogether this time round. This is javascript at the moment and I'm hoping to change it to coffeescript at some point. http://coffeescript.org/
      I think I'll do a post about the differences eventually.

      Looks like I have teething problems with the teething problems post now - I haven't accounted for the fact that the coordinate system now starts at the start of the blog page rather than the top of the Fizzbox window as it did in my tests.

      Can I just ask, on your browser (which one do you use?)when you click on the window does a planet appear where you click or offset somewhere?

      Delete
    2. Seems to be fixed now. That was a right pain to sort out

      Delete
    3. Ahh, sorry - I must have missed where you said you weren't using python anymore!

      The sim is working fine for me - planets appearing where I click, no offset. I'm using safari on my iPad. :)

      Delete
  2. Still having problems with firefox.
    Seems to work OK on other browsers though

    ReplyDelete

About Me

My photo
Manchester, United Kingdom
Second year physics student at the University of Manchester, interested in simulation and education.