The first thing you need to do here is define how a circle is structured. For this example, I am defining a circle as a tuple of two elements, where the first element is coordinates of the origin point and the second element is the radius of the circle. For instance, ((0,0), 3)
is a circle with origin (0,0)
and a radius of 3
.
Now that you have defined a circle, you can move forward with checking a given point is inside a circle as follows:
import math
# Create a unit circle
mycircle = ((0,0), 1)
# Create points
mypoint1 = (3,3)
mypoint2 = (1,1)
# Your definition of distance function
def distance(point1, point2):
return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
# Defining the function to check if the point is inside or on a circle
def in_circle(point, circle):
origin, radius = circle
return radius >= distance(point, origin)
# Test
print(in_circle(mypoint1, mycircle))
# False
print(in_circle(mypoint2, mycircle))
# False
I hope this helps.