[Bf-blender-cvs] [61b6b1f] temp-mathutils: minor edits to expmap functions

Campbell Barton noreply at git.blender.org
Sun Feb 1 12:38:51 CET 2015


Commit: 61b6b1fd4097750cd843f9a24708b935c2f32873
Author: Campbell Barton
Date:   Sun Feb 1 22:17:18 2015 +1100
Branches: temp-mathutils
https://developer.blender.org/rB61b6b1fd4097750cd843f9a24708b935c2f32873

minor edits to expmap functions

add quat_normalized_to_expmap incase we know the quats already unit length

===================================================================

M	source/blender/blenlib/BLI_math_rotation.h
M	source/blender/blenlib/intern/math_rotation.c
M	source/blender/python/mathutils/mathutils_Quaternion.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index c1ce6c9..fbd026f 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -121,6 +121,7 @@ void      angle_to_mat2(float R[2][2], const float angle);
 
 /****************************** Exponential Map ******************************/
 void quat_to_expmap(float expmap[3], const float q[4]);
+void quat_normalized_to_expmap(float expmap[3], const float q[4]);
 void expmap_to_quat(float r[4], const float expmap[3]);
 
 /******************************** XYZ Eulers *********************************/
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index f13d795..2d7388a 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -1017,23 +1017,30 @@ void angle_to_mat2(float mat[2][2], const float angle)
 }
 
 /****************************** Exponential Map ******************************/
-void quat_to_expmap(float expmap[3], const float q[4])
+
+void quat_normalized_to_expmap(float expmap[3], const float q[4])
 {
-	float quat[4];
 	float angle;
+	BLI_ASSERT_UNIT_QUAT(q);
 
 	/* Obtain axis/angle representation. */
-	normalize_qt_qt(quat, q);
-	quat_to_axis_angle(expmap, &angle, quat);
+	quat_to_axis_angle(expmap, &angle, q);
 
 	/* Convert to exponential map. */
 	mul_vn_fl(expmap, 3, angle);
 }
 
+void quat_to_expmap(float expmap[3], const float q[4])
+{
+	float q_no[4];
+	normalize_qt_qt(q_no, q);
+	quat_normalized_to_expmap(expmap, q_no);
+}
+
 void expmap_to_quat(float r[4], const float expmap[3])
 {
-	float angle;
 	float axis[3];
+	float angle;
 
 	/* Obtain axis/angle representation. */
 	angle = normalize_v3_v3(axis, expmap);
diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c
index 48f8e53..786a932 100644
--- a/source/blender/python/mathutils/mathutils_Quaternion.c
+++ b/source/blender/python/mathutils/mathutils_Quaternion.c
@@ -182,9 +182,8 @@ PyDoc_STRVAR(Quaternion_to_exponential_map_doc,
 "\n"
 "   Return the exponential map representation of the quaternion.\n"
 "\n"
-"   This representation consist of the rotation axis multiplied by the rotation\n"
-"   angle. Such a representation is useful for interpolation between multiple\n"
-"   orientations.\n"
+"   This representation consist of the rotation axis multiplied by the rotation angle."
+"   Such a representation is useful for interpolation between multiple orientations.\n"
 "\n"
 "   :return: exponential map.\n"
 "   :rtype: :class:`Vector` of size 3\n"
@@ -1101,11 +1100,21 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
 			break;
 		case 1:
 		{
-			/* Single argument, must be 3-vector or 4-vector. */
 			int size;
-			if ((size = mathutils_array_parse(quat, 3, QUAT_SIZE, seq, "mathutils.Quaternion()")) == -1)
+
+			if ((size = mathutils_array_parse(quat, 3, QUAT_SIZE, seq, "mathutils.Quaternion()")) == -1) {
 				return NULL;
-			if (size == 3) expmap_to_quat(quat, quat);
+			}
+
+			if (size == 4) {
+				/* 4d: Quaternion (common case) */
+			}
+			else {
+				/* 3d: Interpret as exponential map */
+				BLI_assert(size == 3);
+				expmap_to_quat(quat, quat);
+			}
+
 			break;
 		}
 		case 2:




More information about the Bf-blender-cvs mailing list