Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Helper class and functions for basic 3d vector math.
- """
- class Vector3(object):
- def __init__(self,*point):
- """Define a vector in 3d space."""
- self.point = point
- def __add__(self,other):
- return map(reduce(lambda a,b: a+b),zip(self.point,other.point))
- def __sub__(self,other):
- return map(reduce(lambda a,b: a-b),zip(self.point,other.point))
- def __mul__(self,other):
- """Scalar multiplication aka the dot product."""
- return map(reduce(lambda a,b: a*b),zip(self.point,other.point))
- def __div__(self,other):
- return map(reduce(lambda a,b: a/b),zip(self.point,other.point))
- @property
- def x(self):
- return point[0]
- @property
- def y(self):
- return point[1]
- @property
- def z(self):
- return point[2]
- def cross(a,b):
- """Vector multiplication aka the cross product."""
- x = a.y*b.z - a.z*b.y
- y = a.x*b.z - a.z*b.x
- z = a.x*b.y - a.y*b.x
- return Vector3(x,y,z)
- print "Module py.vector3 loaded successfully."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement