Conversation
90cd8d6 to
8be3c41
Compare
ahcorde
left a comment
There was a problem hiding this comment.
Can you update the Python binding too ? Adding the new tests
Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Removes TrianglesInPlane and its Triangle3.hh dependency - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> generated-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8be3c41 to
c1226d2
Compare
|
|
@Mergifyio backport gz-math9 gz-math8 gz-math7 ign-math6 |
✅ Backports have been createdDetails
Cherry-pick of c7f441d has failed: 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
Cherry-pick of c7f441d has failed: 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 |
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Removes TrianglesInPlane and its Triangle3.hh dependency - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow generated-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> (cherry picked from commit c7f441d)
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Removes TrianglesInPlane and its Triangle3.hh dependency - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow generated-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> (cherry picked from commit c7f441d)
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Removes TrianglesInPlane and its Triangle3.hh dependency - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow generated-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> (cherry picked from commit c7f441d) # Conflicts: # include/gz/math/detail/Box.hh
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Removes TrianglesInPlane and its Triangle3.hh dependency - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow generated-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> (cherry picked from commit c7f441d) # Conflicts: # include/gz/math/detail/Box.hh
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Deprecates TrianglesInPlane (kept for source compatibility) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Keeps TrianglesInPlane for source compatibility (with bug note) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
…724) Replace the surface-mesh + divergence theorem implementation of Box::VolumeBelow and Box::CenterOfVolumeBelow with an analytic inclusion-exclusion formula (Scardovelli-Zaleski / Lehmann-Gekle). The old VolumeBelow used TrianglesInPlane which relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planes. The old CenterOfVolumeBelow returned the arithmetic mean of vertex positions instead of the volumetric centroid, which was only correct for axis-aligned cuts. The new implementation: - Computes volume analytically via IE3/IE2/IE1 formulas with proper dimensional reduction (handles 3D, 2D, 1D, and degenerate cases) - Computes centroid via first-moment IE formula with F_k functions matched to the effective dimensionality - Deprecates TrianglesInPlane (kept for source compatibility) - Fixes Sphere<float> compilation by replacing hardcoded Vector3d with Vector3<T>::Zero in VolumeBelow and CenterOfVolumeBelow Generated-by: Claude Opus 4.6 (1M context) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org>
🦟 Bug fix
Summary
This patch fixes some functions used to compute graded buoyancy.
Box::VolumeBelowandBox::CenterOfVolumeBelowwith analytic inclusion-exclusion formulas (Scardovelli-Zaleski / Lehmann-Gekle), fixing two bugs:VolumeBelowusedTrianglesInPlanewhich relied on exact float comparison (Plane::Side() == NO_SIDE) and produced wrong volumes for non-axis-aligned planesCenterOfVolumeBelowreturned arithmetic mean of vertex positions instead of volumetric centroid, only correct for axis-aligned cutsTrianglesInPlanefree function and removeTriangle3.hhinclude (no longer needed)Sphere<float>compilation by replacing hardcodedVector3dwithVector3<T>::ZeroinVolumeBelowandCenterOfVolumeBelowBugs fixed
Box::VolumeBelowwrong for non-axis-aligned planes: The old mesh-based implementation usedTrianglesInPlane, which classified vertices with exact float comparison (Plane::Side() == NO_SIDE, requiringDistance == 0.0). Vertices with any FP error were silently dropped, producing incorrect polygon decompositions. Example: box 4x2x6 with plane n=(2,1,3) gave 26.22 instead of the correct 26.67.Box::CenterOfVolumeBelowfundamentally wrong formula: The old code computedsum(vertices) / count(vertices)— the arithmetic mean of polygon vertices, not the volumetric centroid. This is only correct for axis-aligned cuts. For any diagonal plane, the conservation lawCoV_below * V_below + CoV_above * V_above = (0,0,0)was violated.Sphere<float>compilation failure:VolumeBelowandCenterOfVolumeBelowhardcodedVector3d(0,0,0)instead ofVector3<T>::Zero. InstantiatingSphere<float>failed becausePlane<float>::Distance()has no overload acceptingVector3d.Improvements
max(0,x)^3terms, one divisionmax(0,x)^kevaluationsstd::vectorandstd::setper callstd::arraysTriangle3.hh,<vector>,<utility>,<set><array>,<cmath>WellOrderedVectors1e-3 tolerance (broke for boxes < ~0.002), triangle windingabs,max(0,x), and arithmetic; no tolerance parametersTest plan
BoxTest.VolumeBelowDiagonalPlanes: tetrahedron corner cut, non-unit normals, asymmetric box, tangent plane, very small box (exposes old 1e-3 tolerance bug), complementary planesBoxTest.CenterOfVolumeBelowDiagonal: direction check, tetrahedron centroid, symmetry, weighted-sum conservation, 2D normal (k=2 path), flipped 3D normal (sign transform)SphereTest.VolumeBelowFloat:Sphere<float>VolumeBelow + CenterOfVolumeBelow compile and produce correct resultsChecklist
codecheckpassed (See contributing)Generated-by: Opus 4.6
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.Backports: If this is a backport, please use Rebase and Merge instead.