svg_hexaflexagon_editor: draw also the backfaces
[flexagon-toolkit.git] / src / flexagon / trihexaflexagon.py
index faf4d90..ca21726 100755 (executable)
@@ -37,6 +37,10 @@ class Triangle(object):
 
         return xoffset, yoffset
 
+    def get_backface_index(self):
+        # The backfaces have the triangles in the reverse rotational order
+        return 5 - self.index
+
     def get_angle_in_plan(self):
         """The angle of a triangle in the hexaflexagon plan."""
         return - ((self.index) % 2) * pi / 3.
@@ -44,12 +48,32 @@ class Triangle(object):
     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."""
-        # The meaning of the formula regarding the index is the following:
+        # 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
-        return pi + pi / 6 + (((self.index + 1) % 6) // 2) * pi * 2 / 3
+        #
+        # 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_backface_relative_to_hexagon(self):
+
+        """"Get the angle of the triangle in the backface relative to the
+        rotation of the same triangle in the hexagon."""
+
+        backface_triangle_index = self.get_backface_index()
+        # group triangles in couples
+        group = (((backface_triangle_index + 1) % 6) // 2)
+        return pi + pi * 2 / 3 * group
 
     def get_angle_in_hexagon(self):
         """Get the angle of the triangle in the hexagons.