X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/blobdiff_plain/b0d293a76ed3a595754b643f48b2f2d1b03395f6..3143f02f27e92c9d3475485e706bce8ffd73b6b3:/src/flexagon/trihexaflexagon.py diff --git a/src/flexagon/trihexaflexagon.py b/src/flexagon/trihexaflexagon.py index d79875e..7bd4f72 100755 --- a/src/flexagon/trihexaflexagon.py +++ b/src/flexagon/trihexaflexagon.py @@ -39,19 +39,34 @@ class Triangle(object): def get_angle_in_plan(self): """The angle of a triangle in the hexaflexagon plan.""" - return - ((self.index + 1) % 2) * pi / 3. + return - ((self.index) % 2) * pi / 3. def get_angle_in_plan_relative_to_hexagon(self): """"Get the angle of the triangle in the plan relative to the rotation of the same triangle in the hexagon.""" - return ((self.index + 4) % 6 // 2) * pi * 2. / 3. + # The explicit formula for this angle would be: + # + # pi + pi / 6 + (((self.index + 1) % 6) // 2) * pi * 2 / 3 + # + # The meaning of the part regarding the index is the following: + # - rotate the indices by 1 + # - group by 2 (because couples of triangles move together in the + # plan) + # - multiply the group by a rotation factor + # + # The explicit formula shows clearly that triangles move in groups of + # 2 in the plan. + # + # However, use an implicit form for robustness, so that if the other + # angle functions change this one can be left untouched. + return self.get_angle_in_hexagon() - self.get_angle_in_plan() def get_angle_in_hexagon(self): """Get the angle of the triangle in the hexagons. NOTE: the angle is rotated by pi to have the first triangle with the base on the bottom.""" - return pi + self.index * pi / 3. + return pi + pi / 6. + self.index * pi / 3. def __str__(self): return "%d,%d" % (self.hexagon.index, self.index) @@ -88,8 +103,8 @@ class TriHexaflexagon(object): # a pair (h, t), where 'h' is the index of the hexagon, and 't' is the # index of the triangle in that hexagon. plan_map = [ - [(0, 0), (1, 5), (1, 4), (2, 3), (2, 2), (0, 3), (0, 2), (1, 1), (1, 0)], - [(2, 5), (2, 4), (0, 5), (0, 4), (1, 3), (1, 2), (2, 1), (2, 0), (0, 1)] + [(0, 5), (1, 4), (1, 3), (2, 2), (2, 1), (0, 2), (0, 1), (1, 0), (1, 5)], + [(2, 4), (2, 3), (0, 4), (0, 3), (1, 2), (1, 1), (2, 0), (2, 5), (0, 0)] ] # Preallocate a bi-dimensional array for an inverse mapping, this is