xnx / circle-packing

Packing circles into arbitrary shapes since 2019.
GNU General Public License v2.0
12 stars 6 forks source link

Circles overlap? #2

Open kevinlinxc opened 4 months ago

kevinlinxc commented 4 months ago

Hi, I'm passing in a blank picture and some of the circles overlap:

image

Is there any way to prevent this? I would prefer if they were all tangent. By the way, very nice project, exactly what I was looking for.

kevinlinxc commented 4 months ago

I noticed it was because your code only checks the four cardinal directions, I wrote this code to check more points:

        # if not all((self.img[icx-r,icy], self.img[icx+r,icy],
        #         self.img[icx,icy-r], self.img[icx,icy+r])):
        #     return False
        subdivide = 10
        for i in range(360//subdivide):
            theta = np.deg2rad(i * subdivide)
            x, y = icx + r * np.cos(theta), icy + r * np.sin(theta)
            if not self.img[int(x),int(y)]:
                return False
image

It works but it does take longer to process. I tried speeding it up using numpy and scipy but it wasn't really working properyl.