mailr22518 - /trunk/lib/geometry/vectors.py


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

Header


Content

Posted by edward on March 21, 2014 - 15:22:
Author: bugman
Date: Fri Mar 21 15:22:38 2014
New Revision: 22518

URL: http://svn.gna.org/viewcvs/relax?rev=22518&view=rev
Log:
Created the new vector_angle() library function.

This is located in the lib.geometry.vectors module.  The function will 
calculate the angle between
two vectors with sign or direction using the atan2() function.


Modified:
    trunk/lib/geometry/vectors.py

Modified: trunk/lib/geometry/vectors.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/geometry/vectors.py?rev=22518&r1=22517&r2=22518&view=diff
==============================================================================
--- trunk/lib/geometry/vectors.py       (original)
+++ trunk/lib/geometry/vectors.py       Fri Mar 21 15:22:38 2014
@@ -23,8 +23,8 @@
 """Collection of functions for vector operations."""
 
 # Python module imports.
-from math import acos, cos, pi, sin
-from numpy import array, float64
+from math import acos, atan2, cos, pi, sin
+from numpy import array, cross, dot, float64
 from numpy.linalg import norm
 from random import uniform
 
@@ -72,3 +72,25 @@
 
     # Return the unit vector.
     return vect / norm(vect)
+
+
+def vector_angle(vector1, vector2):
+    """Calculate the directional angle between two N-dimensional vectors.
+
+    The angle between vectors A and B is calculated using the formula::
+
+        theta = arctan(AxB / A.B),
+
+    where the arctan function used is atan2, AxB is the cross product 
between the two vectors, and A.B is the dot product.
+
+
+    @param vector1:     The first vector.
+    @type vector1:      numpy rank-1 array
+    @param vector2:     The second vector.
+    @type vector2:      numpy rank-1 array
+    @return:            The angle between -pi and pi.
+    @rtype:             float
+    """
+
+    # Calculate and return the value.
+    return atan2(cross(vector1, vector2), dot(vector1, vector2))




Related Messages


Powered by MHonArc, Updated Fri Mar 21 17:40:02 2014