Lecture Notes on 02 Feb 2022 import math class Point (object): # constructor def __init__ (self, x = 0, y = 0): self.x = x self.y = y # get the distance to another Point object def dist (self, other): return math.hypot (self.x - other.x, self.y - other.y) # string representation of a Point def __str__ (self): return '(' + str(self.x) + ', ' + str(self.y) + ')' # test for equality of two Point objects def __eq__ (self, other): tol = 1.0e-6 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 the circumference def circumference (self): return 2. * math.pi * self.radius # compute the area def area (self): return math.pi * self.radius * self.radius # determine if a Point p is strictly inside this Circle def point_inside (self, p): return self.center.dist(p) < self.radius # determine if a Circle c is strictly inside this Circle def circle_inside (self, c): dist_centers = self.center.dist (c.center) return (dist_centers + c.radius) < self.radius # determine if a Circle c is strictly outside this Circle def circle_outside (self, c): dist_centers = self.center.dist (c.center) return dist_centers > (self.radius + c.radius) # determine if a Circle c overlaps this Circle def circle_overlaps (self, c): return (not self.circle_inside(c)) and (not self.circle_outside(c)) def main(): # create Point objects a = Point() b = Point (3, 4) c = Point (3, 4) # print the Point objects print (a) print (b) # print the distance between the Point objects print (a.dist(b)) print (b.dist(a)) # test for equality if (b == c): print ("Point objects are equal") else: print ("Point object are not equal") print() # create Circle objects p = Circle (3, 4, 3) q = Circle (1, 3, 2) r = Circle (2, 5, 4) # compute the circumference print (p.circumference()) # compute the area print (p.area()) # test is Point a is inside Circle r if (r.point_inside(a)): print ("Point is inside the Circle") else: print ("Point is not inside the Circle") # test if Circle q is inside Circle p if (p.circle_inside(q)): print ("Circle q is inside Circle p") else: print ("Circle q is not inside Circle p") # test if Circle p and Circle r overlap if (p.circle_overlaps(r)): print ("Circle p and Circle r overlap") else: print ("Circle p and Circle r do not overlap") main()