mailr9477 - /1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on September 08, 2009 - 17:07:
Author: bugman
Date: Tue Sep  8 17:07:06 2009
New Revision: 9477

URL: http://svn.gna.org/viewcvs/relax?rev=9477&view=rev
Log:
Created 3 unit tests of the maths_fns.rotation_matrix.R_axis_angle() function.

These are almost identical to those of quaternion_to_R().


Modified:
    1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py

Modified: 1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py?rev=9477&r1=9476&r2=9477&view=diff
==============================================================================
--- 1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py (original)
+++ 1.3/test_suite/unit_tests/_maths_fns/test_rotation_matrix.py Tue Sep  8 
17:07:06 2009
@@ -243,12 +243,38 @@
             self.assertAlmostEqual(z_new[i], z_real[i])
 
 
-    def test_R_euler_zyz_alpha_30(self):
-        """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
-
-        # Generate the rotation matrix.
-        R = zeros((3, 3), float64)
-        R_euler_zyz(R, pi/6, 0.0, 0.0)
+    def test_R_axis_angle_no_rot(self):
+        """Test the quaternion to rotation matrix conversion for a zero 
angle rotation."""
+
+        # Quaternion of zero angle.
+        axis = array([-1, 1, 1], float64) / sqrt(3)
+        angle = 0.0
+
+        # The rotation matrix.
+        R = zeros((3, 3), float64)
+        R_axis_angle(R, axis, angle)
+        print("Rotation matrix:\n%s" % R)
+
+        # The correct result.
+        R_true = eye(3)
+
+        # Checks.
+        for i in range(3):
+            for j in range(3):
+                self.assertEqual(R[i, j], R_true[i, j])
+
+
+    def test_R_axis_angle_z_30(self):
+        """Test the quaternion to rotation matrix conversion for a 30 degree 
rotation about z."""
+
+        # Axis-angle values.
+        axis = array([0, 0, 1], float64)
+        angle = pi / 6
+
+        # Generate the rotation matrix.
+        R = zeros((3, 3), float64)
+        R_axis_angle(R, axis, angle)
+        print("Rotation matrix:\n%s" % R)
 
         # Axes.
         x_axis = array([1, 0, 0], float64)
@@ -276,9 +302,9 @@
 
         # Checks.
         for i in range(3):
-            self.assertEqual(x_new[i], x_real[i])
-            self.assertEqual(y_new[i], y_real[i])
-            self.assertEqual(z_new[i], z_real[i])
+            self.assertAlmostEqual(x_new[i], x_real[i])
+            self.assertAlmostEqual(y_new[i], y_real[i])
+            self.assertAlmostEqual(z_new[i], z_real[i])
 
         # Axes (do everything again, this time negative!).
         x_axis = array([-1, 0, 0], float64)
@@ -306,17 +332,22 @@
 
         # Checks.
         for i in range(3):
-            self.assertEqual(x_new[i], x_real[i])
-            self.assertEqual(y_new[i], y_real[i])
-            self.assertEqual(z_new[i], z_real[i])
-
-
-    def test_R_euler_zyz_beta_45(self):
-        """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
-
-        # Generate the rotation matrix.
-        R = zeros((3, 3), float64)
-        R_euler_zyz(R, 0.0, pi/4, 0.0)
+            self.assertAlmostEqual(x_new[i], x_real[i])
+            self.assertAlmostEqual(y_new[i], y_real[i])
+            self.assertAlmostEqual(z_new[i], z_real[i])
+
+
+    def test_R_axis_angle_180_complex(self):
+        """Test the quaternion to rotation matrix conversion for a 180 
degree rotation about [1, 1, 1]."""
+
+        # Axis-angle values.
+        axis = array([1, 1, 1], float64) / sqrt(3)
+        angle = 2 * pi / 3
+
+        # Generate the rotation matrix.
+        R = zeros((3, 3), float64)
+        R_axis_angle(R, axis, angle)
+        print("Rotation matrix:\n%s" % R)
 
         # Axes.
         x_axis = array([1, 0, 0], float64)
@@ -324,29 +355,29 @@
         z_axis = array([0, 0, 1], float64)
 
         # Rotated axis (real values).
-        x_real = array([cos(pi/4), 0, -sin(pi/4)], float64)
-        y_real = array([0, 1, 0], float64)
-        z_real = array([sin(pi/4), 0, cos(pi/4)], float64)
-
-        # Rotation.
-        x_new = dot(R, x_axis)
-        y_new = dot(R, y_axis)
-        z_new = dot(R, z_axis)
-
-        # Print out.
-        print("Rotated and true axes (beta = pi/4):")
-        print(("x rot:  %s" % x_new))
-        print(("x real: %s\n" % x_real))
-        print(("y rot:  %s" % y_new))
-        print(("y real: %s\n" % y_real))
-        print(("z rot:  %s" % z_new))
-        print(("z real: %s\n" % z_real))
-
-        # Checks.
-        for i in range(3):
-            self.assertEqual(x_new[i], x_real[i])
-            self.assertEqual(y_new[i], y_real[i])
-            self.assertEqual(z_new[i], z_real[i])
+        x_real = array([0, 1, 0], float64)
+        y_real = array([0, 0, 1], float64)
+        z_real = array([1, 0, 0], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertAlmostEqual(x_new[i], x_real[i])
+            self.assertAlmostEqual(y_new[i], y_real[i])
+            self.assertAlmostEqual(z_new[i], z_real[i])
 
         # Axes (do everything again, this time negative!).
         x_axis = array([-1, 0, 0], float64)
@@ -354,37 +385,37 @@
         z_axis = array([0, 0, -1], float64)
 
         # Rotated axis (real values).
-        x_real = array([-cos(pi/4), 0, sin(pi/4)], float64)
-        y_real = array([0, -1, 0], float64)
-        z_real = array([-sin(pi/4), 0, -cos(pi/4)], float64)
-
-        # Rotation.
-        x_new = dot(R, x_axis)
-        y_new = dot(R, y_axis)
-        z_new = dot(R, z_axis)
-
-        # Print out.
-        print("Rotated and true axes (beta = pi/4):")
-        print(("x rot:  %s" % x_new))
-        print(("x real: %s\n" % x_real))
-        print(("y rot:  %s" % y_new))
-        print(("y real: %s\n" % y_real))
-        print(("z rot:  %s" % z_new))
-        print(("z real: %s\n" % z_real))
-
-        # Checks.
-        for i in range(3):
-            self.assertEqual(x_new[i], x_real[i])
-            self.assertEqual(y_new[i], y_real[i])
-            self.assertEqual(z_new[i], z_real[i])
-
-
-    def test_R_euler_zyz_gamma_15(self):
+        x_real = array([0, -1, 0], float64)
+        y_real = array([0, 0, -1], float64)
+        z_real = array([-1, 0, 0], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertAlmostEqual(x_new[i], x_real[i])
+            self.assertAlmostEqual(y_new[i], y_real[i])
+            self.assertAlmostEqual(z_new[i], z_real[i])
+
+
+    def test_R_euler_zyz_alpha_30(self):
         """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
 
         # Generate the rotation matrix.
         R = zeros((3, 3), float64)
-        R_euler_zyz(R, 0.0, 0.0, pi/12)
+        R_euler_zyz(R, pi/6, 0.0, 0.0)
 
         # Axes.
         x_axis = array([1, 0, 0], float64)
@@ -392,8 +423,8 @@
         z_axis = array([0, 0, 1], float64)
 
         # Rotated axis (real values).
-        x_real = array([cos(pi/12), sin(pi/12), 0], float64)
-        y_real = array([-sin(pi/12), cos(pi/12), 0], float64)
+        x_real = array([cos(pi/6), sin(pi/6), 0], float64)
+        y_real = array([-sin(pi/6), cos(pi/6), 0], float64)
         z_real = array([0, 0, 1], float64)
 
         # Rotation.
@@ -422,8 +453,8 @@
         z_axis = array([0, 0, -1], float64)
 
         # Rotated axis (real values).
-        x_real = array([-cos(pi/12), -sin(pi/12), 0], float64)
-        y_real = array([sin(pi/12), -cos(pi/12), 0], float64)
+        x_real = array([-cos(pi/6), -sin(pi/6), 0], float64)
+        y_real = array([sin(pi/6), -cos(pi/6), 0], float64)
         z_real = array([0, 0, -1], float64)
 
         # Rotation.
@@ -444,14 +475,15 @@
         for i in range(3):
             self.assertEqual(x_new[i], x_real[i])
             self.assertEqual(y_new[i], y_real[i])
-
-
-    def test_R_euler_zyz_alpha_15_gamma_15(self):
+            self.assertEqual(z_new[i], z_real[i])
+
+
+    def test_R_euler_zyz_beta_45(self):
         """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
 
         # Generate the rotation matrix.
         R = zeros((3, 3), float64)
-        R_euler_zyz(R, pi/12, 0.0, pi/12)
+        R_euler_zyz(R, 0.0, pi/4, 0.0)
 
         # Axes.
         x_axis = array([1, 0, 0], float64)
@@ -459,9 +491,9 @@
         z_axis = array([0, 0, 1], float64)
 
         # Rotated axis (real values).
-        x_real = array([cos(pi/6), sin(pi/6), 0], float64)
-        y_real = array([-sin(pi/6), cos(pi/6), 0], float64)
-        z_real = array([0, 0, 1], float64)
+        x_real = array([cos(pi/4), 0, -sin(pi/4)], float64)
+        y_real = array([0, 1, 0], float64)
+        z_real = array([sin(pi/4), 0, cos(pi/4)], float64)
 
         # Rotation.
         x_new = dot(R, x_axis)
@@ -489,6 +521,141 @@
         z_axis = array([0, 0, -1], float64)
 
         # Rotated axis (real values).
+        x_real = array([-cos(pi/4), 0, sin(pi/4)], float64)
+        y_real = array([0, -1, 0], float64)
+        z_real = array([-sin(pi/4), 0, -cos(pi/4)], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertEqual(x_new[i], x_real[i])
+            self.assertEqual(y_new[i], y_real[i])
+            self.assertEqual(z_new[i], z_real[i])
+
+
+    def test_R_euler_zyz_gamma_15(self):
+        """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
+
+        # Generate the rotation matrix.
+        R = zeros((3, 3), float64)
+        R_euler_zyz(R, 0.0, 0.0, pi/12)
+
+        # Axes.
+        x_axis = array([1, 0, 0], float64)
+        y_axis = array([0, 1, 0], float64)
+        z_axis = array([0, 0, 1], float64)
+
+        # Rotated axis (real values).
+        x_real = array([cos(pi/12), sin(pi/12), 0], float64)
+        y_real = array([-sin(pi/12), cos(pi/12), 0], float64)
+        z_real = array([0, 0, 1], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertEqual(x_new[i], x_real[i])
+            self.assertEqual(y_new[i], y_real[i])
+            self.assertEqual(z_new[i], z_real[i])
+
+        # Axes (do everything again, this time negative!).
+        x_axis = array([-1, 0, 0], float64)
+        y_axis = array([0, -1, 0], float64)
+        z_axis = array([0, 0, -1], float64)
+
+        # Rotated axis (real values).
+        x_real = array([-cos(pi/12), -sin(pi/12), 0], float64)
+        y_real = array([sin(pi/12), -cos(pi/12), 0], float64)
+        z_real = array([0, 0, -1], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertEqual(x_new[i], x_real[i])
+            self.assertEqual(y_new[i], y_real[i])
+
+
+    def test_R_euler_zyz_alpha_15_gamma_15(self):
+        """Test the rotation matrix from zyz Euler angle conversion using a 
beta angle of pi/4."""
+
+        # Generate the rotation matrix.
+        R = zeros((3, 3), float64)
+        R_euler_zyz(R, pi/12, 0.0, pi/12)
+
+        # Axes.
+        x_axis = array([1, 0, 0], float64)
+        y_axis = array([0, 1, 0], float64)
+        z_axis = array([0, 0, 1], float64)
+
+        # Rotated axis (real values).
+        x_real = array([cos(pi/6), sin(pi/6), 0], float64)
+        y_real = array([-sin(pi/6), cos(pi/6), 0], float64)
+        z_real = array([0, 0, 1], float64)
+
+        # Rotation.
+        x_new = dot(R, x_axis)
+        y_new = dot(R, y_axis)
+        z_new = dot(R, z_axis)
+
+        # Print out.
+        print("Rotated and true axes (beta = pi/4):")
+        print(("x rot:  %s" % x_new))
+        print(("x real: %s\n" % x_real))
+        print(("y rot:  %s" % y_new))
+        print(("y real: %s\n" % y_real))
+        print(("z rot:  %s" % z_new))
+        print(("z real: %s\n" % z_real))
+
+        # Checks.
+        for i in range(3):
+            self.assertEqual(x_new[i], x_real[i])
+            self.assertEqual(y_new[i], y_real[i])
+            self.assertEqual(z_new[i], z_real[i])
+
+        # Axes (do everything again, this time negative!).
+        x_axis = array([-1, 0, 0], float64)
+        y_axis = array([0, -1, 0], float64)
+        z_axis = array([0, 0, -1], float64)
+
+        # Rotated axis (real values).
         x_real = array([-cos(pi/6), -sin(pi/6), 0], float64)
         y_real = array([sin(pi/6), -cos(pi/6), 0], float64)
         z_real = array([0, 0, -1], float64)




Related Messages


Powered by MHonArc, Updated Tue Sep 08 18:00:02 2009