FlatSurf Demo 1
system:sage


<p>Define the base field.</p>

{{{id=3|
K.<sqrt2> = NumberField(x**2 - 2, embedding=1.414)
///
}}}

<p>Note that <em>sqrt2</em> now stores the actual square root of 2.</p>

{{{id=8|
RR(sqrt2)
///
1.41421356237309
}}}

<h2>Constructing the regular octagon:</h2>

{{{id=9|
from flatsurf.geometry.polygon import Polygons
///
}}}

<p>The following is the parent for polygons with coordinates in the field K.</p>
<p>Remarks:</p>
<ul>
<li>The first vertex of our polygons is always the origin.</li>
<li>All our polygons are convex.&nbsp;</li>
</ul>

{{{id=11|
Polygons(K)
///
polygons with coordinates in Number Field in sqrt2 with defining polynomial x^2 - 2
}}}

<p>To construct a polygon, use the parent to build the parent. Passing a list of edge vectors will produce the polygon. The edge vectors must sum to zero.</p>

{{{id=5|
p = Polygons(K)([(1,0),
(sqrt2/2, sqrt2/2),
(0, 1),
(-sqrt2/2, sqrt2/2),
(-1,0),
(-sqrt2/2, -sqrt2/2),
(0, -1),
(sqrt2/2, -sqrt2/2)
])

print(p)
///
Polygon: (0, 0), (1, 0), (1/2*sqrt2 + 1, 1/2*sqrt2), (1/2*sqrt2 + 1, 1/2*sqrt2 + 1), (1, sqrt2 + 1), (0, sqrt2 + 1), (-1/2*sqrt2, 1/2*sqrt2 + 1), (-1/2*sqrt2, 1/2*sqrt2)
}}}

{{{id=10|
p.plot()
///
}}}

<h2>Defining a translation surface</h2>

<p>A translation surface is a gluing of one or more polygons with edge identifications glued by translation.</p>
<p><br />We will construct the octagon with opposite edges identified. Edges of our polygons are indexed by $[0, 1, 2, ..., n-1]$ where n is the number of sides of the polygon. An edge of a polygon is indexed by a pair $(p,e)$ where $p$ is a polygon index and $e$ is an edge index.</p>
<p><br />The gluings are specified as a list of pairs of edges of polygons. For example we want to the bottom edge $(0,0)$ to the top edge $(0,4)$.</p>

{{{id=19|
from flatsurf import *
///
}}}

<p>Define a surface built from polygons with vertices in K^2.</p>

{{{id=23|
surface = Surface_list(K)
///
}}}

<p>We add the polygon p to the surface. It gets a label, in this case 0.</p>

{{{id=60|
surface.add_polygon(p)
///
0
}}}

<p>We now glue the edges together. The line below says "glue edge e of polygon 0 to edge e+4 of polygon 0."</p>

{{{id=64|
for e in range(4):
    surface.change_edge_gluing(0,e,0,e+4)
///
}}}

<p>We want to view the surface we built as a translation surface.</p>

{{{id=24|
s=TranslationSurface(surface)
///
}}}

<p>Run some tests to make sure the surface is okay.</p>

{{{id=65|
TestSuite(s).run(verbose=True)
///
running ._test_base_label() . . . pass
running ._test_base_ring() . . . pass
running ._test_category() . . . pass
running ._test_edge_matrix() . . . pass
running ._test_gluings() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_override() . . . pass
running ._test_pickling() . . . pass
running ._test_polygons() . . . pass
}}}

<h2>Graphical surfaces:</h2>

<p>A graphical surface is a version of a surface which stores some extra data that can be used to draw the surface.</p>

{{{id=28|
gs=s.graphical_surface()
///
}}}

{{{id=29|
gs.plot()
///
}}}

<h2>Straight-line flow</h2>
<p>Construct the tangent vector in polygon 0 based at (0,0) pointed pointed in direction (1,2).&nbsp;</p>

{{{id=54|
v=s.tangent_vector(0,(0,0),(1,2))
print(v)
///
SimilaritySurfaceTangentVector in polygon 0 based at (0, 0) with vector (1, 2)
}}}

<p>You can convert the tangent vector to a StraightLineTrajectory, which is a finite list of intersections of the straight-line trajectory with the polygons defining the surface.</p>

{{{id=35|
traj=v.straight_line_trajectory()
///
}}}

{{{id=58|
print traj
///
Straight line trajectory made of 1 segments from (0, 0) in polygon 0 to (1/3*sqrt2 + 2/3, 2/3*sqrt2 + 4/3) in polygon 0
}}}

{{{id=57|
gs.plot()+traj.graphical_trajectory(gs).plot()
///
}}}

<p>The <em>flow(n)</em>&nbsp;method constructs the next <em>n</em> segments obtained by straight-line flowing forward and intersecting with the provided polygons. It will just stop if a singularity is hit.</p>

{{{id=39|
traj.flow(100)
print(traj)
print("It has length: "+str(traj.combinatorial_length()))
///
Straight line trajectory made of 17 segments from (0, 0) in polygon 0 to (0, sqrt2 + 1) in polygon 0
It has length: 17
}}}

{{{id=43|
traj.is_saddle_connection()
///
True
}}}

<p>We can draw a picture of this saddle connection by converting it to a&nbsp;GraphicalStraightLineTrajectory.</p>

{{{id=44|
gtraj = traj.graphical_trajectory(gs)
///
}}}

{{{id=53|
gs.plot()+gtraj.plot()
///
}}}