class Point:
def __init__(self):
self.x = 0.0
self.y = 0.0
def __init__(self,x,y):
self.x = x
self.y = y
def GetDistFromTwoPoints(point1,point2):
return math.sqrt((point1.x-point2.x)**2+(point1.y-point2.y)**2)
def Judge(center_x,center_y,radius,xmin,xmax,ymin,ymax):
cCenter = Point(center_x,center_y)
# Coordinates of four points
rDownLeft = Point(xmin,ymin)
rDownRight = Point(xmax,ymin)
rUpperLeft = Point(xmin,ymax)
rUpperRight = Point(xmax,ymax)
# Midpoint of four lines
rSouth = Point(xmin/2+xmax/2,ymin)
rNorth = Point(xmin/2+xmax/2,ymax)
rEast = Point(xmax,ymin/2+ymax/2)
rWest = Point(xmin,ymin/2+ymax/2)
lDownLeft = GetDistFromTwoPoints(cCenter,rDownLeft)
lDownRight = GetDistFromTwoPoints(cCenter,rDownRight)
lUpperLeft = GetDistFromTwoPoints(cCenter,rUpperLeft)
lUpperRight = GetDistFromTwoPoints(cCenter,rUpperRight)
lSouth = GetDistFromTwoPoints(cCenter,rSouth)
lNorth = GetDistFromTwoPoints(cCenter,rNorth)
lEast = GetDistFromTwoPoints(cCenter,rEast)
lWest = GetDistFromTwoPoints(cCenter,rWest)
bRt1 = False
bRt2 = False
# There are two conditions to think about.
# 1: circle > rectangle
if(radius >= lDownLeft and radius >= lDownRight and radius >= lUpperRight and radius >= lUpperLeft):
bRt1 = True
# 2: circle < rectangle
if(radius <= lNorth and radius <= lSouth and radius <= lEast and radius <= lWest):
bRt2 = True
return bRt1 or bRt2
if __name__ == '__main__':
# Test case
print Judge(0,0,1,0,1,0,1)