From 66d0a0b2e2531b61ef513b68c41128aa2df4a95e Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 29 Jun 2017 10:57:11 +0100 Subject: start of work on p-p collisions --- particle.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'particle.js') diff --git a/particle.js b/particle.js index bfafa87..fc7d249 100644 --- a/particle.js +++ b/particle.js @@ -49,4 +49,12 @@ function Particle(x, y, m, c) { dist(x1, y1, x2, y2) ) < 2; } + + this.collide = function(otherp) { + var dist = function(x1, y1, x2, y2) { + return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); + }; + + return dist(this.pos.x, this.pos.y, otherp.pos.x, otherp.pos.y) < this.mass + otherp.mass; + } } -- cgit v1.2.1