{"id":6970,"date":"2017-11-29T13:26:34","date_gmt":"2017-11-29T11:26:34","guid":{"rendered":"http:\/\/www.randform.org\/blog\/?p=6970"},"modified":"2019-03-05T20:26:02","modified_gmt":"2019-03-05T19:26:02","slug":"galaxy-flush-reloaded","status":"publish","type":"post","link":"https:\/\/www.randform.org\/blog\/?p=6970","title":{"rendered":"galaxy flush reloaded"},"content":{"rendered":"<p><canvas width=\"450\" height=\"400\" id=\"mycanvas\" style=\"border:1px solid #335599;\"><\/canvas><br \/>\n<!-- modification of Mike Bostocks canvas swarm simulation at https:\/\/bl.ocks.org\/mbostock\/2647922  by Nadja Kutz, some debugging help from Tim Hoffmann, especially with the zoom, Nov. 2017 GPL license--><br \/>\n<script type=\"text\/javascript\" src=\"https:\/\/d3js.org\/d3.v4.min.js\"><\/script><br \/>\n<script type=\"text\/javascript\">\nvar sc=7.0;var ma=0.2;var data = d3.range(1500).map(function() {return {xloc:sc*(2*Math.random()-1), yloc:sc*(2*Math.random()-1), zloc:sc*(2*Math.random()-1),xvel:  0.000*Math.random(), yvel:0.000*Math.random(),zvel:0.000*Math.random(),mass:ma*Math.random()};});data.forEach(function(d){while(Math.sqrt(d.xloc*d.xloc+d.yloc*d.yloc+d.zloc*d.zloc)>sc){d.xloc=sc*(2*Math.random()-1);d.yloc=sc*(2*Math.random()-1);d.zloc=sc*(2*Math.random()-1);}});data[1].mass=1850;data[1].xloc=sc*2\/70;data[1].yloc=sc*0.0;data[1].zloc=sc*0.0;data[1].xvel=-0.18;data[1].yvel=0.18;data[1].zvel=0.0;data[2].mass=1850;data[2].xloc=-sc*2\/70;data[2].yloc=sc*0.0;data[2].zloc=sc*0.0;data[2].xvel=0.18;data[2].yvel=-0.18;data[2].zvel=0.0;data[3].mass=0.5;data[3].xvel= 0.3;data[3].yvel=0.4;data[3].xloc=-20.0;data[3].yloc=10.0;data[4].mass=0.5;data[4].xvel= -0.3;data[4].yvel=-0.4;data[4].xloc=20.0;data[4].yloc=-10.0;\n\/* from https:\/\/bl.ocks.org\/mbostock\/2647922 *\/ var angle = 2 * Math.PI;var time0 = Date.now(),time1;var canvas = d3.select(\"#mycanvas\"),context = canvas.node().getContext(\"2d\"),width = canvas.property(\"width\"),height = canvas.property(\"height\");var counter=0;var dist = [];var distI = [];var force = [];var dir =[];d3.timer(function() {context.clearRect(0, 0, width, height);drawZoomed();});canvas.call(d3.zoom() .scaleExtent([1 \/ 10, 10]) .on(\"zoom\", zoomed));var tx = 0+150;var ty = 0+130;var tk = 0.2;function zoomed() {tx = d3.event.transform.x+150;ty = d3.event.transform.y+130;tk = 0.2*d3.event.transform.k;} function drawZoomed() {context.save();context.translate(tx, ty);context.scale(tk, tk);drawPoints();context.restore();}function drawPoints() {var scala=30;data.forEach(function(d,k) {dir[0]=0.0;dir[1]=0.0;dir[2]=0.0;var ind=[];ind[0]=0;var count=0;var cloggx=0;var cloggy=0;var cloggz=0;var cloggm=0;var GRAV=0.001;data.forEach(function(dd,i){dist[i] = Math.sqrt((d.xloc-dd.xloc)*(d.xloc-dd.xloc)+(d.yloc-dd.yloc)*(d.yloc-dd.yloc)+(d.zloc-dd.zloc)*(d.zloc-dd.zloc));if(dist[i]>8){distI[i]=1\/dist[i];}else{distI[i]=0.0;ind[count]=i;count++;} dir[0] = dir[0]+(dd.mass*d.mass*GRAV*Math.pow(distI[i],3)*(d.xloc-dd.xloc));dir[1] = dir[1]+(dd.mass*d.mass*GRAV*Math.pow(distI[i],3)*(d.yloc-dd.yloc));dir[2] = dir[2]+(dd.mass*d.mass*GRAV*Math.pow(distI[i],3)*(d.zloc-dd.zloc));});for(i=0;i < ind.length;i++){var dc = data[ind[i]];cloggx = cloggx+dc.mass*dc.xvel;cloggy = cloggy+dc.mass*dc.yvel;cloggz = cloggz+dc.mass*dc.zvel;cloggm = cloggm+dc.mass};var mix = -0.5;var fric =0.000;if(ind.length!=1){d.xloc += (0.5+mix)*d.xvel+(0.5-mix)*1\/cloggm*cloggx;d.yloc += (0.5+mix)*(d.yvel+(0.5-mix)*1\/cloggm*cloggy);d.zloc += (0.5+mix)*d.zvel+(0.5-mix)*1\/cloggm*cloggz;} else d.xloc += d.xvel;d.yloc += d.yvel;d.zloc += d.zvel;d.xvel += -1\/d.mass*dir[0]+fric*d.xvel;d.yvel += -1\/d.mass*dir[1]+fric*d.yvel;d.zvel += -1\/d.mass*dir[2]+fric*d.zvel;var xoffset=+400.0;var yoffset=+300.0;var massscale =80;if(k>4) {context.fillStyle = \"#000000\";context.strokeStyle = \"#aaccff\";context.lineWidth = 3.0;context.beginPath();context.arc(scala*(d.xloc)+xoffset, scala*(d.yloc)+yoffset, massscale*d.mass, 0, angle);context.fill();context.stroke();} if(k==1){context.beginPath();var scalaDM=0.05;var xoffset=+400.0;var yoffset=+300.0;context.fillStyle = \"#fff\";context.strokeStyle = \"#335599\";context.lineWidth = 5;context.arc(scala*(data[1].xloc)+xoffset, scala*(data[1].yloc)+yoffset, scalaDM*2*data[1].mass, 0, angle);context.stroke();} });var scalaDM=0.05;var xoffset=+400.0;var yoffset=+300.0;context.fillStyle = \"#fff\";context.strokeStyle = \"#335599\";context.lineWidth = 5;context.beginPath();context.arc(scala*(data[2].xloc)+xoffset, scala*(data[2].yloc)+yoffset, scalaDM*2*data[2].mass, 0, angle);context.stroke();context.fillStyle = \"#fff\";context.strokeStyle = \"#990000\";context.lineWidth = 5;context.beginPath();context.arc(scala*(data[3].xloc)+xoffset, scala*(data[3].yloc)+yoffset, 80*data[3].mass, 0, angle);context.stroke();context.beginPath();context.arc(scala*(data[4].xloc)+xoffset, scala*(data[4].yloc)+yoffset, 80*data[4].mass, 0, angle);context.stroke();} time1 = Date.now();counter += counter;time0 = time1;<\/script><span style=\"font-size:80%\">pan and zoom as usual<\/span><\/p>\n<p>In 2006 Tim played around with swarm simulations in processing and ended up with funny flush like settings. We tweaked the parameters in such a way that it ended up looking like and sounding like a galaxy being flushed down the drain and made it into the art work <a href=\"http:\/\/www.daytar.de\/art\/dippergalaxyflush\/\">&#8220;dipper galaxy flush&#8221; <\/a> where dipper refers to the wellknown patterns in the constellation <a href=https:\/\/en.wikipedia.org\/wiki\/Ursa_Major\">Ursa Major.<\/a> Our comment wasn&#8217;t though referring to a particular galaxy <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ursa_Major#Deep-sky_objects\">there<\/a> but to galaxies in general &#8211; which could include our own. <\/p>\n<p>If you look at the processing code you see that Tim&#8217;s simulation doesn&#8217;t use e.g. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Newton%27s_law_of_universal_gravitation\">Newtonian gravity,<\/a> although Tim used a force which is similarily &#8220;centralizing&#8221; as dark matter.<\/p>\n<p>Inspired by discussions about <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dark_matter\">dark matter<\/a> and dark energy and general relativity  at <a href=\"https:\/\/plus.google.com\/+johncbaez999\/posts\/Ep2eTwGpRK9\">John Baez&#8217; social media<\/a> I wanted to get a feeling of how important the feature of dark matter is in order to allow for galaxy formation.<br \/>\nThe above is a realtime javascript simulation using purely newtonian gravity with <strong>no dark matter<\/strong> but two giant masses (indicated by blue circles, which size is not proportional to the smaller circles) and something that could be called an &#8220;inelastic binding&#8221;. That is if the distance between masses is smaller than some number then those &#8220;close-by&#8221; masses behave as if they stuck together as in an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Inelastic_collision\">inelastic collision<\/a>, or in other words: the velocity of a mass is set to be the weighted average velocity of the close-by masses (details in the code, how much inelastic collision you want is set by the parameter &#8220;mix&#8221;). <\/p>\n<p>It was acutally not so easy to find a configuration which somewhat mimicks galaxies, but the above looks a bit as if, I find. If I find the time I may add a 3D viewer. Try yourself &#8211; the source code is open.<br \/>\nHere how a scientifically advanced galaxy simulation, which includes dark matter looks on a super computer: <a href=\"https:\/\/www.youtube.com\/watch?v=VQBzdcFkB7w\">World&#8217;s first realistic simulation of the formation of the Milky Way<\/a> and here an <a href=\"https:\/\/www.youtube.com\/watch?v=GYtBQR2oI4U\">interview with the author Lucio Mayer<\/a>.  Just like us many other users think it looks like a filmed flush &#8211; if you read the comments.<br \/>\nHere another simulation by <a href=\"http:\/\/faculty.washington.edu\/fabiog\/movies.html\">Fabio Governato<\/a> on his youtube channel: <a href=\"https:\/\/www.youtube.com\/watch?v=n0jRObc7_xo\">The Formation of a Milky Way like Galaxy.<\/a> He has a whole variety of galaxy formation videos.<\/p>\n<p>remark: the simulation is a modification of Mike Bostocks canvas swarm simulation at <a href=\"https:\/\/bl.ocks.org\/mbostock\/2647922\">https:\/\/bl.ocks.org\/mbostock\/2647922<\/a><\/p>\n<p>update 1.12.2017: There was a mistake in the addition of the z-speed, which is now corrected in the above version. Luckily the correction did affect the overall appearance only slightly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pan and zoom as usual In 2006 Tim played around with swarm simulations in processing and ended up with funny flush like settings. We tweaked the parameters in such a way that it ended up looking like and sounding like a galaxy being flushed down the drain and made it into the art work &#8220;dipper [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,5,15,8,7,6,14],"tags":[],"_links":{"self":[{"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6970"}],"collection":[{"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6970"}],"version-history":[{"count":51,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6970\/revisions"}],"predecessor-version":[{"id":7370,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6970\/revisions\/7370"}],"wp:attachment":[{"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.randform.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}