Package mglutil :: Package math
[hide private]
[frames] | no frames]

Source Code for Package mglutil.math

 1  import Numeric 
 2  N=Numeric 
 3  import types 
 4   
5 -def crossProduct (A, B, normal=True):
6 """ Return cross product of two vectors A and B 7 normal: return normalized vector 8 """ 9 res=[ A[1]*B[2] - A[2]*B[1], 10 A[2]*B[0] - A[0]*B[2], 11 A[0]*B[1] - A[1]*B[0] ] 12 if normal: 13 return norm(res) 14 else: 15 return res
16
17 -def norm (A):
18 """ Return normalized vector A. 19 """ 20 if type(A) == types.ListType: 21 A=Numeric.array(A,'f') 22 res= A/Numeric.sqrt(Numeric.dot(A,A)) 23 return res.tolist() 24 elif type(A)==Numeric.ArrayType: 25 return A/Numeric.sqrt(Numeric.dot(A,A)) 26 else: 27 print "Need a list or Numeric array" 28 return None
29
30 -def getCenter(coords):
31 """ get center of all the coords """ 32 coords=N.array(coords, 'f') 33 return (N.sum(coords)/len(coords)).tolist()
34