파이썬(PYTHON)

중복없이 원그리기 (특정 공간에 특정 크기 입자가 차지하는 수량 및 면적)

WEBJU 2022. 1. 13. 14:31
728x90
#-*- coding:utf-8 -*-
# 특정 공간에 빈 공간없이 최대 격자 채우기

import cv2
import numpy as np
import random
import matplotlib.pyplot as plt

w = 720
h = 720
white_color = 255
black_color = 0
radi = 20
img = np.zeros((h, w), dtype = np.uint8)
cou = 0
pp = []
while 1:
    x = random.randint((-1)*int(radi/2), h+int(radi/2))
    y = random.randint((-1)*int(radi/2), w+int(radi/2))
    img1 = img.copy()
    a1 = sum(sum((img1 > 127)))

    cv2.circle(img1, (x, y), radi, white_color, -1)
    a2 = sum(sum((img1 > 127)))
    #print(a1, a2)
    if (a2 - a1) > radi*radi*3.1: # 10 : 310, 20 : 1250
        img = img1
        cou += 1
        print(cou)
    else:
        img = img

    pp.append(cou)
    cv2.imshow('img', img)
    cv2.waitKey(100)
   
    plt.plot(pp,'.-')
    plt.pause(0.01)
    plt.clf()
   
   

단위 면적 : 720 x 720

 

#1 CASE :

. 입자 반지름 : 20, 최대 수량 : ~ 202 => 20 / 720 = 1 / 31 => 관계 #1 : 202 / 31 

 

 

#2 CASE :

. 입자 반지름 : 10, 최대 수량 : ~ 810 => 10 / 720 = 1 / 72 => 관계 #2 : 810 / 72 = 405 / 31

 

#3 CASE : 

. 입자 반지름 : 30, 최대 수량 : ~ 90 => 30 / 720 = 1 / 24 => 관계 #3 :  90 / 72 = 45 / 31

#4 CASE :

. 입자 반지름 : 40, 최대 수량 : ~ 52 => 40 / 720 = 1 / 18 => 관계 #4 :  52 / 72 = 26 / 31 

 

 

 

728x90