Gravity Simulator
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl
General >> Discussion >> New Gravity Simulator
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl?num=1411876589

Message started by Tony on 09/27/14 at 20:56:28

Title: New Gravity Simulator
Post by Tony on 09/27/14 at 20:56:28

It works on all computers because it works in your browser.  I can even run it on my cell phone.
It doesn't have nearly all the bells and whistles of the Windows version.  You can't even save your simulations (at least not yet!)
It also behaves quite differently on different computers.

This is a recreation of the solar system barycenter simulation:
http://orbitsimulator.com/gravitySimulatorCloud/ssBarycenter.html

This traces the pentagram of Venus caused by the near 13:8 resonance between Venus and Earth
http://orbitsimulator.com/gravitySimulatorCloud/venusPentagram.html

This shows all the Moons of Jupiter
http://orbitsimulator.com/gravitySimulatorCloud/joviansystem.html

This shows the motion of the Spitzer Space Telescope.  Scroll down for a rotating frame version.
http://orbitsimulator.com/gravitySimulatorCloud/spitzer.html

Voyager 1 approaches Jupiter.  It makes very close flybys of Io, Ganymede and Callisto before heading off for Saturn.
http://orbitsimulator.com/gravitySimulatorCloud/voyager1JupiterApproach.html

Super-massive black hole at the center of the Milky Way
http://orbitsimulator.com/gravitySimulatorCloud/mwbh.html

This one is user-controlable!
Deflecting Apophis.  Apophis won't hit Earth in 2029, but it will make a very close approach.  During this approach, if it passes through a "keyhole", it will return to strike Earth in 2036.  Scientists are certain that it won't pass through this keyhole.  But "what if"?  

This simulation begins in 2014.  This simulation gives you 3 Apophises.  The one called Apophis is based on Apophis' actual trajectory.  But a mere 10 kilometers away sits a pair of 'keyhole Apophises'.  They will pass through the keyhole.  They will return to strike Earth in 2036.  The "Vectors" interface lets you control them.  Leave one of them alone to act as your experimental 'control'.  See how much delta V it takes to nudge the other one off course so it misses the 2029 keyhole.  Just edit the velocity, and it will take off on a new trajectory.

This simulation controls the time step for you.  It also pauses prior to Apophis' close approaches to Earth.  You can override the time step, but don't.  If you go faster than 2048, and 32 when Apophis is in Earth's vicinity, you will not get accurate results.  The simulations takes care of this for you.  It takes some time for this simulation to develop, so be patient.  The sim will automatically pause a few days before Apophis' close approaches, so you won't return to your computer to discover you've missed it.
http://orbitsimulator.com/gravitySimulatorCloud/apophis2014.html

Trojan planet
Adjust the mass of a planet and its trojan companion to see what mass ratios are stable.
http://orbitsimulator.com/gravitySimulatorCloud/trojanratio.html

Turn off Sun's gravity
In demonstrating Newton's Laws, it seems to be a common conceptual question:  What path would the planets follow if the Sun's gravity were somehow turned off? With the press of a button the students can find out.
http://orbitsimulator.com/gravitySimulatorCloud/turnOffSunGravity.html

A binary star system with planets
This is one of the original Gravity Simulator simulations.
http://orbitsimulator.com/gravitySimulatorCloud/casella.html

If the Moon orbited the Earth in a polar orbit, it would crash to the Earth in under a decade due to the Kozai Mechanism.
http://orbitsimulator.com/gravitySimulatorCloud/kozaiMoon.html

Earth captures an asteroid.  In 2006, Earth captured 2006 RH120,  It spent just over a year orbiting Earth before escaping back into interplanetary space.
http://orbitsimulator.com/gravitySimulatorCloud/capturedmoon.html

Title: Re: New Gravity Simulator
Post by flap on 09/30/14 at 05:33:16

Hello Tony.
Unfortunately, is does not work for me (I see some boxes on the left side of the screen. But no animation)

EDIT : It actually works. I had not realised that I had to press the > button hidden somewhere along the boxes.
I guess that it is very much WIP...

Title: Re: New Gravity Simulator
Post by frankuitaalst on 09/30/14 at 22:21:27

Same here , works when the ">" button is pressed under "time step" .
Wonder how Tony did this !

Title: Re: New Gravity Simulator
Post by flap on 10/01/14 at 07:26:44

html5 probably.

One issue now is that once a windows has been closed, it can't be reopened. (Or I haven't figured it out yet...).

Also, as you are porting orbitsim to another support, a cool feature would be to save the trajectory (instead of just drawing them), so we can keep them when zooming, changing the orientation...

Title: Re: New Gravity Simulator
Post by Tony on 10/01/14 at 11:05:51

Yes, this is HTML5 with javascript.
I probably should have began this sim unpaused.

I might try to save the trajectories, but there are a few other things higher on the priority list at the moment.

You can't save the sim as you figured out.  When you close it you lose it. Javascript doesn't allow you save files on a user's hard drive for security reasons.
There's 2 work-arounds:
1. Save the simulation to a text box.  The user copies the contents, pastes it into a text editor and saves it as a text file with an html extension.
2. Use PHP or Perl to save a user's simulation to my server.  This would require users have an account ($$) with me as server space is not free.

I made this because I work in a school where all the students have iPads.  I wanted to give them some assignments using Gravity Simulator that would work on their iPads.  It's worked fine for that purpose.  It's simple.  There's nothing to install.  The HTML5 version might not ever be as powerful as the Windows version.  Browsers don't like being thrown into what they perceive as an endless loop.  Any attempts I've made to speed it up result in a "script not responding" error.

So for the moment, this is just an attempt to recreate some of Gravity Simulator's simulations on a platform anyone can access.  I'll post a few more in the coming days.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 10/02/14 at 13:18:54

I'm not familiar with HTML programming , well , not very familiar , but I wonder how this works .
Do you link then to an application which is running at your server , or is the executable code transferred to a Java engine on the users screen , or even worse did you have to reprogram GravSim into ...??

Title: Re: New Gravity Simulator
Post by Tony on 10/02/14 at 17:58:37


frankuitaalst wrote:
...or even worse did you have to reprogram GravSim into ...??

Yes, I had to reprogram.
But keep in mind, the RK-4 routine that powers Gravity Simulator is already coded in C++, which is virtually identical in syntax to javascript (at least for the stuff I'm doing).
And the orbital elements code was already translated into javascript code on my orbitsimulator.com/formulas page.

So it was more of a piecing together of stuff that already existed, and making slight modifications rather than coding from scratch.

The code is executed in your browser.  You can save it to your computer and run it offline.  Do a "view source" and you can see the code.

Here's another one: http://orbitsimulator.com/gravitySimulatorCloud/spitzer.html
This shows the Spitzer Space Telescope in a rotating frame.

Title: Re: New Gravity Simulator
Post by Tony on 11/05/14 at 19:12:08

Venus pentagram and Jupiter's moons have been added to the first post of this thread.  I've also modified all simulations to begin in the play mode rather than the pause mode.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 11/07/14 at 09:02:00

I really like this work Tony ! especially the Jovian system .
I guess we ( users ) cannot (yet ) select existing simulations and let them run on this app ?

Title: Re: New Gravity Simulator
Post by Tony on 11/07/14 at 18:04:33


frankuitaalst wrote:
I really like this work Tony ! especially the Jovian system .
I guess we ( users ) cannot (yet ) select existing simulations and let them run on this app ?

So far there are 4 you can select from!
I need to improve this a bit more, and add more features: labels, autopilot, etc.  Then I can port over any existing simulation.

I'm not sure it will ever be as good as the Windows version.  Simulating into the deep future seems a bit difficult.  Browsers don't like to be thrown into endless loops.  But for short simulations I like this.  It runs on ANY computer, even cell phones.

If you have any existing sims you'd like ported over, let me know.

Title: Re: New Gravity Simulator
Post by Tony on 11/10/14 at 18:51:23

I've added a few more to the first post in this thread.

Title: Re: New Gravity Simulator
Post by Tony on 06/30/15 at 19:34:31


frankuitaalst wrote:
This is absolutely a wonderful achievement Tony !
I see a lot of new features in the html version compared to the GravSim executable .
Is there any chance the GravSim will get this features also in the future ?

Gravity Simulator is written in Visual Basic 6.0, which can not do a lot of the things HTML5 can do.  HTML5 can take advantage of the new multi-core processors. VB6 is no longer supported by Microsoft, so that won't change.
HTML5 with javascript is much faster, and all platforms can run it.  Here are some sneak previews:

In 2029, Apophis comes very close to Earth.  I exaggerated Earth's diameter, so Apophis will hit.  In Windows Gravity Simulator, with the graphics turned off, it took about 20 seconds to propagate Apophis from today to 2029.  In HTML5, it only takes about 6 seconds with the graphics ON. (assuming your computer has the same speed as mine).  Change the DoEvents to 10 for a more enjoyable viewing.  This simulation is a view of Earth from Apophis.
http://orbitsimulator.com/BA/1435715518034_aprelease.html

HTML5 gives me multiple layers of graphics.  So I can continuously refresh an object's orbit without wiping out the path it traces.  This simulation of Cruithne is an example.
http://orbitsimulator.com/BA/1435715833482_cruithneRelease.html

Soon I'll release the full HTML5 version with all the menus and GUIs I've created this far.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 07/01/15 at 10:41:24

Again , amazing achievement Tony !

I ran the http://orbitsimulator.com/BA/1435715518034_aprelease.html simulation and have following info :

* Apophis crashes to Earth in 2029 . Is this also what you get ?
* The time slice is 2048 , I can't change it to lower or higher values . The "reverse" however works .
* Two input buttons seem to interact : pushing the "star field " sometimes triggers the "pre-orbit "feature . Sometimes the "pre-orbit" button doesn't seem to react also .  

Title: Re: New Gravity Simulator
Post by Tony on 07/01/15 at 12:53:53


frankuitaalst wrote:
Again , amazing achievement Tony !

I ran the http://orbitsimulator.com/BA/1435715518034_aprelease.html simulation and have following info :

* Apophis crashes to Earth in 2029 . Is this also what you get ?
* The time slice is 2048 , I can't change it to lower or higher values . The "reverse" however works .
* Two input buttons seem to interact : pushing the "star field " sometimes triggers the "pre-orbit "feature . Sometimes the "pre-orbit" button doesn't seem to react also .  

Yes, I exaggerated Earth's diameter by a factor of 10 to create the collision.
Your integrator is set to RK4 variable time step.  It chooses the largest accurate time step for you.  If you want to override that, you have to choose RK4 as your integrator instead of RK4vts.
Which 2 input buttons?  Pre trails should not work in this sim as pre-trails were never generated for any of the objects.  Selecting this should do nothing.  In the Cruithne simulation pre-trails is used.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 07/01/15 at 13:27:52

Thanks , I wasn't aware there was an "optimal" time step avalable .
Curious : how did you code for this ??? Taking into account the minimum actual distance between bodies ?  

I was talking about the buttons :
"stars " and the "pre-trails" which interfere .

Title: Re: New Gravity Simulator
Post by Tony on 07/01/15 at 14:50:31


frankuitaalst wrote:
Thanks , I wasn't aware there was an "optimal" time step avalable .
Curious : how did you code for this ??? Taking into account the minimum actual distance between bodies ?  

I was talking about the buttons :
"stars " and the "pre-trails" which interfere .

It's programmed in the Steps Per Radian textbox. With that number set to 100, it chooses a time step that will allow an object to traverse 1 radian of its orbit in 100 steps. (in which case, the entire orbit would take 628 steps)

The trails you see when you turn off the stars are not pre-trails.  They are "post-trails".  They get drawn as the object moves.  Pre-trails are computed before the simulation begins running.  They're not used in the Apophis simulation.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 08/09/15 at 04:28:37

I especially like the feature which lets you INSERT a body in a simulation.
As I understood the html version then contacts the horizons jpl website and retrieves the x,y,z,vx,vy,vz coordinates of the specified body and uses them in the simulation . Fantastic .
http://ssd.jpl.nasa.gov/?horizons_doc#specific_quantities
Is it possible to clarify Tony which settings you use for retrieving the data ?
( Ie : reference frame choosen (JC , FK ) and the options concerning the light -time ) .
The latter may be important in case of far away bodies such as Pluto where the light time comes yes/no into play depending upon ...

Title: Re: New Gravity Simulator
Post by Tony on 08/09/15 at 09:13:24

For example, to retrieve position and velocity vectors for Charon on May 1, 2015, paste the following into your browser:

http://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=1&START_TIME%20=%20%272015-May-01%2000:00:00%27&STOP_TIME%20=%20%272015-May-01%2000:00:01%27&TABLE_TYPE%20=%20%27Vector%27&REF_PLANE%20=%20%27Ecliptic%27&CENTER%20=%20%27@010%27&COMMAND=%20%27901%27%20%27999%27%20%27902%27%20%27903%27%20%27904%27%20%27905%27%20%27-97%27

It returns sun-centered position and velocity.  Light speed is not accounted for.  I forget the explanation, but if you account for light speed in an n-body it makes the system unstable.  Somewhere in the explanation, light travel time cancels out due to a relativistic effect.  If I find a link explaining it I'll post it here.

Title: Re: New Gravity Simulator
Post by frankuitaalst on 08/09/15 at 09:41:52


Tony wrote:
For example, to retrieve position and velocity vectors for Charon on May 1, 2015, paste the following into your browser:

http://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=1&START_TIME%20=%20%272015-May-01%2000:00:00%27&STOP_TIME%20=%20%272015-May-01%2000:00:01%27&TABLE_TYPE%20=%20%27Vector%27&REF_PLANE%20=%20%27Ecliptic%27&CENTER%20=%20%27@010%27&COMMAND=%20%27901%27%20%27999%27%20%27902%27%20%27903%27%20%27904%27%20%27905%27%20%27-97%27

It returns sun-centered position and velocity.  Light speed is not accounted for.  I forget the explanation, but if you account for light speed in an n-body it makes the system unstable.  Somewhere in the explanation, light travel time cancels out due to a relativistic effect.  If I find a link explaining it I'll post it here.

Thanks Tony for the link .
Concerning the light time correction : It is assumed gravity works instantanious , just as Newton derived .  This means the action of far away bodies comes from another position as to where we "see" the body . Just wondered with which value GravSim works . Seems ok
Edit : maybe the "light time correction " may give some funny results if one would observe eclipses , such as solar eclipse in which the observed time may be off by several minutes .  

Title: Re: New Gravity Simulator
Post by frankuitaalst on 12/12/15 at 11:28:53

I'm really fascinated about some new features in the html version of the GravSim simulator as there are :
the possibility to choose a camera location and "look at" feature , and also the feature which displays on screen crescents , such as the crescent moon , taking account the position of the illumination source .
I've not looked at the code yet , but is this a "standard " function html provides or did it require additional coding ?

Title: Re: New Gravity Simulator
Post by Tony on 12/13/15 at 13:20:52

The camera position and "look at" feature was done with additional coding.  The crescents were done with additional coding as well.
There are some libraries available to HTML5 such as WebGL and three.js.  I've played around with each a little, but not all browsers support them, so I didn't use them.
In the future, I might use them to include surfaces of planets, so when you look at Earth, you see continents and oceans instead of a big blue circle.

Crescents were done by computing the phase angle between the camera/object and object/sun lines.  The shape of the terminator line is a half ellipse, alternating between e = 0 (circle) and e = 1, straight line.  In the code, look for the function: function drawCrescentA()

Title: Re: New Gravity Simulator
Post by frankuitaalst on 12/13/15 at 13:40:03

Thanks for the reply Tony. Amazing achievement in coding !  
I looked at the "moon occults Venus" html sim .
It really looks as viewing through a telesscope to view the crescent moon occult the phased Venus .
Drwaing phases is also done by drawCrescentA() ?
I'll take a look .  

Title: Re: New Gravity Simulator
Post by Tony on 12/13/15 at 16:27:15

Yes, the drawing phases is done by drawCrescentA().  But lots of math is done outside that function before it is called.
You need to know the vectors for the various objects.

The two vectors are:
vector1: the line connecting the target object to the Sun
vector2: the line connecting the target object to the camera object

So in the "Moon occults Venus" sim when it draws the Moon, vector 1 is the line connecting the Moon to the Sun and vector2 is the line connecting the Moon to the Earth.
When it draws Venus, vector1 is the line connecting Venus to the Sun, and vector2 is the line connecting Venus to the Earth.

The following code gets executed just prior to calling drawCrescentA();

These 2 lines of code create the vectors in heliocentric coordinates (Sun is at 0, 0, 0)

vector1x = objx[k]; vector1y = objy[k]; vector1z = objz[k];
vector2x = objx[k] - objx[fromObjA]; vector2y = objy[k] - objy[fromObjA]; vector2z = objz[k] - objz[fromObjA];


These 2 lines use Pythagorean theorem to get the lengths or magnitudes of the vectors

vector1mag = Math.sqrt(vector1x * vector1x+ vector1y * vector1y + vector1z*vector1z);
vector2mag = Math.sqrt(vector2x * vector2x+ vector2y * vector2y + vector2z*vector2z);


To get the phase angle between 2 vectors, you use:
arccosine (dot product of the 2 vectors divided by the product of their magnitudes)

These two lines compute the dot product and the magnitude product

dot = vector1x * vector2x  + vector1y * vector2y  + vector1z * vector2z ;
mag = vector1mag * vector2mag;


Now you can compute the phase angle

theta = Math.acos(dot / mag);


Now you have to compute the orientation of the terminator line.  The terminator touches the limb of the planet on 2 points, 180 degrees apart.  This forms a line.
Find the slope of this line using slope = rise / run.
Then use arctangent to get the angle of that line.


rise = sY - sunY; run = sX - sunX; phi = Math.atan2(rise, run) - 0.5 * Math.PI;


Prevent quadrant error.

if (sunTheta > 90) {phi = phi - Math.PI}


Send to the drawCrescent function the index of the object to be drawn (k), plus its position on the screen (sX, sY), its angular size (plotsize), the phase angle (theta), and the orientation (phi).
plotsize, sX and sY were computed a few lines before the crescent code since they're the same whether the user chooses to display crescents or not.

drawCrescentA(k, sX, sY, plotsize, theta, phi);

The function drawCrescent takes this info and:
1. Draws a semi circle representing the dark limb of the object.
2. A semi ellipse representing the terminator (day/night line).
3. Colors this closed shape with the object's shadow color.
4. Draws another semi circle representing the bright limb of the object.
5. Redraws the same semi ellipse representing the terminator.
6. Colors this closed shape with the object's color.

Title: Re: New Gravity Simulator
Post by Tony on 12/13/15 at 18:40:42


frankuitaalst wrote:
I'm really fascinated about some new features in the html version of the GravSim simulator...

It also has realistic stars.
I won't be able to see this in San Francisco, but here's a view from Brussels of the Moon occulting Aldebaran on the night before the night before Christmas.
http://orbitsimulator.com/gravitySimulatorCloud/simulations/1450059732001_Moon_Occults_Aldebaran.html

Title: Re: New Gravity Simulator
Post by frankuitaalst on 12/14/15 at 11:43:32

Just one word to above posts Tony : waw !
Great job !

Edit : thought the DrawCrescent() was a standard function in html , but after looking at the code I see the function is coded as the parts you describe in the previous post . Nice !  
Second Edit : any chance the code may be extended with the anaglyph viewing function ? Would be nice to get some depth in the screen . I see parallel vieuwing is already inplemented . The step to anaglyph may therfor be possible .

Title: Re: New Gravity Simulator
Post by Tony on 12/14/15 at 21:18:53

Yes, I had to write drawCrescent.

The code already has anaglyph view.

Going back to a slightly older version, here's an example:
http://orbitsimulator.com/gravitySimulatorCloud/simulations/1450155652482_3d.html

In the newer versions, you use the 3d checkbox to turn on or off the stereo mode.

You can control the baseline and swap views with the "crosseye" or "parallel" options.

I don't like red/blue glasses, so I never tinted the images.  Instead, send away for the "Owl Viewer", invented by astrophysicist Brian May (also the guitarist for Queen [We will we will rock you!]). http://www.londonstereo.com/shop_home3.html
If you have a very high res display like most current tablets have, you can't even see the pixels through the magnifying glasses.  But if you don't, you can always take very-hi res screen shots and print them just like family photos at the local drug store.  If you get the baseline properly adjusted, the images pop out at you just like 3-d movies.

If it doesn't make you dizzy or give you headaches, you can always just cross your eyes and make a free 3d image.  No glasses or viewer required!

This also explains why the code has drawCrescentA() and drawCrescentB().  A is the left image, and B is the right.

Gravity Simulator » Powered by YaBB 2.1!
YaBB © 2000-2005. All Rights Reserved.