Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Godot Physics]: Correct typo in moment of inertia calculations. #47284

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

DarkKilauea
Copy link
Contributor

The moment of inertia calculation for BoxShape is:

Vector3(
    (p_mass / 3.0) * (ly * ly + lz * lz), 
    (p_mass / 3.0) * (lx * lx + lz * lz), 
    (p_mass / 3.0) * (lx * lx + ly * ly));

where the final line includes both the x and y extents.

However, for CapsuleShape3D, CylinderShape3D, ConvexPolygonShape3D, ConcavePolygonShape3D, and HeightMapShape3D, the final line read (p_mass / 3.0) * (extents.y * extents.y + extents.y * extents.y).

I believe this is a mistake, considering the comment in each case mentions using an AABB approximation, which should follow the same approach as BoxShape.

This change corrects the final line to include both the x and y components of the shape's extent.

The moment of inertia calculation for BoxShape is:

```
Vector3(
    (p_mass / 3.0) * (ly * ly + lz * lz), 
    (p_mass / 3.0) * (lx * lx + lz * lz), 
    (p_mass / 3.0) * (lx * lx + ly * ly));
```

where the final line includes both the x and y extents.

However, for CapsuleShape3D, CylinderShape3D, ConvexPolygonShape3D, ConcavePolygonShape3D, and HeightMapShape3D, the final line read `(p_mass / 3.0) * (extents.y * extents.y + extents.y * extents.y)`.  I believe this is a mistake, considering the comment in each case mentions using an AABB approximation, which should follow the same approach as BoxShape.

This change corrects the final line to include both the x and y components of the shape's extent.
Copy link
Contributor

@madmiraal madmiraal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is a typo.

In reality, moment of Inertia calculations are more complicated than these; so the whole subject probably deserves further investigation, but the change is definitely an improvement.

@akien-mga akien-mga merged commit f7a92ee into godotengine:master Mar 23, 2021
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@DarkKilauea DarkKilauea deleted the fix-moment-of-inertia branch March 26, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants