Skip to content

Commit 5862949

Browse files
committed
fix centroid for static compound bodies
1 parent dc7289e commit 5862949

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

  • v3/src/physics/matter-js/lib/body

v3/src/physics/matter-js/lib/body/Body.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,16 @@ var Axes = require('../geometry/Axes');
671671

672672
// sum the properties of all compound parts of the parent body
673673
for (var i = body.parts.length === 1 ? 0 : 1; i < body.parts.length; i++) {
674-
var part = body.parts[i];
674+
var part = body.parts[i],
675+
mass = part.mass !== Infinity ? part.mass : 1;
676+
675677
properties.mass += part.mass;
676678
properties.area += part.area;
677679
properties.inertia += part.inertia;
678-
properties.centre = Vector.add(properties.centre,
679-
Vector.mult(part.position, part.mass !== Infinity ? part.mass : 1));
680+
properties.centre = Vector.add(properties.centre, Vector.mult(part.position, mass));
680681
}
681682

682-
properties.centre = Vector.div(properties.centre,
683-
properties.mass !== Infinity ? properties.mass : body.parts.length);
683+
properties.centre = Vector.div(properties.centre, properties.mass);
684684

685685
return properties;
686686
};

0 commit comments

Comments
 (0)