File:Brooks circle packing invariant 3.444.svg
From testwiki
Jump to navigation
Jump to search
Original file (SVG file, nominally 480 × 360 pixels, file size: 742 bytes)
Contents
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionBrooks circle packing invariant 3.444.svg |
English: Circle packing in a circular rectangle with Brooks invariant 3 + 1/(2 + 1/4) = 31/9 |
| Date | |
| Source | Own work |
| Author | David Eppstein |
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
| This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
| The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
Source code

This media was created with Python (general-purpose programming language)
Here is a listing of the source used to create this file.
Here is a listing of the source used to create this file.
Deutsch ∙ македонски ∙ English ∙ +/−
from PADS.SVG import SVG,colors
import sys
pattern = [0] + [2**(i/2)*1j**(k/2) for i in range(-2,3) for k in range(8)]
def tanrad(A,p):
"""Radius of circle at p tangent to circle A"""
Actr,Arad = A
return abs(Actr-p)-Arad
def discrepancy(A,B,C,p):
"""How far are we from being triply tangent?"""
rads = [tanrad(X,p) for X in (A,B,C)]
return max(rads) - min(rads)
def positive(x,y,imag):
if imag:
x,y = x.imag,y.imag
else:
x,y = x.real,y.real
return y > x
def inscribe(A,B,C,imag):
"""Find triply tangent circle in given direction from B.
imag=0 for positive real dir, 1 for positive imaginary dir"""
p = B[0] + 1.5*(1j)**imag*B[1]
tries = 0
d = discrepancy(A,B,C,p)
while tries < 200 and d > 0.0001:
candidates = [p+d*x for x in pattern if positive(B[0],p+d*x,imag)]
best = min ([(discrepancy(A,B,C,q),q) for q in candidates])
d,p = best
tries += 1
return (p,tanrad(A,p))
bbox = 480+360j
fills = [colors.blue,colors.yellow,colors.red]
fillidx = 0
svg = SVG(bbox,sys.stdout)
svg.group(stroke=colors.black)
svg.group(fill="#666")
def pack(slope,limit):
Acenter = 240 - slope*240*1j
Bcenter = 180j - 180/slope
Arad = abs(Acenter)
Brad = abs(Bcenter)
A = (Acenter,Arad)
B = (Bcenter,Brad)
C = (bbox-Bcenter,Brad)
D = (bbox-Acenter,Arad)
circles = [A,B,C,D,None]
offidx = 0
while len(circles) < limit:
E = inscribe(A,B,D,offidx)
Cdist = tanrad(C,E[0])-E[1]
if Cdist < 0: # flip!
circles.append(None)
A,B,C,D = B,A,D,C
offidx ^= 1
else:
circles.append(E)
B = E
if Cdist < 0.001:
break
return circles
def confrac(circles):
f = 0
for i in range(len(circles)-1,4,-1):
if circles[i]:
f += 1
elif f:
f = 1/f
return f
target = 31/9
lo = 0.5 # gives 4 + 1/(3 + 1/...)
hi = 1 # gives 1 + 1/(1 + 1/...)
for i in range(30):
mid = (lo+hi)/2
circles = pack(mid,30)
brooks = confrac(circles)
if brooks > target:
lo = mid
else:
hi = mid
circles = pack(mid,30)
for C in circles:
if C:
svg.circle(*C)
else:
svg.ungroup()
svg.group(fill=fills[fillidx])
fillidx = (fillidx + 1)%len(fills)
svg.ungroup()
svg.ungroup()
svg.close()
Captions
Circle packing in a circular rectangle with Brooks invariant 3 + 1/(2 + 1/4) = 31/9
Items portrayed in this file
depicts
some value
2 January 2026
742 byte
image/svg+xml
ea28adb9f5dad7fb3f8fdf288c0c50c8607b6e05
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 02:08, 3 January 2026 | 480 × 360 (742 bytes) | wikimediacommons>David Eppstein | Uploaded own work with UploadWizard |
File usage
There are no pages that use this file.