0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

fix centroid for static compound bodies, closes #483

This commit is contained in:
liabru 2017-11-25 14:52:41 +00:00
parent 50a89d0217
commit ece66e6f16

View file

@ -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;
};