# geom_tutor.py # Walker M. White (wmw2) # September 7, 2015 """Code to show off an object in the Python tutor Copy and past the following code into the tutor. Put it in a second (separate) tab, and rename the tab to geom""" class Point3(object): """An instance is a point in 3 space.""" def __init__(self,x,y,z): """**Constructor**: creates a new Point value (x,y,z). Parameter x: initial x value **Precondition**: value is an int or float. Parameter y: initial y value **Precondition**: value is an int or float. Parameter z: initial z value **Precondition**: value is an int or float. All values are 0.0 by default. """ self.x = float(x) self.y = float(y) self.z = float(z) def __eq__(self, other): """**Returns**: True if self and other are equivalent Points. This method uses numpy to test whether the coordinates are "close enough". It does not require exact equality for floats. :param other: value to compare against """ return (type(other) == Point3 and p.x == other.x and p.y == other.y and p.z == other.z) def distanceTo(self, other): """**Returns**: the Euclidean distance from this point to other Parameter other: value to compare against **Precondition**: value is a Tuple3 object. """ return math.sqrt((self.x-other.x)*(self.x-other.x)+ (self.y-other.y)*(self.y-other.y)+ (self.z-other.z)*(self.z-other.z)) def abs(self): """Sets each component of this Tuple3 to its absolute value.""" self.x = abs(self.x) self.y = abs(self.y) self.z = abs(self.z)