diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-02-01 13:58:10 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-02-01 15:06:00 +0300 |
commit | 9fa628f35be31a18edfdb1e1fca8a6bd3b6b453c (patch) | |
tree | 999052f41e41117200da4bb1d177ffc6a7ff9fab /tests | |
parent | 8c7e1b648b782542c4906ccb849c39b167265558 (diff) |
mathutils: added exponential map to Quaternion
Added conversion to and from exponential map representation. This
representation is useful for interpolation of > 2 quaternions, or in
PD controllers.
Implementation in C functions quat_to_expmap,
quat_normalized_to_expmap, and expmap_to_quat with Python API, unit
tests and documentation.
Added Quaternion.to_exponential_map() and Quaternion(3-vector) to
Python API.
Reviewers: campbellbarton
Projects: #bf_blender
Differential Revision: https://developer.blender.org/D1049
Diffstat (limited to 'tests')
-rw-r--r-- | tests/python/bl_pyapi_mathutils.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/python/bl_pyapi_mathutils.py b/tests/python/bl_pyapi_mathutils.py index 85232e465d7..b7f61df0e40 100644 --- a/tests/python/bl_pyapi_mathutils.py +++ b/tests/python/bl_pyapi_mathutils.py @@ -2,7 +2,7 @@ # ./blender.bin --background -noaudio --python tests/python/bl_pyapi_mathutils.py -- --verbose import unittest -from mathutils import Matrix, Vector +from mathutils import Matrix, Vector, Quaternion from mathutils import kdtree import math @@ -210,6 +210,35 @@ class VectorTesting(unittest.TestCase): self.assertAlmostEqual(v.angle(v.orthogonal()), angle_90d) +class QuaternionTesting(unittest.TestCase): + + def test_to_expmap(self): + q = Quaternion((0, 0, 1), math.radians(90)) + + e = q.to_exponential_map() + self.assertAlmostEqual(e.x, 0) + self.assertAlmostEqual(e.y, 0) + self.assertAlmostEqual(e.z, math.radians(90), 6) + + def test_expmap_axis_normalization(self): + q = Quaternion((1, 1, 0), 2) + e = q.to_exponential_map() + + self.assertAlmostEqual(e.x, 2 * math.sqrt(0.5), 6) + self.assertAlmostEqual(e.y, 2 * math.sqrt(0.5), 6) + self.assertAlmostEqual(e.z, 0) + + def test_from_expmap(self): + e = Vector((1, 1, 0)) + q = Quaternion(e) + axis, angle = q.to_axis_angle() + + self.assertAlmostEqual(angle, math.sqrt(2), 6) + self.assertAlmostEqual(axis.x, math.sqrt(0.5), 6) + self.assertAlmostEqual(axis.y, math.sqrt(0.5), 6) + self.assertAlmostEqual(axis.z, 0) + + class KDTreeTesting(unittest.TestCase): @staticmethod |