日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python定义一个圆_Python-矩形和圆形

發(fā)布時間:2024/10/8 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python定义一个圆_Python-矩形和圆形 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#######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

#計算點是否在圓內(nèi)

def point_in_circle(x,y):

b=point_in_len(x,y)

if b <=radius.x:

print( b)

return True

else:

return False

#

#計算矩形全部在圓內(nèi)

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,

#原理:比對在矩形的范圍內(nèi)所有的點,是否有到圓心的距離,小于半徑的

###原理:如果有符合的就計數(shù)+1

##并計算 計數(shù)是否大于1,如果大于1,則認(rèn)為矩形有點是在圓形中

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

###計算矩形是否全部包含在圓形內(nèi)

print(rect_in_circle(box.point.x,box.point.y))

##計算矩形是否有部分在圓形內(nèi)

print(rect_circle_overlap(box.point.x,box.point.y))

總結(jié)

以上是生活随笔為你收集整理的python定义一个圆_Python-矩形和圆形的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。