Write a Python program to determine if the point is inside or outside the circle. (using method _init _()), knowing the coordinates (x1, y1) of the center of the circle and its radius.

Questions & AnswersCategory: PythonWrite a Python program to determine if the point is inside or outside the circle. (using method _init _()), knowing the coordinates (x1, y1) of the center of the circle and its radius.

بمعلومية إحداثيات (x1، y1) لمركز دائرة وهو نصف القطر. اكتب برنامج بيثون لتحديد ما إذا كانت النقطة تقع داخل الدائرة أو خارجها. (باستخدام طريقة _init _ ()) 

Write a Python program to determine if the point is inside or outside the circle. (using method _init _()), knowing the coordinates (x1, y1) of the center of the circle and its radius.

 

1 Answers
Lokesh Kumar Staff answered 2 years ago
import math
class circle():

    def __init__(self, radius, center):
        self.radius = radius
        self.center = center
    
    def point_location(self, point):
        self.point = point
        
        #distance between two points
        distance_p = math.sqrt(pow((self.center[0]-point[0]),2) + pow((self.center[1]-point[1]),2))
        
        print(distance_p)
        res = self.radius>=distance_p
        return res


if __name__ == '__main__':
    C1 = circle(5, (0,0))
    p_result = C1.point_location((4,4))
    if p_result:
        print("Point lies inside the circle.")
    else:
        print("Point lies outside the circle.")