Package lib :: Package geometry :: Module vectors
[hide private]
[frames] | no frames]

Source Code for Module lib.geometry.vectors

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2004-2013 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Collection of functions for vector operations.""" 
24   
25  # Python module imports. 
26  from math import acos, cos, pi, sin 
27  from random import uniform 
28   
29   
30 -def random_unit_vector(vector):
31 """Generate a random rotation axis. 32 33 Uniform point sampling on a unit sphere is used to generate a random axis orientation. 34 35 @param vector: The 3D rotation axis. 36 @type vector: numpy 3D, rank-1 array 37 """ 38 39 # Random azimuthal angle. 40 u = uniform(0, 1) 41 theta = 2*pi*u 42 43 # Random polar angle. 44 v = uniform(0, 1) 45 phi = acos(2.0*v - 1) 46 47 # Random unit vector. 48 vector[0] = cos(theta) * sin(phi) 49 vector[1] = sin(theta) * sin(phi) 50 vector[2] = cos(phi)
51