diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-19 16:12:50 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-19 16:17:10 +0400 |
commit | a51a0ca772b21814e29bdb3b2b5fd854e29c5334 (patch) | |
tree | 134e4517c0a8cbd2ee05bb56d223e0922820e06e /source/blender/blenlib/intern/math_geom_inline.c | |
parent | 9c93c0bf08c0bc73d2c09e7f8c57721b557eb222 (diff) |
Math Lib: add shell_v3v3_normalized_to_dist and v2 version
bypass angle calculation to avoids (asin, sqrt, cos).
Diffstat (limited to 'source/blender/blenlib/intern/math_geom_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom_inline.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 0e243c5e198..1e54dd11a76 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -34,6 +34,9 @@ #include <string.h> +/* A few small defines. Keep'em local! */ +#define SMALL_NUMBER 1.e-8f + /********************************** Polygons *********************************/ MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2]) @@ -227,4 +230,35 @@ MINLINE float plane_point_side_v3(const float plane[4], const float co[3]) return dot_v3v3(co, plane) + plane[3]; } +/* useful to calculate an even width shell, by taking the angle between 2 planes. + * The return value is a scale on the offset. + * no angle between planes is 1.0, as the angle between the 2 planes approaches 180d + * the distance gets very high, 180d would be inf, but this case isn't valid */ +MINLINE float shell_angle_to_dist(const float angle) +{ + return (UNLIKELY(angle < SMALL_NUMBER)) ? 1.0f : fabsf(1.0f / cosf(angle)); +} +/** + * equivalent to ``shell_angle_to_dist(angle_normalized_v3v3(a, b))`` + */ +MINLINE float shell_v3v3_normalized_to_dist(const float a[3], const float b[3]) +{ + const float angle_cos = fabsf(dot_v3v3(a, b)); + BLI_ASSERT_UNIT_V3(a); + BLI_ASSERT_UNIT_V3(b); + return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos); +} +/** + * equivalent to ``shell_angle_to_dist(angle_normalized_v2v2(a, b))`` + */ +MINLINE float shell_v2v2_normalized_to_dist(const float a[2], const float b[2]) +{ + const float angle_cos = fabsf(dot_v2v2(a, b)); + BLI_ASSERT_UNIT_V2(a); + BLI_ASSERT_UNIT_V2(b); + return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos); +} + +#undef SMALL_NUMBER + #endif /* __MATH_GEOM_INLINE_C__ */ |