Lecture Notes on 27 Jan 2017 import math class Point (object): # constructor def __init__ (self, x = 0, y = 0): self.x = x self.y = y # get distance def dist (self, other): return math.hypot (self.x - other.x, self.y - other.y) # get a string representation of Point def __str__ (self): return '(' + str(self.x) + ", " + str(self.y) + ")" # test for equality def __eq__ (self, other): tol = 1.0e-16 return ((abs (self.x - other.x) < tol) and (abs(self.y - other.y) < tol)) class Circle (object): # constructor def __init__ (self, radius = 1, x = 0, y = 0): self.radius = radius self.center = Point (x, y) # compute cirumference def circumference (self): return 2.0 * math.pi * self.radius # compute area def area (self): return math.pi * self.radius * self.radius # determine if point is inside circle def point_inside (self, p): return (self.center.dist(p) < self.radius) # determine if a circle is inside this circle def circle_inside (self, c): distance = self.center.dist (c.center) return (distance + c.radius) < self.radius # determine if a circle c intersects this circle def does_intersect (self, c): class Rectangle (object): # constructor def __init__ (self, ul_x = 0, ul_y = 1, lr_x = 1, lr_y = 0): if ((ul_x < lr_x) and (ul_y > lr_y)): self.ul = Point (ul_x, ul_y) self.lr = Point (lr_x, lr_y) else: self.ul = Point (0, 1) self.lr = Point (1, 0) def main(): # create Point objects pointA = Point () pointB = Point (3, 4) # print the coordinates of the points print (pointA) print (pointB) # find the distance between the points print (pointA.dist(pointB)) print (pointB.dist(pointA)) main()