diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-07-11 14:06:13 +0400 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2014-07-11 14:16:32 +0400 |
commit | 4633e655dc59b68d622e3319102d5050245a22eb (patch) | |
tree | 08982a589dd5a3e96fbf342c8319fe46ad65d642 /source/blender/blenlib | |
parent | 78d38a90332027609933be102e61438cb4c7f9f0 (diff) |
Fix T41019: Calculate Mass does not calculate actual volume.
This was a ToDo item, for mesh-based rigid body shapes (trimesh, convex)
the operator was simply using the bounding box volume, which can grossly
overestimate the volume and mass.
Calculating the actual volume of a mesh is not so difficult after all,
see e.g.
http://research.microsoft.com/en-us/um/people/chazhang/publications/icip01_ChaZhang.pdf
This patch also allows calculating the center-of-mass in the same way.
This is currently unused, because the rigid body system assumes the CoM
to be the same as the geometric object center. This is fine most of the
time, adding such user settings for "center-of-mass offset" would also
add quite a bit of complexity in user space, but it could be necessary
at some point. A number of other physical properties could be calculated
using the same principle, e.g. the moment of inertia.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index f4bcc810846..ed0777aceea 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -72,6 +72,7 @@ MINLINE float plane_point_side_v3(const float plane[4], const float co[3]); /********************************* Volume **********************************/ float volume_tetrahedron_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]); +float volume_tetrahedron_signed_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 5f3ab5eb73e..efb881cde1b 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -238,6 +238,18 @@ float volume_tetrahedron_v3(const float v1[3], const float v2[3], const float v3 return fabsf(determinant_m3_array(m)) / 6.0f; } +/** + * The volume from a tetrahedron, normal pointing inside gives negative volume + */ +float volume_tetrahedron_signed_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]) +{ + float m[3][3]; + sub_v3_v3v3(m[0], v1, v2); + sub_v3_v3v3(m[1], v2, v3); + sub_v3_v3v3(m[2], v3, v4); + return determinant_m3_array(m) / 6.0f; +} + /********************************* Distance **********************************/ |