Skip to content

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

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

Add VolumeBelow/CenterOfVolumeBelow for Ellipsoid, Cylinder, Capsule and Cone (backport #730)#733
caguero merged 1 commit intogz-math8from
mergify/bp/gz-math8/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.

@mergify
Copy link
Copy Markdown
Contributor Author

mergify bot commented Mar 19, 2026

Cherry-pick of 2860804 has failed:

On branch mergify/bp/gz-math8/pr-730
Your branch is up to date with 'origin/gz-math8'.

You are currently cherry-picking commit 2860804.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   include/gz/math/Capsule.hh
	modified:   include/gz/math/Cone.hh
	modified:   include/gz/math/Cylinder.hh
	modified:   include/gz/math/Ellipsoid.hh
	modified:   include/gz/math/detail/Capsule.hh
	modified:   include/gz/math/detail/Cone.hh
	modified:   include/gz/math/detail/Cylinder.hh
	modified:   include/gz/math/detail/Ellipsoid.hh
	new file:   include/gz/math/detail/WetVolume.hh
	modified:   src/Capsule_TEST.cc
	modified:   src/Cone_TEST.cc
	modified:   src/Cylinder_TEST.cc
	modified:   src/Ellipsoid_TEST.cc
	modified:   src/python_pybind11/src/Capsule.hh
	modified:   src/python_pybind11/src/Cone.hh
	modified:   src/python_pybind11/src/Cylinder.hh
	modified:   src/python_pybind11/src/Ellipsoid.hh
	new file:   src/ruby/Capsule.i
	modified:   src/ruby/Cone.i
	modified:   src/ruby/Cylinder.i
	new file:   src/ruby/Ellipsoid.i

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/python_pybind11/test/Capsule_TEST.py
	both modified:   src/python_pybind11/test/Cone_TEST.py
	both modified:   src/python_pybind11/test/Cylinder_TEST.py
	both modified:   src/python_pybind11/test/Ellipsoid_TEST.py

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

… Cone (#730)

Generated-by: Claude
Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
@caguero caguero force-pushed the mergify/bp/gz-math8/pr-730 branch from 458daa4 to dd81d5f Compare March 19, 2026 13:11
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 19, 2026
@caguero caguero merged commit 05af857 into gz-math8 Mar 19, 2026
14 checks passed
@caguero caguero deleted the mergify/bp/gz-math8/pr-730 branch March 19, 2026 13:40
@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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants