In [127]:
import math
%pylab inline
In [128]:
def createhex(xoff=1,yoff=1):
A = (math.cos(math.radians(30)), math.sin(math.radians(30)))
B = (math.cos(math.radians(90)), sin(math.radians(90)))
C = (math.cos(math.radians(150)), sin(math.radians(150)))
D = (math.cos(math.radians(210)), sin(math.radians(210)))
E = (math.cos(math.radians(270)), sin(math.radians(270)))
F = (math.cos(math.radians(330)), sin(math.radians(330)))
G = (math.cos(math.radians(30)), math.sin(math.radians(30)))
x,y = zip(A,B,C,D,E,F,G)
x = [i + xoff for i in x]
y = [i + yoff for i in y]
return x,y
In [129]:
figsize(8,8)
xoffset = math.cos(math.radians(30))
yoffset = math.sin(math.radians(30))
for i in range(2):
for j in range(2):
xoff = j * xoffset * 2
if i % 2 != 0:
xoff += xoffset
yoff = i * yoffset * 3
x,y = createhex(xoff, yoff)
plt.plot(x,y)
In [4]:
def createoct(xoff=1,yoff=1):
A = (math.cos(math.radians(45)), math.sin(math.radians(45)))
B = (math.cos(math.radians(90)), sin(math.radians(90)))
C = (math.cos(math.radians(135)), sin(math.radians(135)))
D = (math.cos(math.radians(180)), sin(math.radians(180)))
E = (math.cos(math.radians(225)), sin(math.radians(225)))
F = (math.cos(math.radians(270)), sin(math.radians(270)))
G = (math.cos(math.radians(315)), sin(math.radians(315)))
H = (math.cos(math.radians(360)), sin(math.radians(360)))
I = (math.cos(math.radians(45)), math.sin(math.radians(45)))
x,y = zip(A,B,C,D,E,F,G,H,I)
x = [i + xoff for i in x]
y = [i + yoff for i in y]
return x,y
In [5]:
x, y = createoct()
plt.plot(x,y)
Out[5]:
In [211]:
figsize=(4,4)
def createtri(xoff=1, yoff=1):
A = (-1, 0)
B = (1, 0)
C = (0, 1 * math.sqrt(3))
D = (-1, 0)
x,y = zip(A, B, C, D)
x = [i + xoff for i in x]
y = [i + yoff for i in y]
return x,y
def createinvtri(xoff=1, yoff=1):
A = (-1, 0)
B = (1, 0)
C = (0, -1 * math.sqrt(3))
D = (-1, 0)
x,y = zip(A, B, C, D)
x = [i + xoff for i in x]
y = [i + yoff for i in y]
return x,y
x, y = createtri()
plot(x,y, 'r-o')
x, y = createinvtri()
plot(x, y, 'b-o')
Out[211]:
In [335]:
xoffset = 0.5
yoffset = 1.0
for k in range(9):
if k %2 == 0:
for i in range(10):
xoff = i * xoffset * 4
for j in range(2):
if j % 2 != 0:
x, y = createinvtri(xoff, yoff)
else:
yoff = j + yoffset * 4
x,y = createtri(xoff, yoff)
plt.plot(x,y)
else:
yoff = (k + 1) * 1.9
for i in range(10):
xoff = (i * xoffset * 4) + (xoffset * 2)
for j in range(2):
if j % 2 != 0:
x, y = createtri(xoff, yoff)
else:
x, y = createinvtri(xoff, yoff)
plt.plot(x,y)
In [ ]: