Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

GR in HTML/JavaScript?

  1. Jun 27, 2012 #1
    OK, just a bit of fun . . . hope no-one is too offended ;)

    Inspired by the Newtonian orbit example here: http://www.travisglines.com/tag/runge-kutta, I thought I'd see how much GR I could do in JavaScript/HTML5 canvas. So, I got a side-by-side Newton/Schwarzschild demo going, code here: https://www.box.com/s/a514bd0a108e7717ab09. I stopped when I got bored, and I'm not into HTML, so I didn't make any controls for it; there are two scenarios commented in the JS code which you will need to edit to taste. By default it displays a borderline unstable decaying circular orbit against the Newtonian "equivalent", using the effective potential equations from MTW chapter 25 (Euler integration seems be more accurate than the RK4 on the original site, which has horrible precession for a Newton orbit).

    Feel free to take/use/ignore with impunity, I'm sort of leaning towards trying a Boyer-Lindquist version, but not decided yet.

    Of course, if you are looking for accuracy just go with GROrbits!
     
  2. jcsd
  3. Apr 18, 2013 #2
    OK I went quite a bit further than I had originally planned, and so we now have a JavaScript/HTML5 canvas model of a spinning black hole in the equatorial plane, again up against Isaac's vision.
    It uses an "effective potential" approach, with Euler integration and my own "turnaround" code. If you see precession in the Newton trace, you need to reduce the timestep.
    It starts up with a reasonable approximation to the orbit of Mercury, you have to "zoom in" quite a lot to see the effects of GR (hopefully the input controls make sense).
    I checked the geometrized figures against GROrbits, but to add a touch of reality I have attempted to "denormalize" everything to more everyday units; I might have made errors at this stage, please let me know if anyone finds any . . .
    Anyway, Voila!

    https://www.box.com/s/vfznxq5ymhg5zjyoeqds
     
  4. Apr 18, 2013 #3

    pervect

    User Avatar
    Staff Emeritus
    Science Advisor

  5. Apr 18, 2013 #4
    Ha, I had no idea that was yours! In fact that applet and later GROrbits were the inspiration for what I have done ;) I built them both in Eclipse and had a good rummage in the code, and wondered how far the basic engine could be stripped down, for learning purposes (mine or anyone else's).
    My claim to notoriety is mainly down to the tiny code size (there is a commented out Schwarzschild model that can be deleted, also I haven't tried minifying . . .), also it can run and be debugged in any of the open source browsers (hint: not tested on any version of IE).
    I do hope we can all coexist in harmony ;)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: GR in HTML/JavaScript?
  1. Transformation in GR (Replies: 6)

  2. Acceleration and GR (Replies: 11)

  3. GR Journal (Replies: 5)

  4. Tensors in GR (Replies: 2)

Loading...