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:
parent
50a89d0217
commit
ece66e6f16
1 changed files with 6 additions and 6 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue