Python implements the small circle covering the big circle problem

Issue review


    Given a circle with a radius of 10m, and several small circles with a radius of 1m (the number of small circles is enough), now you need to use several small circles to cover the big circle. Ask at least how many small circles are needed to cover this circle with a radius of 10m?

Solution ideas


     In order to ensure the smallest number of small circles, there is no overlap between the circles and the circles are tangent.
     Because the gap between the big circle and the small circle needs to be considered, the gap between the small circle and the small circle should also be considered.
     Therefore, only approximate ideas can be used for calculation.
     
    1. When r<R<2r, n=1;
    2. When 2r<=R<2.1547r, n=2;
    3. When R>2.1547*r, first distribute a circle of small circles evenly next to the large circle , Calculate the number of small circles, in the second circle of pendulum, get the number of small circles, by analogy,...

 

 

import math

PI= 3.1415926

#计算圆面积
def getArea(R):
    Area = PI*R**2
    return Area

BigR = 10  #大圆半径
MinR = 1   #小圆半径


BigArea = getArea(BigR)  #大圆面积

MinArea = getArea(MinR)   #小圆面积

BestNumber = round(BigArea/MinArea) #最理想情况小圆个数


'''

现在考虑内圆与外圆的空隙。求的一个更精确的解。
根据上面第3条,最外圆的可以放的圆的个数为 n0 = [pi/( arcsin(r/(R- r)) )];
那么考虑当内圈的一个圆与外圈的两个圆相切时,特别的,当三个圆心成正三角形时,最节省空间。
于是得到:

n0 = [ pi/(arcsin(r/(R- r)) )]
n1 = [ pi/arcsin(r/( sqrt((R -1 - sqrt(3) )^2 + 1) )) ]
n2 = [ pi/arcsin(r/( sqrt((R -1 - 2*sqrt(3) )^2 +1) )) ]
n3 = [ pi/arcsin(r/( sqrt((R -1 - 3*sqrt(3) )^2 + 1) )) ]
....
一直到减出来小于0为止
把所有的n相加就得到了解。

'''

n0 = round(PI/(math.asin(MinR/(BigR - MinR)) ))  
n1 = round(PI/(math.asin(MinR/(math.sqrt((BigR -1 -   math.sqrt(3) )**2 + 1) )) ))
n2 = round(PI/(math.asin(MinR/(math.sqrt((BigR -1 - 2*math.sqrt(3) )**2 + 1) )) ))
n3 = round(PI/(math.asin(MinR/(math.sqrt((BigR -1 - 3*math.sqrt(3) )**2 + 1) )) ))
n4 = round(PI/(math.asin(MinR/(math.sqrt((BigR -1 - 4*math.sqrt(3) )**2 + 1) )) ))
n5 = round(PI/(math.asin(MinR/(math.sqrt((BigR -1 - 5*math.sqrt(3) )**2 + 1) )) ))


print("最好情况:",BestNumber)

N = n0 +n1+n2+n3+n4+n5

print("使用近似思想(忽略圆与圆之间间隔)得到的小圆个数为:",N)

 

Guess you like

Origin blog.csdn.net/qq_39463175/article/details/107579251