From ece66e6f167f4b13fbd77472d0016602bf747389 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 25 Nov 2017 14:52:41 +0000 Subject: [PATCH] fix centroid for static compound bodies, closes #483 --- src/body/Body.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index fcb18c1c..49fe7177 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -672,16 +672,16 @@ var Axes = require('../geometry/Axes'); // sum the properties of all compound parts of the parent body for (var i = body.parts.length === 1 ? 0 : 1; i < body.parts.length; i++) { - var part = body.parts[i]; - properties.mass += part.mass; + var part = body.parts[i], + mass = part.mass !== Infinity ? part.mass : 1; + + properties.mass += mass; properties.area += part.area; properties.inertia += part.inertia; - properties.centre = Vector.add(properties.centre, - Vector.mult(part.position, part.mass !== Infinity ? part.mass : 1)); + properties.centre = Vector.add(properties.centre, Vector.mult(part.position, mass)); } - properties.centre = Vector.div(properties.centre, - properties.mass !== Infinity ? properties.mass : body.parts.length); + properties.centre = Vector.div(properties.centre, properties.mass); return properties; };