Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-12-15 12:39:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-12-15 12:39:46 +0300
commit7fc799d4a9c52254390e5df2942c73831ca7e5ac (patch)
treec265c60e3cff3913d280f6229b9eae01cc91e44b /source/blender/blenlib
parent55898c04fd4935de5610242bfb259f30e58b0413 (diff)
utility functions for getting the corner angles of a quad or tri: angle_quad_v3 & angle_tri_v3
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_vector.h2
-rw-r--r--source/blender/blenlib/intern/math_vector.c38
2 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 399c234a108..e915a9a85f3 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -131,6 +131,8 @@ float angle_normalized_v2v2(float a[2], float b[2]);
float angle_v3v3(float a[2], float b[2]);
float angle_v3v3v3(float a[2], float b[2], float c[2]);
float angle_normalized_v3v3(float a[3], float b[3]);
+void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
+void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
/********************************* Geometry **********************************/
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 289d8818753..2ce4a069a48 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -205,6 +205,44 @@ float angle_normalized_v2v2(float *v1, float *v2)
return 2.0f*(float)saasin(len_v2v2(v2, v1)/2.0f);
}
+void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3])
+{
+ float ed1[3], ed2[3], ed3[3];
+
+ sub_v3_v3v3(ed1, v3, v1);
+ sub_v3_v3v3(ed2, v1, v2);
+ sub_v3_v3v3(ed3, v2, v3);
+
+ normalize_v3(ed1);
+ normalize_v3(ed2);
+ normalize_v3(ed3);
+
+ angles[0]= M_PI - angle_normalized_v3v3(ed1, ed2);
+ angles[1]= M_PI - angle_normalized_v3v3(ed2, ed3);
+ // face_angles[2] = M_PI - angle_normalized_v3v3(ed3, ed1);
+ angles[2]= M_PI - (angles[0] + angles[1]);
+}
+
+void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
+{
+ float ed1[3], ed2[3], ed3[3], ed4[3];
+
+ sub_v3_v3v3(ed1, v4, v1);
+ sub_v3_v3v3(ed2, v1, v2);
+ sub_v3_v3v3(ed3, v2, v3);
+ sub_v3_v3v3(ed4, v3, v4);
+
+ normalize_v3(ed1);
+ normalize_v3(ed2);
+ normalize_v3(ed3);
+ normalize_v3(ed4);
+
+ angles[0]= M_PI - angle_normalized_v3v3(ed1, ed2);
+ angles[1]= M_PI - angle_normalized_v3v3(ed2, ed3);
+ angles[2]= M_PI - angle_normalized_v3v3(ed3, ed4);
+ angles[3]= M_PI - angle_normalized_v3v3(ed4, ed1);
+}
+
/********************************* Geometry **********************************/
/* Project v1 on v2 */