mailr22521 - in /branches/double_rotor: ./ lib/geometry/ test_suite/unit_tests/_lib/_geometry/


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

Header


Content

Posted by edward on March 21, 2014 - 17:47:
Author: bugman
Date: Fri Mar 21 17:47:31 2014
New Revision: 22521

URL: http://svn.gna.org/viewcvs/relax?rev=22521&view=rev
Log:
Merged revisions 22518-22520 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r22518 | bugman | 2014-03-21 15:22:38 +0100 (Fri, 21 Mar 2014) | 6 lines
  
  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.
........
  r22519 | bugman | 2014-03-21 17:26:06 +0100 (Fri, 21 Mar 2014) | 3 lines
  
  Addition of a number of unit tests for the new 
lib.geometry.vectors.vector_angle() function.
........
  r22520 | bugman | 2014-03-21 17:29:24 +0100 (Fri, 21 Mar 2014) | 7 lines
  
  Changes to the lib.geometry.vectors.vector_angle() function.
  
  This now expects the normal of the plane in which the angle is defined.  
The original logic was not
  functional, therefore the angle is forced to be negative if the cross 
product between the two
  vectors points in the opposite direction as the normal.
........

Added:
    branches/double_rotor/test_suite/unit_tests/_lib/_geometry/test_vectors.py
      - copied unchanged from r22520, 
trunk/test_suite/unit_tests/_lib/_geometry/test_vectors.py
Modified:
    branches/double_rotor/   (props changed)
    branches/double_rotor/lib/geometry/vectors.py
    branches/double_rotor/test_suite/unit_tests/_lib/_geometry/__init__.py

Propchange: branches/double_rotor/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Mar 21 17:47:31 2014
@@ -1 +1 @@
-/trunk:1-22516
+/trunk:1-22520

Modified: branches/double_rotor/lib/geometry/vectors.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/double_rotor/lib/geometry/vectors.py?rev=22521&r1=22520&r2=22521&view=diff
==============================================================================
--- branches/double_rotor/lib/geometry/vectors.py       (original)
+++ branches/double_rotor/lib/geometry/vectors.py       Fri Mar 21 17:47:31 
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,32 @@
 
     # Return the unit vector.
     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

Modified: 
branches/double_rotor/test_suite/unit_tests/_lib/_geometry/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/double_rotor/test_suite/unit_tests/_lib/_geometry/__init__.py?rev=22521&r1=22520&r2=22521&view=diff
==============================================================================
--- branches/double_rotor/test_suite/unit_tests/_lib/_geometry/__init__.py    
  (original)
+++ branches/double_rotor/test_suite/unit_tests/_lib/_geometry/__init__.py    
  Fri Mar 21 17:47:31 2014
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2013 Edward d'Auvergne                                       
 #
+# Copyright (C) 2013-2014 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax (http://www.nmr-relax.com).         
 #
 #                                                                            
 #
@@ -24,5 +24,6 @@
     'test___init_',
     'test_lines',
     'test_pec',
-    'test_rotations'
+    'test_rotations',
+    'test_vectors'
 ]




Related Messages


Powered by MHonArc, Updated Mon Mar 24 17:20:02 2014