diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index eec5d214473..4f8810d50e1 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -92,6 +92,9 @@ float volume_tetrahedron_signed_v3(const float v1[3], const float v3[3], const float v4[3]); +float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3]); +float volume_tri_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3]); + bool is_edge_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]); bool is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]); bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 27715ed49b5..ba2a8605dec 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -300,6 +300,25 @@ float volume_tetrahedron_signed_v3(const float v1[3], return determinant_m3_array(m) / 6.0f; } +/** + * The volume from a triangle that is made into a tetrahedron. + * This uses a simplified formula where the tip of the tetrahedron is in the world origin. + * Using this method, the total volume of a closed triangle mesh can be calculated. + * Note that you need to divide the result by 6 to get the actual volume. + */ +float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3]) +{ + float v_cross[3]; + cross_v3_v3v3(v_cross, v1, v2); + float tetra_volume = dot_v3v3(v_cross, v3); + return tetra_volume; +} + +float volume_tri_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3]) +{ + return volume_tri_tetrahedron_signed_v3_6x(v1, v2, v3) / 6.0f; +} + /********************************* Distance **********************************/ /* distance p to line v1-v2 |