Author: bugman
Date: Mon Nov 17 17:12:44 2014
New Revision: 26601
URL: http://svn.gna.org/viewcvs/relax?rev=26601&view=rev
Log:
Implemented the lib.geometry.vectors.vector_angle_atan2() function.
This is for calculating the inter-vector angle using the more numerically
stable atan2() formula.
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=26601&r1=26600&r2=26601&view=diff
==============================================================================
--- trunk/lib/geometry/vectors.py (original)
+++ trunk/lib/geometry/vectors.py Mon Nov 17 17:12:44 2014
@@ -101,3 +101,26 @@
# Return the signed angle.
return angle
+
+
+def vector_angle_atan2(vector1, vector2):
+ """Calculate the angle between two N-dimensional vectors using the atan2
formula.
+
+ The formula is::
+
+ angle = atan2(norm(cross(a, b)), dot(a, b)).
+
+
+ This is more numerically stable for angles close to 0 or pi than the
acos() formula.
+
+
+ @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 0 and pi.
+ @rtype: float
+ """
+
+ # Calculate and return the angle.
+ return atan2(norm(cross(vector1, vector2)), dot(vector1, vector2))
_______________________________________________
relax (http://www.nmr-relax.com)
This is the relax-commits mailing list
[email protected]
To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits