mailr9487 - /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 - 21:07:
Author: bugman
Date: Tue Sep  8 21:07:41 2009
New Revision: 9487

URL: http://svn.gna.org/viewcvs/relax?rev=9487&view=rev
Log:
Added a unit test to bounce around all the conversion functions in 
maths_fns.rotation_matrix.

This bounces through:
    1) euler_zyz_to_R().
    2) R_to_axis_angle().
    3) axis_angle_to_quaternion().
    4) quaternion_to_axis_angle().
    5) axis_angle_to_R().
    6) R_to_quaternion().
    7) quaternion_to_R().
    8) R_to_euler_zyz().


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=9487&r1=9486&r2=9487&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 
21:07:41 2009
@@ -201,122 +201,8 @@
         self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
 
 
-    def test_euler_zyz_to_R_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)
-        euler_zyz_to_R(pi/6, 0.0, 0.0, R)
-
-        # Rotated pos axes (real values).
-        x_real_pos = array([cos(pi/6), sin(pi/6), 0], float64)
-        y_real_pos = array([-sin(pi/6), cos(pi/6), 0], float64)
-        z_real_pos = array([0, 0, 1], float64)
-
-        # Rotated neg axes (real values).
-        x_real_neg = array([-cos(pi/6), -sin(pi/6), 0], float64)
-        y_real_neg = array([sin(pi/6), -cos(pi/6), 0], float64)
-        z_real_neg = array([0, 0, -1], float64)
-
-        # Check the rotation.
-        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
-
-
-    def test_euler_zyz_to_R_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)
-        euler_zyz_to_R(0.0, pi/4, 0.0, R)
-
-        # Rotated pos axes (real values).
-        x_real_pos = array([cos(pi/4), 0, -sin(pi/4)], float64)
-        y_real_pos = array([0, 1, 0], float64)
-        z_real_pos = array([sin(pi/4), 0, cos(pi/4)], float64)
-
-        # Rotated neg axes (real values).
-        x_real_neg = array([-cos(pi/4), 0, sin(pi/4)], float64)
-        y_real_neg = array([0, -1, 0], float64)
-        z_real_neg = array([-sin(pi/4), 0, -cos(pi/4)], float64)
-
-        # Check the rotation.
-        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
-
-
-    def test_euler_zyz_to_R_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)
-        euler_zyz_to_R(0.0, 0.0, pi/12, R)
-
-        # Rotated pos axes (real values).
-        x_real_pos = array([cos(pi/12), sin(pi/12), 0], float64)
-        y_real_pos = array([-sin(pi/12), cos(pi/12), 0], float64)
-        z_real_pos = array([0, 0, 1], float64)
-
-        # Rotated neg axes (real values).
-        x_real_neg = array([-cos(pi/12), -sin(pi/12), 0], float64)
-        y_real_neg = array([sin(pi/12), -cos(pi/12), 0], float64)
-        z_real_neg = array([0, 0, -1], float64)
-
-        # Check the rotation.
-        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
-
-
-    def test_euler_zyz_to_R_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)
-        euler_zyz_to_R(pi/12, 0.0, pi/12, R)
-
-        # Rotated pos axes (real values).
-        x_real_pos = array([cos(pi/6), sin(pi/6), 0], float64)
-        y_real_pos = array([-sin(pi/6), cos(pi/6), 0], float64)
-        z_real_pos = array([0, 0, 1], float64)
-
-        # Rotated neg axes (real values).
-        x_real_neg = array([-cos(pi/6), -sin(pi/6), 0], float64)
-        y_real_neg = array([sin(pi/6), -cos(pi/6), 0], float64)
-        z_real_neg = array([0, 0, -1], float64)
-
-        # Check the rotation.
-        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
-
-
-    def test_R_to_axis_angle_no_rot(self):
-        """Test the rotation matrix to axis-angle conversion."""
-
-        # Generate the rotation matrix.
-        R = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], float64)
-
-        # Get the axis and angle.
-        axis, angle = R_to_axis_angle(R)
-
-        # Test the angle.
-        self.assertEqual(angle, 0.0)
-
-
-    def test_R_to_axis_angle_180_complex(self):
-        """Test the rotation matrix to axis-angle conversion."""
-
-        # Generate the rotation matrix.
-        R = array([[0, 0, 1], [1, 0, 0], [0, 1, 0]], float64)
-
-        # Get the axis and angle.
-        axis, angle = R_to_axis_angle(R)
-
-        # Test the angle.
-        self.assertEqual(angle, 2 * pi / 3)
-
-        # Test the vector.
-        for i in range(3):
-            self.assertAlmostEqual(axis[i], 1.0/sqrt(3))
-
-
-    def test_R_to_euler_zyz(self):
-        """Test the rotation matrix to zyz Euler angle conversion."""
+    def test_euler_zyz_to_euler_zyz(self):
+        """Bounce around all the conversion functions to see if the original 
angles are returned."""
 
         # Starting angles.
         alpha = uniform(0, 2*pi)
@@ -329,12 +215,35 @@
         print(("beta: %s" % beta))
         print(("gamma: %s\n" % gamma))
 
-        # Generate the rotation matrix.
-        R = zeros((3, 3), float64)
+        # Init.
+        axis = zeros(3, float64)
+        quat = zeros(4, float64)
+        R = zeros((3, 3), float64)
+
+        # 1) Euler angles to rotation matrix.
         euler_zyz_to_R(alpha, beta, gamma, R)
 
-        # Get back the angles.
+        # 2) Rotation matrix to axis-angle.
+        axis, angle = R_to_axis_angle(R)
+
+        # 3) Axis-angle to quaternion.
+        axis_angle_to_quaternion(axis, angle, quat)
+
+        # 4) Quaternion to axis-angle.
+        axis, angle = quaternion_to_axis_angle(quat)
+
+        # 5) Axis-angle to rotation matrix.
+        axis_angle_to_R(axis, angle, R)
+
+        # 6) Rotation matrix to quaternion.
+        R_to_quaternion(R, quat)
+
+        # 7) Quaternion to rotation matrix.
+        quaternion_to_R(quat, R)
+
+        # 8) Rotation matrix to Euler angles.
         alpha_new, beta_new, gamma_new = R_to_euler_zyz(R)
+
 
         # Wrap the angles.
         alpha_new = wrap_angles(alpha_new, 0, 2*pi)
@@ -353,6 +262,158 @@
         self.assertAlmostEqual(gamma, gamma_new)
 
 
+    def test_euler_zyz_to_R_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)
+        euler_zyz_to_R(pi/6, 0.0, 0.0, R)
+
+        # Rotated pos axes (real values).
+        x_real_pos = array([cos(pi/6), sin(pi/6), 0], float64)
+        y_real_pos = array([-sin(pi/6), cos(pi/6), 0], float64)
+        z_real_pos = array([0, 0, 1], float64)
+
+        # Rotated neg axes (real values).
+        x_real_neg = array([-cos(pi/6), -sin(pi/6), 0], float64)
+        y_real_neg = array([sin(pi/6), -cos(pi/6), 0], float64)
+        z_real_neg = array([0, 0, -1], float64)
+
+        # Check the rotation.
+        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
+
+
+    def test_euler_zyz_to_R_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)
+        euler_zyz_to_R(0.0, pi/4, 0.0, R)
+
+        # Rotated pos axes (real values).
+        x_real_pos = array([cos(pi/4), 0, -sin(pi/4)], float64)
+        y_real_pos = array([0, 1, 0], float64)
+        z_real_pos = array([sin(pi/4), 0, cos(pi/4)], float64)
+
+        # Rotated neg axes (real values).
+        x_real_neg = array([-cos(pi/4), 0, sin(pi/4)], float64)
+        y_real_neg = array([0, -1, 0], float64)
+        z_real_neg = array([-sin(pi/4), 0, -cos(pi/4)], float64)
+
+        # Check the rotation.
+        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
+
+
+    def test_euler_zyz_to_R_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)
+        euler_zyz_to_R(0.0, 0.0, pi/12, R)
+
+        # Rotated pos axes (real values).
+        x_real_pos = array([cos(pi/12), sin(pi/12), 0], float64)
+        y_real_pos = array([-sin(pi/12), cos(pi/12), 0], float64)
+        z_real_pos = array([0, 0, 1], float64)
+
+        # Rotated neg axes (real values).
+        x_real_neg = array([-cos(pi/12), -sin(pi/12), 0], float64)
+        y_real_neg = array([sin(pi/12), -cos(pi/12), 0], float64)
+        z_real_neg = array([0, 0, -1], float64)
+
+        # Check the rotation.
+        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
+
+
+    def test_euler_zyz_to_R_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)
+        euler_zyz_to_R(pi/12, 0.0, pi/12, R)
+
+        # Rotated pos axes (real values).
+        x_real_pos = array([cos(pi/6), sin(pi/6), 0], float64)
+        y_real_pos = array([-sin(pi/6), cos(pi/6), 0], float64)
+        z_real_pos = array([0, 0, 1], float64)
+
+        # Rotated neg axes (real values).
+        x_real_neg = array([-cos(pi/6), -sin(pi/6), 0], float64)
+        y_real_neg = array([sin(pi/6), -cos(pi/6), 0], float64)
+        z_real_neg = array([0, 0, -1], float64)
+
+        # Check the rotation.
+        self.check_rotation(R, x_real_pos, y_real_pos, z_real_pos, 
x_real_neg, y_real_neg, z_real_neg)
+
+
+    def test_R_to_axis_angle_no_rot(self):
+        """Test the rotation matrix to axis-angle conversion."""
+
+        # Generate the rotation matrix.
+        R = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], float64)
+
+        # Get the axis and angle.
+        axis, angle = R_to_axis_angle(R)
+
+        # Test the angle.
+        self.assertEqual(angle, 0.0)
+
+
+    def test_R_to_axis_angle_180_complex(self):
+        """Test the rotation matrix to axis-angle conversion."""
+
+        # Generate the rotation matrix.
+        R = array([[0, 0, 1], [1, 0, 0], [0, 1, 0]], float64)
+
+        # Get the axis and angle.
+        axis, angle = R_to_axis_angle(R)
+
+        # Test the angle.
+        self.assertEqual(angle, 2 * pi / 3)
+
+        # Test the vector.
+        for i in range(3):
+            self.assertAlmostEqual(axis[i], 1.0/sqrt(3))
+
+
+    def test_R_to_euler_zyz(self):
+        """Test the rotation matrix to zyz Euler angle conversion."""
+
+        # Starting angles.
+        alpha = uniform(0, 2*pi)
+        beta =  uniform(0, pi)
+        gamma = uniform(0, 2*pi)
+
+        # Print out.
+        print("Original angles:")
+        print(("alpha: %s" % alpha))
+        print(("beta: %s" % beta))
+        print(("gamma: %s\n" % gamma))
+
+        # Generate the rotation matrix.
+        R = zeros((3, 3), float64)
+        euler_zyz_to_R(alpha, beta, gamma, R)
+
+        # Get back the angles.
+        alpha_new, beta_new, gamma_new = R_to_euler_zyz(R)
+
+        # Wrap the angles.
+        alpha_new = wrap_angles(alpha_new, 0, 2*pi)
+        beta_new = wrap_angles(beta_new, 0, 2*pi)
+        gamma_new = wrap_angles(gamma_new, 0, 2*pi)
+
+        # Print out.
+        print("New angles:")
+        print(("alpha: %s" % alpha_new))
+        print(("beta: %s" % beta_new))
+        print(("gamma: %s\n" % gamma_new))
+
+        # Checks.
+        self.assertAlmostEqual(alpha, alpha_new)
+        self.assertAlmostEqual(beta, beta_new)
+        self.assertAlmostEqual(gamma, gamma_new)
+
+
     def test_R_to_quaternion_no_rot(self):
         """Test the rotation matrix to quaternion conversion for a zero 
angle rotation."""
 




Related Messages


Powered by MHonArc, Updated Wed Sep 09 16:20:05 2009