Skip to content

Commit

Permalink
add normalize function
Browse files Browse the repository at this point in the history
  • Loading branch information
tclapython committed Feb 10, 2016
1 parent b9bdbe5 commit 826fabd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ def times_scalar(self, scalar):

def magnitude(self):
return math.sqrt(sum([x*x for x in self.coordinates]))


def normalize(self):
return [x / self.magnitude() for x in self.coordinates]

0 comments on commit 826fabd

Please sign in to comment.