#######15.9 p175
import math
class Circle: #
"""
This is a circle Class,
incude Center and radius
"""
class Point:
"""
This is a point
"""
class Rectangle():
"""
This is a 矩形
"""
radius=Circle()
radius.x=75.0
center=Circle()
center.box=Point()
center.box.x=150.0
center.box.y=100.0
##矩形
box=Rectangle()
box.wei=100.0
box.hei=100.0
box.point=Point()
#计算点到圆心的距离
def point_in_len(x,y):
b=math.sqrt((x-center.box.x)**2+(y-center.box.y)**2)
return b
#计算点是否在圆内
def point_in_circle(x,y):
b=point_in_len(x,y)
if b <=radius.x:
print( b)
return True
else:
return False
#
#计算矩形全部在圆内
def rect_in_circle(x,y):
x1=x+box.wei
y1=y+box.hei
b1=math.sqrt((x-center.box.x)**2+(y-center.box.y)**2)
b2= math.sqrt((x1-center.box.x)**2+(y-center.box.y)**2)
b3= math.sqrt((x-center.box.x)**2+(y1-center.box.y)**2)
b4=math.sqrt(box.wei**2+box.hei**2)
if b4 <=radius.x:
if b1<=radius.x and b2<=radius.x and b3<=radius.x:
return True
else:
return False
else:
return False
def rect_circle_overlap(x,y): ###
#算如果矩形在圆形的一部分就返回Ture,
#原理:比对在矩形的范围内所有的点,是否有到圆心的距离,小于半径的
###原理:如果有符合的就计数+1
##并计算 计数是否大于1,如果大于1,则认为矩形有点是在圆形中
x2=int(x)
x3=x2+int(x+box.wei)
y2=int(y)
y3=y2+int(y+box.hei)
count=0
for x1 in range(x2,x3):
for y1 in range(y2,y3):
len1=math.sqrt((x1-center.box.x)**2+(y1-center.box.y)**2)
if len1 >radius.x:
count=count+0
else:
count+=1
if count >=1:
return True
point=Point()
point.x=90.0
point.y=90.0
print(point_in_circle(point.x,point.y))
###矩形
box.point.x=160.0
box.point.y=100.0
###计算矩形是否全部包含在圆形内
print(rect_in_circle(box.point.x,box.point.y))
##计算矩形是否有部分在圆形内
print(rect_circle_overlap(box.point.x,box.point.y))