How to create a method in a class that will determine the intersection of circles?(Python 3.x)

  class, function, methods, python, python-3.x

I have a code

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def dist(self, other_point):  # the dist method takes another object of class Point and finds the Euclidean distance between two points.
        d = (other_point.x - self.x) ** 2 + (other_point.y - self.y) ** 2
        return d**(1/2)
class Circle:
    def __init__(self, center,radius):  # a constructor that takes an object of class Point, the center point of the circle, and a number, the radius of the circle;
        self.center = center  # center and radius return the center and radius of the circle, respectively;
        self.radius = radius
    def square(self):
        S = 3.14 * self.radius**2
        return S  # returns the area of a circle

I need to add a do_intersect method to class Circle, which will accept another object of the Circle class and return True or False depending on whether the circles intersect or not.

I added this:

    def do_intersect(self, circle_2):
        if (((self.center[0] - circle_2.center[0]) + (self.center[1] - circle_2.center[1])) ** 2) ** 0.5 <= self.radius + circle_2.radius:
            return True
        return False

But I have an error 'Point' object does not support indexing when the test program enters Circle(Point(0, 0), 10).do_intersect(Circle(Point(0, 0), 10))

Please, help me to fix this problem

Source: Python-3x Questions

LEAVE A COMMENT