Graphics Configuration

Rearranging Polygons

from flatsurf.geometry.polyhedra import platonic_dodecahedron

s = platonic_dodecahedron()[1]

The default plot of this surface:

s.plot()
../_images/56971cf10c7736a04086d53eb87e750582d51dbee8f6ba2be8a8311d231361f2.png

Labels in the center of each polygon indicate the label of the polygon. Edge labels above indicate which polygon the edge is glued to.

Plotting the surface is controlled by a GraphicalSurface object:

gs = s.graphical_surface()

The graphical surface controls where polygons are drawn. You can glue a polygon across an edge using gs.make_adjacent(label, edge). A difficulty is that you need to know which edge is which. You can enable zero_flags to see the zero vertex of each polygon.

gs.will_plot_zero_flags = True
gs.plot()
../_images/872b30fef8f85cba5aadabf3cd3b3e812c2792da2aa7e95c6696644f10a6ede4.png

sage-flatsurf uses a simple algorithm to layout polygons. Sometimes polygons overlap. But in this example the main concern is maybe that the picture is not as symmetric as we would like it to be. For example, we could aim for things to be symmetric around the polygons 0 and 1. Let’s say we would like to move polygon 2 so that it’s glued to 10 instead of being glued to 0. We count the edges on polygon 10 until we reach the edge glued to 2. It’s the first one. We can verify that this is correct:

s.opposite_edge(10, 0)
(2, 3)

We can move polygon 2 so that it is adjacent to polygon 10 with the command:

gs.make_adjacent(10, 0)

Lets check that it worked:

gs.plot()
../_images/c29e1fd07d053be46e09c2f609292300a38b4cabf5b67c2a198cdeec7e7a631f.png

Let’s build the symmetric widget at polygon 1 by moving 7 to be adjacent to 5 and 3 to be adjacent to 7. Note that the order of the movements matter. If we do it in the wrong order, we detach things:

gs.make_adjacent(7, 3)
gs.make_adjacent(5, 4)
gs.plot()
../_images/989e3cd0e697121200ab1d60919a311f11c30f99d9a44acff5b1cbcdab46d5c5.png

Indeed, we moved 3 to be adjacent to 7 but then moved 7 away. Let’s do it in the correct order:

gs.make_adjacent(5, 4)
gs.make_adjacent(7, 3)
gs.plot()
../_images/06a75aca20054f12f3f745739e21bc618216dbd702c477cdb649ba0825d9dcef.png

Finally, glue 9 to 8 for a symmetric picture:

gs.make_adjacent(8, 0)
gs.plot()
../_images/b62416564de7ba069dde4c7da44c9d12d06c78130dc1e26ccce521dd006c38b1.png

Moving between coordinate systems

The Euclidean Cone Surface s works in a different coordinate system then the graphical surface gs. So, when we moved the polygon above, we had no affect on s. In fact, the polygons of s are all the same:

s.polygon(0)
Polygon(vertices=[(0, 0), (2, 0), (-a^2 + 4, a^3 - 3*a), (1, a^3 - 4*a), (a^2 - 2, a^3 - 3*a)])
s.polygon(1)
Polygon(vertices=[(0, 0), (2, 0), (-a^2 + 4, a^3 - 3*a), (1, a^3 - 4*a), (a^2 - 2, a^3 - 3*a)])

So really s is a disjoint union of twelve copies of a standard pentagon with some edge gluings.

Lets now look at “graphical coordinates” i.e., the coordinates in which gs works.

show(gs.plot(), axes=True)
../_images/783e5aefb304e9c1be951946b9d6066391b1df0988c3def1896eb598cd6029fe.png

We can tell that the point (4, -4) is in the unfolding, but we can’t immediately tell if it is in polygon 5 or 7. The GraphicalSurface gs is made out of GraphicalPolygons which we can use to deal with this sort of thing.

gs.graphical_polygon(5).contains((4, -4))
False
gs.graphical_polygon(7).contains((4, -4))
True

Great. Now we can get the position of the point on the surface!

gp = gs.graphical_polygon(7)
pt = gp.transform_back((4, -4))
pt
(a^2 - 2*a - 4, a^3 + 2*a^2 - 5*a - 6)

Here we plot polygon 7 in its geometric coordinates with pt.

s.polygon(7).plot() + point2d([pt], zorder=100, color="red")
../_images/7229feee73c576b86cda848d4f67e3ff4a2983d17cd71c95a3b8d421b2c82d0a.png

Lets convert it to a surface point and plot it!

Note that we will have to pass the graphical surface to the point so it plots with respect to gs and not with respect to s.graphical_surface.

spt = s.point(7, pt)
spt
Point (a^2 - 2*a - 4, a^3 + 2*a^2 - 5*a - 6) of polygon 7
gs.plot() + spt.plot(gs, color="red", size=20)
../_images/946ad76c17c9f4503cdc3ade7379d187cb0af56ea8243f5192029a0b342c411a.png

Now we want to plot an upward trajectory through this point. Again, we have to deal with the fact that the coordinates might not match. You can get access to the transformation (a similarity) from geometric coordinates to graphical coordinates:

transformation = gs.graphical_polygon(7).transformation()
transformation
(x, y) |-> ((-1/2*a^2 + 3/2)*x + (-1/2*a)*y + (-a^2 + 5), (1/2*a)*x + (-1/2*a^2 + 3/2)*y + (-2*a^3 + 7*a))

Really we want the inverse:

inverse_transformation = ~transformation
inverse_transformation
(x, y) |-> ((-1/2*a^2 + 3/2)*x + (1/2*a)*y + (3*a^2 - 10), (-1/2*a)*x + (-1/2*a^2 + 3/2)*y + (a^3 - 3*a))

We just want the derivative of this similarity to transform the vertical direction. The derivative is a \(2 \times 2\) matrix.

show(inverse_transformation.derivative())
\(\displaystyle \left(\begin{array}{rr} -\frac{1}{2} a^{2} + \frac{3}{2} & \frac{1}{2} a \\ -\frac{1}{2} a & -\frac{1}{2} a^{2} + \frac{3}{2} \end{array}\right)\)
direction = inverse_transformation.derivative() * vector((0, 1))
direction
(1/2*a, -1/2*a^2 + 3/2)

We can use the point and the direction to get a tangent vector, which we convert to a trajectory, flow and plot.

tangent_vector = s.tangent_vector(7, pt, direction)
tangent_vector
SimilaritySurfaceTangentVector in polygon 7 based at (a^2 - 2*a - 4, a^3 + 2*a^2 - 5*a - 6) with vector (1/2*a, -1/2*a^2 + 3/2)
traj = tangent_vector.straight_line_trajectory()
traj.flow(100)
traj.is_closed()
True
gs.plot() + spt.plot(gs, color="red") + traj.plot(gs, color="orange")
../_images/b0ddee28720cf3ae942810238cbda5c04a3fb7b82bd8da13399bb9538d53a6d2.png

Multiple graphical surfaces

It is possible to have more than one graphical surface. Maybe you want to have one where things look better. To get a new surface, you can call s.graphical_surface() again.

pretty_gs = s.graphical_surface(polygon_labels=False, edge_labels=False)
pretty_gs.plot()
../_images/e151d8a9a79e88a689b5446415132113147f24d7a58afa97d8f2c71ca7556238.png

Current polygon printing options:

pretty_gs.polygon_options
{'color': 'lightgray'}
del pretty_gs.polygon_options["color"]
pretty_gs.polygon_options["rgbcolor"] = "#ffeeee"
pretty_gs.non_adjacent_edge_options["thickness"] = 0.5
pretty_gs.non_adjacent_edge_options["color"] = "lightblue"
pretty_gs.will_plot_adjacent_edges = False
pretty_gs.plot()
../_images/d2af998b0f1685a88862d715b3688475a87513320d5ba47667ef04324f850deb.png

Again, to use a non-default graphical surface, we need to pass the graphical surface as a parameter.

pretty_gs.plot() + spt.plot(pretty_gs, color="red") + traj.plot(pretty_gs)
../_images/0c7242c8f89a3b296112f7cf25bc1ffc7996c943bd8250211bca5474a3818c95.png

Lets make it prettier by drawing some stars on the faces!

Find all saddle connections of length at most \(\sqrt{16}\):

saddle_connections = s.saddle_connections(16)

The edges have length two so we will keep anything that has a different length.

saddle_connections2 = []
for sc in saddle_connections:
    h = sc.holonomy()
    if h[0] ** 2 + h[1] ** 2 != 4:
        saddle_connections2.append(sc)
len(saddle_connections2)
120
plot = pretty_gs.plot()
for sc in saddle_connections2:
    plot += sc.plot(pretty_gs, color="red")
plot
../_images/0e4b14f7003ac0bbff34b7e44b18e8a4070f5477c15776b963326efa5c0eb790.png

Plot using the original graphical surface.

plot = s.plot()
for sc in saddle_connections2:
    plot += sc.plot(color="red")
plot
../_images/afd961034657e90aaccf36bc558454a1e155c85363b84f8802e372ee15ba28de.png

Manipulating edge labels

from flatsurf import translation_surfaces

s = translation_surfaces.arnoux_yoccoz(4)
s.plot()
../_images/70b8798eb4eff1fcc44fbca3382e905082d29a9e26d988c9b6a114421ef5930a.png

Here is an example with the edge labels centered on the edge.

gs = s.graphical_surface()
del gs.polygon_options["color"]
gs.polygon_options["rgbcolor"] = "#eee"
gs.edge_label_options["position"] = "edge"
gs.edge_label_options["t"] = 0.5
gs.edge_label_options["push_off"] = 0
gs.edge_label_options["color"] = "green"
gs.adjacent_edge_options["thickness"] = 0.5
gs.will_plot_non_adjacent_edges = False
gs.plot()
../_images/496b3e75aa968cd76677ee15d105e536985cc72512557e1016a96fc352dd1148.png
gs = s.graphical_surface()
del gs.polygon_options["color"]
gs.polygon_options["rgbcolor"] = "#eef"
gs.edge_label_options["position"] = "outside"
gs.edge_label_options["t"] = 0.5
gs.edge_label_options["push_off"] = 0.02
gs.edge_label_options["color"] = "green"
gs.adjacent_edge_options["thickness"] = 0.5
gs.non_adjacent_edge_options["thickness"] = 0.25
gs.plot()
../_images/a428a69e9b4747bac4c7dfc22d0fd083373c5ba1b80171cc820c78021eb018e0.png