From: Antonio Ospite Date: Wed, 27 Jun 2018 13:48:35 +0000 (+0200) Subject: Change how a trihexaflexagon is drawn X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/commitdiff_plain/5f2e900515a64fe483569855b89f26abcc89a441?hp=0535503e3f96e135b9a478df1a9ea8ef7fd206d5;ds=sidebyside Change how a trihexaflexagon is drawn Change how a trihexaflexagon is drawn to obtain a hexaflexagon more aligned with conventions used elsewhere. Now the hexagons are drawn with a "vertical orientation", opposed to the previous horizontal one where they looked like they were laying on the x axis. This shows more clearly that the triangles are grouped in couples and these couples only change orientation on one axis when shown on the "opposite" face. To have a clearer view of hat that means take a look at "The symmetry within the trihexaflexagon, with Simon Pampena": https://www.youtube.com/watch?v=NBJrGbbxceU --- diff --git a/src/flexagon/hexaflexagon_diagram.py b/src/flexagon/hexaflexagon_diagram.py index 09e8fc9..cdd636b 100755 --- a/src/flexagon/hexaflexagon_diagram.py +++ b/src/flexagon/hexaflexagon_diagram.py @@ -56,7 +56,7 @@ class HexaflexagonDiagram(object): cx = self.x_border + self.hexagon_radius + (2 * self.hexagon_radius + self.x_border) * hexagon.index self.hexagons_centers[hexagon.index] = (cx, cy) - triangles_centers = self.backend.get_regular_polygon(cx, cy, 6, self.triangle_radius) + triangles_centers = self.backend.get_regular_polygon(cx, cy, 6, self.triangle_radius, pi / 6) for triangle in hexagon.triangles: self.triangles_centers[hexagon.index][triangle.index] = triangles_centers[triangle.index] diff --git a/src/flexagon/trihexaflexagon.py b/src/flexagon/trihexaflexagon.py index d79875e..e3aab5c 100755 --- a/src/flexagon/trihexaflexagon.py +++ b/src/flexagon/trihexaflexagon.py @@ -39,19 +39,19 @@ 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. + return ((self.index + 5) % 6 // 2) * pi * 2 / 3 - pi / 6 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 +88,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 diff --git a/src/svg_hexaflexagon_editor.py b/src/svg_hexaflexagon_editor.py index f86ad13..48c8646 100755 --- a/src/svg_hexaflexagon_editor.py +++ b/src/svg_hexaflexagon_editor.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from math import pi import svgwrite from diagram.svgwrite_diagram import SvgwriteDiagram @@ -61,7 +60,7 @@ class SvgwriteHexaflexagonDiagram(HexaflexagonDiagram): # Draw some default content old_active_group = self.backend.active_group self.backend.active_group = self.groups["hexagon%d-content" % hexagon.index] - self.backend.draw_regular_polygon(cx, cy, 6, self.hexagon_radius, pi / 6., fill_color=(0.5, 0.5, 0.5, 0.2), stroke_color=None) + self.backend.draw_regular_polygon(cx, cy, 6, self.hexagon_radius, fill_color=(0.5, 0.5, 0.5, 0.2), stroke_color=None) self.backend.active_group = old_active_group # Add folding guides