Author: bugman Date: Mon Nov 17 17:23:30 2014 New Revision: 26604 URL: http://svn.gna.org/viewcvs/relax?rev=26604&view=rev Log: Renamed vector_angle() to vector_angle_normal() in the lib.geometry.vectors module. This is to standardise the naming as there are now the standard vector angle formula implemented as the vector_angle_acos() and vector_angle_atan2() functions. Modified: trunk/lib/geometry/vectors.py trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py Modified: trunk/lib/geometry/vectors.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/geometry/vectors.py?rev=26604&r1=26603&r2=26604&view=diff ============================================================================== --- trunk/lib/geometry/vectors.py (original) +++ trunk/lib/geometry/vectors.py Mon Nov 17 17:23:30 2014 @@ -74,35 +74,6 @@ return vect / norm(vect) -def vector_angle(vector1, vector2, normal): - """Calculate the directional angle between two N-dimensional vectors. - - @param vector1: The first vector. - @type vector1: numpy rank-1 array - @param vector2: The second vector. - @type vector2: numpy rank-1 array - @param normal: The vector defining the plane, to determine the sign. - @type normal: numpy rank-1 array - @return: The angle between -pi and pi. - @rtype: float - """ - - # Normalise the vectors (without changing the original vectors). - vector1 = vector1 / norm(vector1) - vector2 = vector2 / norm(vector2) - - # The cross product. - cp = cross(vector1, vector2) - - # The angle. - angle = acos(dot(vector1, vector2)) - if dot(cp, normal) < 0.0: - angle = -angle - - # Return the signed angle. - return angle - - def vector_angle_acos(vector1, vector2): """Calculate the angle between two N-dimensional vectors using the acos formula. @@ -143,3 +114,32 @@ # Calculate and return the angle. return atan2(norm(cross(vector1, vector2)), dot(vector1, vector2)) + + +def vector_angle_normal(vector1, vector2, normal): + """Calculate the directional angle between two N-dimensional vectors. + + @param vector1: The first vector. + @type vector1: numpy rank-1 array + @param vector2: The second vector. + @type vector2: numpy rank-1 array + @param normal: The vector defining the plane, to determine the sign. + @type normal: numpy rank-1 array + @return: The angle between -pi and pi. + @rtype: float + """ + + # Normalise the vectors (without changing the original vectors). + vector1 = vector1 / norm(vector1) + vector2 = vector2 / norm(vector2) + + # The cross product. + cp = cross(vector1, vector2) + + # The angle. + angle = acos(dot(vector1, vector2)) + if dot(cp, normal) < 0.0: + angle = -angle + + # Return the signed angle. + return angle Modified: trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py?rev=26604&r1=26603&r2=26604&view=diff ============================================================================== --- trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py (original) +++ trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py Mon Nov 17 17:23:30 2014 @@ -25,85 +25,85 @@ from unittest import TestCase # relax module imports. -from lib.geometry.vectors import vector_angle +from lib.geometry.vectors import vector_angle_normal class Test_vectors(TestCase): """Unit tests for the lib.geometry.vectors relax module.""" - def test_vector_angle1(self): - """Test the vector_angle() function with the vectors [1, 0, 0] and [0, 1, 0].""" + def test_vector_angle_normal1(self): + """Test the vector_angle_normal() function with the vectors [1, 0, 0] and [0, 1, 0].""" # Calculate the angle. v1 = array([1, 0, 0], float64) v2 = array([0, 1, 0], float64) normal = array([0, 0, 1], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, pi/2.0) - def test_vector_angle2(self): - """Test the vector_angle() function with the vectors [1, 0, 0] and [0, 2, 0].""" + def test_vector_angle_normal2(self): + """Test the vector_angle_normal() function with the vectors [1, 0, 0] and [0, 2, 0].""" # Calculate the angle. v1 = array([1, 0, 0], float64) v2 = array([0, 2, 0], float64) normal = array([0, 0, 1], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, pi/2.0) - def test_vector_angle3(self): - """Test the vector_angle() function with the vectors [2, 0, 0] and [0, -2, 0].""" + def test_vector_angle_normal3(self): + """Test the vector_angle_normal() function with the vectors [2, 0, 0] and [0, -2, 0].""" # Calculate the angle. v1 = array([2, 0, 0], float64) v2 = array([0, -2, 0], float64) normal = array([0, 0, 1], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, -pi/2.0) - def test_vector_angle4(self): - """Test the vector_angle() function with the vectors [2, 0, 0] and [2, 2, 0].""" + def test_vector_angle_normal4(self): + """Test the vector_angle_normal() function with the vectors [2, 0, 0] and [2, 2, 0].""" # Calculate the angle. v1 = array([2, 0, 0], float64) v2 = array([2, 2, 0], float64) normal = array([0, 0, 2], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, pi/4.0) - def test_vector_angle5(self): - """Test the vector_angle() function with the vectors [2, 0, 0] and [2, 2, 0].""" + def test_vector_angle_normal5(self): + """Test the vector_angle_normal() function with the vectors [2, 0, 0] and [2, 2, 0].""" # Calculate the angle. v1 = array([2, 0, 0], float64) v2 = array([2, 2, 0], float64) normal = array([0, 0, -2], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, -pi/4.0) - def test_vector_angle6(self): - """Test the vector_angle() function with the vectors [2, 2, 0] and [2, -2, 0].""" + def test_vector_angle_normal6(self): + """Test the vector_angle_normal() function with the vectors [2, 2, 0] and [2, -2, 0].""" # Calculate the angle. v1 = array([2, 2, 0], float64) v2 = array([2, -2, 0], float64) normal = array([0, 0, 2], float64) - angle = vector_angle(v1, v2, normal) + angle = vector_angle_normal(v1, v2, normal) # Check the angle. self.assertAlmostEqual(angle, -pi/2.0)