Demoscene and Modified Newton Gravity

Saw this story at Nautilus, about physicist Mordehai Milgrom, written by Oded Carmeli,

http://nautil.us/issue/48/chaos/the-physicist-who-denies-dark-matter

It says you can model gravity by saying instead of force = mass by acceleration, f=ma, that force = mass by square of acceleration, upon a constant.

f=\frac{ma^2}{a_0}

They call this MOND or Modified Newtonian Gravity, after Isaac Newton who did a lot of pioneering with f=ma.

What does MOND mean for a simple demo-style simulation of Newton gravity?

Well first, what is demoscene style gravity simulation? On old computers, like the 80486 from Intel in the 1990s, there was no floating point coprocessor. People used fake calculus to simulate gravity. It started with a simple object with an x and y coordinate on screen. Then on every frame of animation the computer would update the object’s position, it’s velocity, and it’s acceleration. A very rough example:

x += xvelocity

y += yvelocity

xvelocity += xacceleration

yvelocity += yacceleration

r = (x^2+y^2)^(1/2)

xacceleration = -(x/r)*Gm1/r^2

yacceleration = -(y/r)*Gm1/r^2

Repeat and draw x, and y after every iteration,  fiddle with some variables, and you get a nice orbit-looking picture.


This can be derived theoretically in a certain way. We start with force = mass by acceleration, and Gravity force = Gravity constant by mass1 by mass2 upon the square of distance. Distance being difference-in-x squared plus difference-in-y squared, rooted.

f=m_1a

f=\frac{Gm_1m_2}{r^2}

We can re-write this a bit, since object 2 is at position x=0,y=0 we can say distance between object1 and object2 is simply the distance from 0,0 to the x and y coordinate of object 1.  In other words, distancex=x, distancey=y, distancetotal=squareroot(x*x+y*y). But distance square = x*x+y*y. So.

f=\frac{Gm_1m_2}{dx^2+dy^2}

ma=\frac{Gm_1m_2}{dx^2+dy^2}

a=\frac{Gm_2}{dx^2+dy^2}

The acceleration was broken into x and y components by using triangles

\frac{xaccel}{accel}=\frac{dx}{\sqrt{dx^2+dy^2}}

xaccel=\frac{accel*dx}{\sqrt{dx^2+dy^2}}

This means the actual code uses something like this:

xaccel=\frac{Gm_2}{dx^2+dy^2}\frac{dx}{\sqrt{dx^2+dy^2}}

xaccel=\frac{G*m_2*dx}{(dx^2+dy^2)^{3/2}}

Now to simplify on a simple demo you can fake this in computer code. First assume Gravity constant and mass are both 1. Also I like to think of Distance Squared as Wildberger’s Quadrance, or Q. Then its simple few lines of code for updating position and velocity every frame of animation.

dx=x, dy=y

Q=dx*dx+dy*dy

x+=vx+=-dx/Q^1.5

y+=vy+=-dy/Q^1.5

If you play around with the 1.5 and some constants and initial values, you can get all kinds of cool orbit-shaped things.


What if we use modified newton gravity? Let’s try the same derivation.

f=m\frac{a^2}{a_0}

f=\frac{Gm_1m_2}{r^2}

m\frac{a^2}{a_0}=\frac{Gm_1m_2}{dx^2+dy^2}

a^2=\frac{a_0*Gm_2}{dx^2+dy^2}

The acceleration is again broken into x and y components by using triangles, no change

\frac{xaccel}{accel}=\frac{dx}{\sqrt{dx^2+dy^2}}

xaccel=\frac{accel*dx}{\sqrt{dx^2+dy^2}}

This time when substituting in acceleration, we get new stuff. In fact lets square everything to make it easier.

xaccel^2=\frac{accel^2*dx^2}{dx^2+dy^2}

Then do substitution, a^2 above into accel^2 here.

xaccel^2=\frac{a_0*Gm_2}{dx^2+dy^2}\frac{dx^2}{dx^2+dy^2}

xaccel^2=\frac{a_0*G*m_2*dx^2}{(dx^2+dy^2)^2}

xaccel=\frac{\sqrt{a_0*G*m_2}*dx}{dx^2+dy^2}

I find this fascinating because, if I did it correctly, then in terms of distance and coordinates, we are now entirely in Rational Numbers and Rational Functions. There is a square root operator, but it only applies to Gravitational Constant and Milgrom’s Constant and mass. All of which are constant over time for a typical demo like this. So theoretically this could be computed pretty quick in a simulation, without using Sqrt function every update. But I digress.

Now to simplify for computer code… say that sqrt(a0)*G*m is just 1. The code from the old physics, above, changes into this:

dx=x, dy=y

Q=dx*dx+dy*dy

x+=vx+=-dx/Q

y+=yx+=-yx/Q

The only big difference is that the power on Q is now 1. It was Q^3/2. Now it’s just plain old Q. You can also throw in some constants to slow it down, so your computer will show better animation, like this

dx=x, dy=y

Q=dx*dx+dy*dy

x+=vx+=-dx/Q/999

y+=vy+=-dy/Q/999

This actually produces some interesting stuff… start with 2000 random objects and apply MOND as if there were a central gigantic object, and you get a kind of blob with items rotating around the middle… a handful of them flying off into huge orbits. Animation can be seen at the CodeGolf.tk website: https://CodeGolf.tk/a/81

mond2

Here is the prototype javascript code for the above animation, which will work inside the CodeGolf or dwitter.net sandboxes. Note C=Math.cos, S=Math.sin.

Note here that the code is prototyped for 3 dimensions but in this example only 2 dimensions are used, Z is set to 0. Interesting that the stability of the system seems to be related to the dimensionality but that is another story for another time.

x.globalAlpha=.08
x.fillStyle="black"
x.fillRect(0,0,3e3,3e3)
t?1:o=[]
o.length<2000?o.push({
   X:Math.random()*4-2,
   Y:Math.random()*4-2,
   Z:0,
   XV:.01,
   YV:0,
   ZV:0}):1
o.map((星)=>{
 ({X,Y,Z,XV,YV,ZV}=星);
 Q=(X*X+Y*Y+Z*Z)**1;
 星.X+=星.XV+=-星.X/Q/999
 星.Y+=星.YV+=-星.Y/Q/999
 星.Z+=星.ZV+=0  //-星.Z/Q/999
 })
dist=100
o.map((a)=>{
 ({X,Y,Z}=a)
 x.clearRect(1e3+1e4*X/(Z+dist),
 500+1e4*Y/(Z+dist),3,3)}
)

In conclusion:

Making a demo with fake calculus and fake MOND physics can make some interesting animations.

Advertisements
Posted in Uncategorized | Leave a comment