Skip to content

Commit

Permalink
fix centroid for static compound bodies, closes #483
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 25, 2017
1 parent 50a89d0 commit ece66e6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit ece66e6

Please sign in to comment.