Skip to content

Commit

Permalink
Added util function for normalizing a n,3 vector
Browse files Browse the repository at this point in the history
  • Loading branch information
jterrace committed Mar 12, 2011
1 parent 60ad53f commit ad8c5ad
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions collada/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ def checkSource( source, components, maxindex):
if source.components != components:
raise DaeMalformedError('Wrong format in source %s'%source.id)
return source

def normalize_v3(arr):
''' Normalize a numpy array of 3 component vectors shape=(n,3) '''
lens = numpy.sqrt( arr[:,0]**2 + arr[:,1]**2 + arr[:,2]**2 )
arr[:,0] /= lens
arr[:,1] /= lens
arr[:,2] /= lens

0 comments on commit ad8c5ad

Please sign in to comment.