Skip to content

Add VolumeBelow/CenterOfVolumeBelow for Ellipsoid, Cylinder, Capsule and Cone (backport #730)#732

Merged
caguero merged 1 commit intogz-math9from
mergify/bp/gz-math9/pr-730
Mar 19, 2026
Merged

Add VolumeBelow/CenterOfVolumeBelow for Ellipsoid, Cylinder, Capsule and Cone (backport #730)#732
caguero merged 1 commit intogz-math9from
mergify/bp/gz-math9/pr-730

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify bot commented Mar 19, 2026

🎉 New feature

Summary

Continuing with #724 , this patch extends the volume API (VolumeBelow and CenterOfVolumeBelow) — previously available only on Sphere and Box — to Ellipsoid, Cylinder, Capsule, and Cone.

Each shape computes the volume and centroid of the region below an arbitrary cutting plane, which is the key primitive needed for buoyancy force and torque calculations in simulation.

Algorithms

Shape Complexity Technique Notes
Ellipsoid O(1) Affine map to unit sphere + spherical cap formula 1 sqrt, 0 trig, 0 heap allocs
Cylinder O(1) Closed-form circular segment antiderivatives (Cavalieri's principle) 2-5 trig calls, 0 heap allocs. Shared helpers in WetVolume.hh
Capsule O(1) Decomposes into Cylinder + 2 Sphere hemispheres Stability guard for tiny hemisphere slices avoids catastrophic cancellation
Cone O(1) 10-point Gauss-Legendre quadrature over smooth sub-intervals <= 90 integrand evals. Varying radius prevents closed-form. Kink-point subdivision ensures smoothness

All implementations are header-only, zero-allocation, and suitable for real-time stepping.

Changes

  • detail/WetVolume.hh (new) — shared circular-segment and GL10 quadrature helpers, eliminating duplication between Cylinder and Cone.
  • detail/{Ellipsoid,Cylinder,Capsule,Cone}.hhVolumeBelow and CenterOfVolumeBelow implementations.
  • Public headers — method declarations added.
  • C++ tests — per-shape tests (horizontal, vertical, oblique, tilted planes; complement symmetry; rotational offset) + VolumeBelowFloat tests for all four shapes.
  • Python pybind11volume_below / center_of_volume_below bindings and tests for all four shapes.
  • Ruby SWIGVolumeBelow / CenterOfVolumeBelow added to Cylinder.i, Cone.i. New Ellipsoid.i, Capsule.i created (preparatory; not in active build).

Test plan

  • All 193 existing + new C++ tests pass (ctest --output-on-failure)
  • New Python binding tests pass for all four shapes
  • Float instantiation tests compile and pass for all four shapes
  • CI passes on all platforms

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the feature
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Claude

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Backports: If this is a backport, please use Rebase and Merge instead.


This is an automatic backport of pull request #730 done by Mergify.

… Cone (#730)

- Extract shared circular-segment and GL10 quadrature helpers into
  detail/WetVolume.hh, replacing duplicate code in Cylinder and Cone
- Improve Capsule CenterOfVolumeBelow numerical stability by guarding
  against catastrophic cancellation when hemisphere slice volume is tiny
- Add float instantiation tests for all four shapes
- Add Python pybind11 bindings and tests for volume_below and
  center_of_volume_below on all four shapes
- Add Ruby SWIG bindings for VolumeBelow/CenterOfVolumeBelow on
  Cylinder, Cone, and new Ellipsoid/Capsule .i files
- Fix MSVC C4305 truncation warning in Ellipsoid::Volume

Generated-by: Claude

Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
(cherry picked from commit 2860804)
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 19, 2026
@caguero caguero merged commit 54ac149 into gz-math9 Mar 19, 2026
14 checks passed
@caguero caguero deleted the mergify/bp/gz-math9/pr-730 branch March 19, 2026 13:18
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🪵 jetty Gazebo Jetty

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants