# jch 18-MAY-2003; created Point.py from twist1.py utility # $Header: /jch/play/cvsroot/twist/Point.py,v 1.2 2003/05/30 03:20:04 jch Exp $ #// Copyright 2003 YON - Jan C. Hardenbergh. Permission to copy is #// granted as long as this copyright and this URL are maintained: #// http://www.jch.com/NURBS/ # import Numeric import math class Point: def __init__(self, value): self.data = [value[0], value[1], value[2]] def __getitem__(self, index): return self.data[index] def __add__(self, other): return Point([self.data[0]+other[0], self.data[1]+other[1], self.data[2]+other[2]]) def __sub__(self, other): return Point([self.data[0]-other[0], self.data[1]-other[1], self.data[2]-other[2]]) def __mul__(self, other): return Point([self.data[0]*other, self.data[1]*other, self.data[2]*other]) def __div__(self, other): return Point([self.data[0]/other, self.data[1]/other, self.data[2]/other]) def DistanceTo(self, other): x = self.data[0]-other[0] y = self.data[1]-other[1] z = self.data[2]-other[2] return math.sqrt(x*x+y*y+z*z) def Length(self): length = math.sqrt(self.data[0]*self.data[0]+self.data[1]*self.data[1]+self.data[2]*self.data[2]) return length def Normalized(self): length = math.sqrt(self.data[0]*self.data[0]+self.data[1]*self.data[1]+self.data[2]*self.data[2]) return self.__div__(length) def Dot(self,other): return self.data[0]*other[0]+self.data[1]*other[1]+self.data[2]*other[2] def Print(self): print "Point : %g, %g, %g" % (self.data[0], self.data[1], self.data[2]) def Assign(self,x,y,z): self.data[0] = x self.data[1] = y self.data[2] = z def GetVertex(self): return self.data