const PhSim = require("."); /** * Apply Newtonian gravity field. * @function */ PhSim.prototype.applyGravitationalField = function() { var a = this.objUniverse; for(var i = 0; i < a.length; i++) { for(var j = 0; j < a.length; j++) { if(i !== j && !this.isNonDyn(a[i]) && !this.isNonDyn(a[j]) && !a[i].matter.isStatic && !a[j].matter.isStatic) { var a1 = PhSim.Vector.scale(PhSim.Vector.subtract(a[j].matter.position,a[i].matter.position),6.67 * Math.pow(10,-11) * a[i].matter.mass * a[j].matter.mass * -1) var b1 = Math.pow(PhSim.Vector.distance(a[j].matter.position,a[i].matter.position),3); var c = PhSim.Vector.divide(a1,b1); PhSim.Motion.applyForce(a[j],a[i].matter.position,c); } } } }