diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2012-06-24 20:19:19 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2012-06-24 20:19:19 +0400 |
commit | df9ca0455c281ffba785a27f9cfd95135195f906 (patch) | |
tree | f7e7ec12c818406556914ce095d481ac5a0198c1 /source/blender/blenlib/intern/math_vector.c | |
parent | e60c2f5c3e8945b4829171cd436fe15518fb916e (diff) |
Fix [#31807] Ngon triangulation error
Notes:
*This implements a quite simple algorithm, which simply checks angles (actually, absolute cosines) of created tri and remaining face (which may be a tri, quad, or more NGon), so that both are "best" (ie avoid as much as possible too much narrow/wide corners), and also checks the new edge is OK (i.e. does not goes "out" of original face).
*Incidently, it fixes a typo in that bm_face_goodline() func!
*It's quite performant (a bit quicker than previous code, as far as I have tested it) and prevent creation of completely flat triangles as much as possible, but it's far from being a "best" solution (as it is still a "progressive" one)!
*It also introduces a new math func (in BLI_math_vector.h), cos_v3v3v3, which computes cosine (ie dot product of normalized vectors) and is roughly a quicker replacement for angle_v3v3v3, when real angles are not needed.
Diffstat (limited to 'source/blender/blenlib/intern/math_vector.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index d939576904e..5cda1c0b81f 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -136,6 +136,19 @@ float angle_v3v3v3(const float v1[3], const float v2[3], const float v3[3]) return angle_normalized_v3v3(vec1, vec2); } +/* Quicker than full angle computation */ +float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]) +{ + float vec1[3], vec2[3]; + + sub_v3_v3v3(vec1, p2, p1); + sub_v3_v3v3(vec2, p2, p3); + normalize_v3(vec1); + normalize_v3(vec2); + + return dot_v3v3(vec1, vec2); +} + /* Return the shortest angle in radians between the 2 vectors */ float angle_v3v3(const float v1[3], const float v2[3]) { |