Skip to content

Commit 9fa0b77

Browse files
committed
cleaned up some of the colouring geometry prototiles; added get_prototiles_from_vectors function
1 parent c34742a commit 9fa0b77

File tree

4 files changed

+71
-83
lines changed

4 files changed

+71
-83
lines changed

examples/scratch-pad.ipynb

+10-65
Large diffs are not rendered by default.

weavingspace/tileable.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ def get_local_patch(self, r: int = 1,
331331
if not include_0: # throw away the identity vector
332332
vecs.pop((0, 0, 0) if self.base_shape in (TileShape.HEXAGON,) else (0, 0))
333333
ids, tiles = [], []
334-
# we need to add the translated prototiles in order of their distance from # tile 0, esp. in the square case, i.e. something like this:
334+
# we need to add the translated prototiles in order of their distance from
335+
# tile 0, esp. in the square case, i.e. something like this:
335336
#
336337
# 5 4 3 4 5
337338
# 4 2 1 2 4

weavingspace/tiling_geometries.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,13 @@ def setup_hex_colouring(unit:"TileUnit") -> None:
647647
elif unit.n == 5:
648648
hexagon = affine.rotate(hexagon, 30, origin = (0, 0))
649649
w, h = h, w
650-
tr = [(-w, 3 * h / 8), (0, 3 * h / 8), ( w, 3 * h / 8),
651-
(-w / 2, -3 * h / 8), (w / 2, -3 * h / 8)]
650+
tr = [(-w, h / 4), (0, h / 4), ( w, h / 4),
651+
(-w / 2, -h / 2), (w / 2, -h / 2)]
652652
hexes = [affine.translate(hexagon, v[0], v[1]) for v in tr]
653653
_setup_base_tile(unit, TileShape.HEXAGON)
654654
unit.prototile.geometry = [geom.Polygon([
655-
(-9 * w / 8, -3 * h / 4), (-11 * w / 8, 0), (-9 * w / 8, 3 * h / 4),
656-
( 9 * w / 8, 3 * h / 4), ( 11 * w / 8, 0), ( 9 * w / 8, -3 * h / 4)
655+
(-w, -3 * h / 4), (-3 * w / 2, 0), (-w, 3 * h / 4),
656+
( w, 3 * h / 4), ( 3 * w / 2, 0), ( w, -3 * h / 4)
657657
])]
658658
elif unit.n == 6:
659659
hexagon = affine.rotate(hexagon, 30, origin = (0, 0))
@@ -686,12 +686,10 @@ def setup_hex_colouring(unit:"TileUnit") -> None:
686686
hexes = [affine.translate(hexagon, v[0], v[1]) for v in tr]
687687
_setup_base_tile(unit, TileShape.HEXAGON)
688688
unit.prototile.geometry = [geom.Polygon([
689-
(-11 * w / 8, -7 * h / 8), (-13 * w / 8, -5 * h / 8), (-7 * w / 8, 11 * h / 8),
690-
( 11 * w / 8, 7 * h / 8), ( 13 * w / 8, 5 * h / 8), ( 7 * w / 8, -11 * h / 8)
689+
(-3 * w / 2, -h), (-3 * w / 2, -h / 2), (-w, 5 * h / 4),
690+
( 3 * w / 2, h), ( 3 * w / 2, h / 2), ( w, -5 * h / 4)
691691
])]
692692
elif unit.n == 9:
693-
# Make a hexagon and displace in the direction of its
694-
# own 6 corners, scaled as needed
695693
_setup_base_tile(unit, TileShape.HEXAGON)
696694
offsets = [
697695
(-3 * w / 4, -5 * h / 4), (0, -3 * h / 4), ( 3 * w / 4, -5 * h / 4),
@@ -737,8 +735,8 @@ def setup_square_colouring(unit:"TileUnit") -> None:
737735
_setup_base_tile(unit, TileShape.HEXAGON)
738736
x = s * np.sqrt(2)
739737
unit.prototile.geometry = [geom.Polygon([
740-
(-5 * x / 8, -x / 2), (-7 * x / 8, 0), (-5 * x / 8, x / 2),
741-
( 5 * x / 8, x / 2), ( 7 * x / 8, 0), ( 5 * x / 8, -x / 2),
738+
(-x / 2, -x / 2), (-x, 0), (-x / 2, x / 2),
739+
( x / 2, x / 2), ( x, 0), ( x / 2, -x / 2),
742740
])]
743741
elif unit.n == 4:
744742
# Copy and translate square
@@ -753,7 +751,7 @@ def setup_square_colouring(unit:"TileUnit") -> None:
753751
_setup_base_tile(unit, TileShape.RECTANGLE)
754752
# Copy and translate square
755753
tr = [( 0, 0),
756-
(s, 0), (0, s),
754+
( s, 0), (0, s),
757755
(-s, 0), (0, -s)]
758756
squares = [affine.translate(sq, v[0], v[1]) for v in tr]
759757
rotation = np.degrees(np.arctan2(1, 2))
@@ -780,10 +778,11 @@ def setup_square_colouring(unit:"TileUnit") -> None:
780778
squares = [affine.translate(sq, v[0], v[1]) for v in tr]
781779
squares = [affine.rotate(sq, -45, (0, 0)) for sq in squares]
782780
_setup_base_tile(unit, TileShape.HEXAGON)
783-
unit.prototile.geometry = [affine.rotate(geom.Polygon([
784-
(-11 * s / 14, -23 * s / 14), (-17 * s / 14, -19 * s / 14), (-25 * s / 14, 5 * s / 14),
785-
( 11 * s / 14, 23 * s / 14), ( 17 * s / 14, 19 * s / 14), ( 25 * s / 14, -5 * s / 14)
786-
]), -45, (0, 0))]
781+
x = s * np.sqrt(2)
782+
unit.prototile.geometry = [geom.Polygon([
783+
(-x, -x / 2), (-3 * x / 2, 0), (-x / 2, x),
784+
( x, x / 2), ( 3 * x / 2, 0), ( x / 2, -x)
785+
])]
787786
elif unit.n == 8:
788787
# Copy and translate square
789788
tr = [(-s, -s), (0, -s), ( s, -s),
@@ -794,8 +793,8 @@ def setup_square_colouring(unit:"TileUnit") -> None:
794793
_setup_base_tile(unit, TileShape.HEXAGON)
795794
x = s * np.sqrt(2)
796795
unit.prototile.geometry = [geom.Polygon([
797-
(-3 * x / 4, -x), ( 3 * x / 4, -x), ( 5 * x / 4, 0),
798-
( 3 * x / 4, x), (-3 * x / 4, x), (-5 * x / 4, 0)
796+
(-x / 2, -x), ( x / 2, -x), ( 3 * x / 2, 0),
797+
( x / 2, x), (-x / 2, x), (-3 * x / 2, 0)
799798
])]
800799
elif unit.n == 9:
801800
# Copy and translate square

weavingspace/tiling_utils.py

+43
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,46 @@ def get_intersection(line1:StraightLine,
11291129
x = x if x_set else (line1.B * line2.C - line2.B * line1.C) / denominator
11301130
y = y if y_set else (line1.C * line2.A - line2.C * line1.A) / denominator
11311131
return geom.Point(x, y)
1132+
1133+
def get_prototiles_from_vectors(v1:tuple[float], v2:tuple[float]):
1134+
# parallelogram exists regardless
1135+
parallelogram = geom.Polygon([
1136+
geom.Point(0, 0), v1, (v1[0]+v2[0], v1[1]+v2[1]), v2])
1137+
# pc = parallelogram.centroid
1138+
# parallelogram = affine.translate(geom.Polygon, xoff=-pc.x, yoff=-pc.y)
1139+
triangle1 = ensure_cw(geom.Polygon([(0, 0), v1, v2]))
1140+
triangle2 = ensure_cw(geom.Polygon([(0, 0), v1, (-v2[0], -v2[1])]))
1141+
angles1 = get_interior_angles(triangle1)
1142+
angles2 = get_interior_angles(triangle2)
1143+
triangle = triangle1 if max(angles1) <= max(angles2) else triangle2
1144+
c = incentre(triangle)
1145+
# c = triangle.centroid
1146+
t_corners = [geom.Point(p[0] - c.x, p[1] - c.y)
1147+
for p in triangle.exterior.coords]
1148+
e_corners = [geom.Point(p.x + q.x, p.y + q.y)
1149+
for p, q in zip(t_corners[:-1], t_corners[1:])]
1150+
hex_corners = []
1151+
for i in range(3):
1152+
hex_corners.extend([t_corners[i], e_corners[i]])
1153+
hex = geom.Polygon(hex_corners)
1154+
hex = affine.translate(hex, -hex.centroid.x, -hex.centroid.y)
1155+
return parallelogram, hex
1156+
1157+
# p = [p for p in triangle.exterior.coords]
1158+
# e = [geom.Point(p2[0] - p1[0], p2[1] - p1[1])
1159+
# for p1, p2 in zip(p[:-1], p[1:])]
1160+
# e = [e[0], geom.Point(-e[1].x, -e[1].y), e[2]]
1161+
1162+
# # L1 = get_straight_line(geom.Point(0, 0), e[0], True)
1163+
# # L2 = get_straight_line(geom.Point(0, 0), e[1], True)
1164+
# # L3 = get_straight_line(geom.Point(0, 0), e[2], True)
1165+
# # L4 = get_straight_line(geom.Point(0, 0),
1166+
# # geom.Point(-e[0].x, -e[0].y), True)
1167+
# # c1 = get_intersection(L1, L2)
1168+
# # c2 = get_intersection(L2, L3)
1169+
# # c3 = get_intersection(L3, L4)
1170+
# # print(f'{c1=} {c2=} {c3=}')
1171+
# # hex = geom.Polygon([c1, c2, c3, geom.Point(-c1.x, -c1.y),
1172+
# # geom.Point(-c2.x, -c2.y), geom.Point(-c3.x, -c3.y)])
1173+
# return parallelogram, hex
1174+

0 commit comments

Comments
 (0)