Skip to content

Commit ece66e6

Browse files
committed
fix centroid for static compound bodies, closes #483
1 parent 50a89d0 commit ece66e6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/body/Body.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,16 @@ var Axes = require('../geometry/Axes');
672672

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

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

686686
return properties;
687687
};

0 commit comments

Comments
 (0)