Skip to content

Incorrect Inertia Computation for Capsules, Cylinders, and Cones Due to Default Axis Mismatch #486#505

Merged
vreutskyy merged 2 commits into
newton-physics:mainfrom
vreutskyy:486-incorrect-inertia-computation-for-capsules-cylinders-and-cones-due-to-default-axis-mismatch
Aug 7, 2025
Merged

Incorrect Inertia Computation for Capsules, Cylinders, and Cones Due to Default Axis Mismatch #486#505
vreutskyy merged 2 commits into
newton-physics:mainfrom
vreutskyy:486-incorrect-inertia-computation-for-capsules-cylinders-and-cones-due-to-default-axis-mismatch

Conversation

@vreutskyy

@vreutskyy vreutskyy commented Aug 4, 2025

Copy link
Copy Markdown
Member

Description

Fixes incorrect inertia computation for capsules, cylinders, and cones due to axis mismatch. Closes #486

Problem

When adding capsule, cylinder, or cone shapes, they are internally stored with Z-axis orientation:

# internally capsule axis is always +Z
q = quat_between_axes(Axis.Z, axis)
xform = wp.transform(xform.p, xform.q * q)

However, the inertia computation functions (compute_capsule_inertia, compute_cylinder_inertia, compute_cone_inertia) were calculating inertia assuming Y-axis orientation. This mismatch caused incorrect inertia tensors, leading to inaccurate rotational dynamics in physics simulations.

Solution

Updated the inertia computation functions in newton/geometry/inertia.py to compute inertia for Z-axis orientation:

  • Changed docstrings to reflect Z-axis orientation
  • Modified inertia tensor assignment: changed from I = [[Ia, 0, 0], [0, Ib, 0], [0, 0, Ia]] (Y-axis) to I = [[Ia, 0, 0], [0, Ia, 0], [0, 0, Ib]] (Z-axis)
  • Added comprehensive unit tests in test_inertia.py to verify correct inertia computation for all three axes (X, Y, Z)

Testing

Added test_capsule_cylinder_cone_axis_inertia() which verifies:

  • Z-axis aligned shapes have I_xx = I_yy ≠ I_zz
  • Y-axis aligned shapes have I_xx = I_zz ≠ I_yy
  • X-axis aligned shapes have I_yy = I_zz ≠ I_xx

All existing tests continue to pass.

Newton Migration Guide

Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this MR.

  • The migration guide in docs/migration.rst is up-to-date

Before your PR is "Ready for review"

  • All commits are signed-off to indicate that your contribution adheres to the Developer Certificate of Origin requirements
  • Necessary tests have been added and new examples are tested (see newton/tests/test_examples.py)
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • Documentation

    • Updated documentation to clarify that capsules, cylinders, and cones extend along the z-axis, with corresponding changes to comments and inertia tensor descriptions.
  • Tests

    • Added new tests to verify that inertia tensors for capsules, cylinders, and cones reflect correct axis orientation and symmetry properties.

…to Default Axis Mismatch newton-physics#486

Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 4, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The inertia computation functions for capsules, cylinders, and cones were updated to use the z-axis as the principal extension direction, correcting prior inconsistencies in documentation, comments, and inertia tensor construction. A new unit test was added to verify that inertia tensors for these shapes reflect the correct axis-dependent symmetry properties.

Changes

Cohort / File(s) Change Summary
Inertia Computation Axis Correction
newton/geometry/inertia.py
Updated docstrings, comments, and inertia tensor matrix construction in capsule, cylinder, and cone inertia functions to reflect z-axis orientation.
Axis-Oriented Inertia Tensor Test
newton/tests/test_inertia.py
Added a new test method to verify inertia tensor symmetry for capsules, cylinders, and cones aligned along different axes.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase as test_capsule_cylinder_cone_axis_inertia
    participant ModelBuilder
    participant InertiaFunc as compute_capsule_inertia / compute_cylinder_inertia / compute_cone_inertia

    TestCase->>ModelBuilder: add_body(), add_shape_capsule/cylinder/cone(axis, ...)
    ModelBuilder->>InertiaFunc: compute inertia tensor (shape, axis)
    InertiaFunc-->>ModelBuilder: inertia tensor (aligned with z-axis)
    ModelBuilder-->>TestCase: finalized model with inertia
    TestCase->>TestCase: assert inertia tensor diagonal elements reflect axis symmetry
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Correct inertia computation for capsules, cylinders, and cones to align with z-axis extension (#486)
Update documentation and comments to match new axis convention (#486)
Add or update tests to verify axis-dependent inertia tensor properties (#486)

Suggested reviewers

  • eric-heiden

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 900cbd8 and fc98d7a.

📒 Files selected for processing (2)
  • newton/geometry/inertia.py (4 hunks)
  • newton/tests/test_inertia.py (1 hunks)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
  • GitHub Check: Run GPU Benchmarks (Pull Request)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
🔇 Additional comments (4)
newton/geometry/inertia.py (3)

63-86: LGTM! Correct axis orientation fix for capsule inertia.

The changes properly align the inertia computation with the internal Z-axis representation of capsules. The docstring, comments, and inertia tensor construction have been correctly updated to reflect that I_xx = I_yy = Ia and I_zz = Ib for Z-axis oriented capsules.


92-110: LGTM! Consistent axis orientation fix for cylinder inertia.

The changes correctly update the cylinder inertia computation to match the Z-axis internal representation. The docstring updates, parameter descriptions, and inertia tensor construction are all properly aligned with the new convention.


116-134: LGTM! Consistent axis orientation fix for cone inertia.

The changes correctly update the cone inertia computation to match the Z-axis internal representation. All documentation and tensor construction changes are consistent with the capsule and cylinder updates, ensuring uniform behavior across shape types.

newton/tests/test_inertia.py (1)

157-251: Excellent comprehensive test coverage for axis-dependent inertia properties.

This test thoroughly validates the axis orientation fixes by:

  • Testing all three shape types (capsules, cylinders, cones)
  • Verifying correct symmetry relationships for different axis orientations
  • Using appropriate numerical tolerances and clear assertion messages
  • Ensuring Z-axis shapes have I_xx = I_yy ≠ I_zz, Y-axis shapes have I_xx = I_zz ≠ I_yy, and X-axis shapes have I_yy = I_zz ≠ I_xx

The test design perfectly complements the inertia computation fixes and provides confidence in the correctness of the axis orientation changes.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@shi-eric shi-eric requested review from nvtw and removed request for shi-eric August 6, 2025 16:06
Comment thread newton/geometry/inertia.py
…es-cylinders-and-cones-due-to-default-axis-mismatch
@vreutskyy vreutskyy enabled auto-merge (squash) August 7, 2025 09:23
@vreutskyy vreutskyy merged commit ee6f9a7 into newton-physics:main Aug 7, 2025
11 checks passed
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
…to Default Axis Mismatch newton-physics#486 (newton-physics#505)

Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
vidurv-nvidia pushed a commit to vidurv-nvidia/newton that referenced this pull request Mar 6, 2026
# Description

Correct teleop system requirements doc

<!--
Thank you for your interest in sending a pull request. Please make sure
to check the contribution guidelines.

Link:
https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html
-->

Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes # (issue)

<!-- As a practice, it is recommended to open an issue to have
discussions on the proposed pull request.
This makes it easier for the community to keep track of what is being
developed or added, and if a given feature
is demanded by more than one party. -->

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- This change requires a documentation update

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
…to Default Axis Mismatch newton-physics#486 (newton-physics#505)

Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Inertia Computation for Capsules, Cylinders, and Cones Due to Default Axis Mismatch

2 participants