[Bf-blender-cvs] [9c48ea3] master: Math Lib: add function to get signed angle about an axis
Campbell Barton
noreply at git.blender.org
Wed Jul 9 03:17:33 CEST 2014
Commit: 9c48ea3979f5b3f8ede7a4f830a745cf9cff2dbb
Author: Campbell Barton
Date: Wed Jul 9 11:15:08 2014 +1000
https://developer.blender.org/rB9c48ea3979f5b3f8ede7a4f830a745cf9cff2dbb
Math Lib: add function to get signed angle about an axis
===================================================================
M source/blender/blenlib/BLI_math_vector.h
M source/blender/blenlib/intern/math_vector.c
===================================================================
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index aa103c9..942097e 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -251,6 +251,7 @@ float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WA
float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]) ATTR_WARN_UNUSED_RESULT;
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT;
float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT;
+float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT;
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]);
void angle_poly_v3(float *angles, const float *verts[3], int len);
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 7cbbaaf..15b88fe 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -467,6 +467,32 @@ float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float
return angle_v3v3(v1_proj, v2_proj);
}
+float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3])
+{
+ float v1_proj[3], v2_proj[3], tproj[3];
+ float angle;
+
+ sub_v3_v3v3(v1_proj, v1, v2);
+ sub_v3_v3v3(v2_proj, v3, v2);
+
+ /* project the vectors onto the axis */
+ project_v3_v3v3(tproj, v1_proj, axis);
+ sub_v3_v3(v1_proj, tproj);
+
+ project_v3_v3v3(tproj, v2_proj, axis);
+ sub_v3_v3(v2_proj, tproj);
+
+ angle = angle_v3v3(v1_proj, v2_proj);
+
+ /* calculate the sign (reuse 'tproj') */
+ cross_v3_v3v3(tproj, v2_proj, v1_proj);
+ if (dot_v3v3(tproj, axis) < 0.0f) {
+ angle = ((float)(M_PI * 2.0)) - angle;
+ }
+
+ return angle;
+}
+
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];
More information about the Bf-blender-cvs
mailing list