You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I know the first body in body.parts is the parent (main) body. If body consists of more than 1 part, every next part become child body so the first one become some kind of container for the rest.
During analyzing of Bodies.fromVertices function i found that Body object after setting all parts it calculate total mass, inertia and centroid based on these parts and there comes _totalProperties function - but I see that centroid can be calculated wrong. I talking about last lines of this function:
var _totalProperties = function(body) {
// [...]
// 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;
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.div(
properties.centre,
properties.mass !== Infinity ? properties.mass : body.parts.length // this one
);
return properties;
};
This "if" properties.mass !== Infinity ? properties.mass : body.parts.length return total mass of body parts if mass is not infinity (what means body is static) and otherwise it returns body.parts.length but as my logic say it is wrong because the first part is the parent body and mass of first one is not calculated to total mass as you can see in loop conditions. Is that ok ? I think this should be divided by number of parts without parent.
The text was updated successfully, but these errors were encountered:
As I know the first body in
body.parts
is the parent (main) body. If body consists of more than 1 part, every next part become child body so the first one become some kind of container for the rest.During analyzing of
Bodies.fromVertices
function i found thatBody
object after setting all parts it calculate total mass, inertia and centroid based on these parts and there comes_totalProperties
function - but I see that centroid can be calculated wrong. I talking about last lines of this function:This "if"
properties.mass !== Infinity ? properties.mass : body.parts.length
return total mass of body parts if mass is not infinity (what means body is static) and otherwise it returnsbody.parts.length
but as my logic say it is wrong because the first part is the parent body and mass of first one is not calculated to total mass as you can see in loop conditions. Is that ok ? I think this should be divided by number of parts without parent.The text was updated successfully, but these errors were encountered: