Explore GR & Newtonian Orbits in HTML/JS

  • Context: HTML/CSS 
  • Thread starter Thread starter m4r35n357
  • Start date Start date
  • Tags Tags
    Gr
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
m4r35n357
Messages
657
Reaction score
148
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!
 
Physics news on Phys.org
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
 
pervect said:
You might take a peek at http://www.fourmilab.ch/gravitation/orbits/, if you haven't already.
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 ;)