Created
May 27, 2016 00:32
-
-
Save gagern/e9606b3f12d53ff92c4541e1e7b51d6d to your computer and use it in GitHub Desktop.
Cycles of regular polygons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://math.stackexchange.com/q/1798630/35416 | |
def polycycle(n, collected): | |
cf = CyclotomicField(n) | |
zeta = cf.gen() | |
corner = -2*(1 + zeta)/(1 + zeta + 1 + 1/zeta) | |
center = [corner*zeta^k for k in range(n)] | |
gra = [] | |
for m in range(3, 7): | |
mn = (m - 2)*n | |
if mn & 1: continue | |
for part in Partitions(mn//2, length=m): | |
for perm in set(map(tuple, CyclicPermutations(part))): | |
z = 0 | |
for k in perm: | |
z = z + 1 | |
z = -z * zeta^k | |
if z: continue | |
# print(perm) | |
corners = [] | |
overlap = False | |
for k in perm: | |
f = lambda p: -(p + 2) * zeta^k | |
corners = center + map(f, corners) | |
if any(CC(c*c.conjugate()).real() < 1 for c in corners): | |
overlap = True | |
break | |
if overlap: continue | |
polys = Graphics() | |
for k, poly in enumerate(matrix(cf, m, n, corners).rows()): | |
polys += polygon2d(map(CC, poly), | |
title="{} regular {}-gons".format(m, n), | |
color=hue(float(k/float(m)), 0.5, 0.5), | |
edgecolor="black") | |
polys.axes(False) | |
gra.append(polys) | |
if gra: | |
print "{} regular {}-gons".format(m, n) | |
break | |
collected.append(gra) | |
collected = [] | |
for i in range(3, 25): | |
polycycle(i, collected) | |
maxlen = max(map(len, collected)) | |
for row in collected: | |
while len(row) < maxlen: | |
row.append(Graphics()) | |
graphics_array(collected).show(axes=False, title=None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment