Skip to content

Commit

Permalink
Merge pull request #1061 from Geode-solutions/volume_to_edge_quality_…
Browse files Browse the repository at this point in the history
…metric

feat(Geometry): adding new tetrahedron quality metric (volume to edge ratio).
  • Loading branch information
MelchiorSchuh authored Dec 12, 2024
2 parents 52b9616 + a465b72 commit e01c8df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/geode/geometry/quality.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ namespace geode
{
[[nodiscard]] double opengeode_geometry_api tetrahedron_aspect_ratio(
const Tetrahedron& tetra );
[[nodiscard]] double opengeode_geometry_api
tetrahedron_volume_to_edge_ratio( const Tetrahedron& tetra );
} // namespace geode
23 changes: 23 additions & 0 deletions src/geode/geometry/quality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <limits>

#include <geode/geometry/basic_objects/tetrahedron.hpp>
#include <geode/geometry/mensuration.hpp>
#include <geode/geometry/vector.hpp>

namespace geode
Expand Down Expand Up @@ -64,4 +65,26 @@ namespace geode
constant * longest_edge_length * total_area2 / absolute_det;
return aspect_ratio;
}

double tetrahedron_volume_to_edge_ratio( const Tetrahedron& tetra )
{
const auto signed_volume = geode::tetrahedron_signed_volume( tetra );
double sq_len{ 0 };
const auto& vertices = tetra.vertices();
for( const auto v0 : geode::LRange{ 3 } )
{
const auto& point0 = vertices[v0].get();
for( const auto v1 : geode::LRange{ v0, 4 } )
{
const auto& point1 = vertices[v1].get();
for( const auto d : geode::LRange{ 3 } )
{
const auto diff = point0.value( d ) - point1.value( d );
sq_len += diff * diff;
}
}
}
const auto l_rms = std::sqrt( sq_len / 6 );
return 6 * std::sqrt( 2 ) * signed_volume / ( l_rms * l_rms * l_rms );
}
} // namespace geode

0 comments on commit e01c8df

Please sign in to comment.