We need to tell SAGE about FlatSurf. Change the following to the directory of the FlatSurf source code.
{{{id=1| sys.path.append('/home/pat/active/talks/2016/Oaxaca-SAGE_Days/sage-flatsurf-master') /// }}}Define the base field.
{{{id=3| K.Note that sqrt2 now stores the actual square root of 2.
{{{id=8| RR(sqrt2) /// 1.41421356237309 }}}The following is the parent for polygons with coordinates in the field K.
Remarks:
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.
{{{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() /// }}}A translation surface is a gluing of one or more polygons with edge identifications glued by translation.
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.
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)$.
The TranslationSurface_polygons_and_gluings class can be used to construct a translation surface from a finite list of polygons and the gluing data which must mention every edge.
{{{id=24| s=TranslationSurface_polygons_and_gluings([p], gluings) /// }}}A graphical surface is a version of a surface which stores some extra data that can be used to draw the surface.
{{{id=28| gs=s.graphical_surface() /// }}} {{{id=29| gs.plot() /// }}}Construct the tangent vector in polygon 0 based at (0,0) pointed pointed in direction (1,2).
{{{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) }}}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.
{{{id=35| traj=v.straight_line_trajectory() /// }}} {{{id=58| print traj /// StraightLineTrajectorydeque([Segment in polygon 0 starting at (0, 0) and ending at (1/3*sqrt2 + 2/3, 2/3*sqrt2 + 4/3)]) }}} {{{id=57| gs.plot()+traj.graphical_trajectory(gs).plot() /// }}}The flow(n) method constructs the next n segments obtained by straight-line flowing forward and intersecting with the provided polygons. It will just stop if a singularity is hit.
{{{id=39| traj.flow(100) print(traj) print("It has length: "+str(traj.combinatorial_length())) /// StraightLineTrajectorydeque([Segment in polygon 0 starting at (0, 0) and ending at (1/3*sqrt2 + 2/3, 2/3*sqrt2 + 4/3), Segment in polygon 0 starting at (-1/6*sqrt2 - 1/3, 1/6*sqrt2 + 1/3) and ending at (1/4*sqrt2, sqrt2 + 1), Segment in polygon 0 starting at (1/4*sqrt2, 0) and ending at (1/2*sqrt2 + 2/3, 1/2*sqrt2 + 4/3), Segment in polygon 0 starting at (-1/3, 1/3) and ending at (1/2*sqrt2, sqrt2 + 1), Segment in polygon 0 starting at (1/2*sqrt2, 0) and ending at (2/3*sqrt2 + 2/3, 1/3*sqrt2 + 4/3), Segment in polygon 0 starting at (1/6*sqrt2 - 1/3, -1/6*sqrt2 + 1/3) and ending at (1/2*sqrt2 + 1/3, 1/2*sqrt2 + 5/3), Segment in polygon 0 starting at (-2/3, 2/3) and ending at (1/2*sqrt2 - 1/2, sqrt2 + 1), Segment in polygon 0 starting at (1/2*sqrt2 - 1/2, 0) and ending at (2/3*sqrt2 + 1/3, 1/3*sqrt2 + 5/3), Segment in polygon 0 starting at (1/6*sqrt2 - 2/3, -1/6*sqrt2 + 2/3) and ending at (3/4*sqrt2 - 1/2, sqrt2 + 1), Segment in polygon 0 starting at (3/4*sqrt2 - 1/2, 0) and ending at (5/6*sqrt2 + 1/3, 1/6*sqrt2 + 5/3), Segment in polygon 0 starting at (1/3*sqrt2 - 2/3, -1/3*sqrt2 + 2/3) and ending at (sqrt2 - 1/2, sqrt2 + 1), Segment in polygon 0 starting at (sqrt2 - 1/2, 0) and ending at (1/2*sqrt2 + 1, -sqrt2 + 3), Segment in polygon 0 starting at (-1/2*sqrt2, -sqrt2 + 3) and ending at (sqrt2 - 2, 2*sqrt2 - 1), Segment in polygon 0 starting at (3/2*sqrt2 - 1, 3/2*sqrt2 - 2) and ending at (1/2*sqrt2 + 1, -1/2*sqrt2 + 2), Segment in polygon 0 starting at (-1/2*sqrt2, -1/2*sqrt2 + 2) and ending at (1/2*sqrt2 - 1, 3/2*sqrt2), Segment in polygon 0 starting at (sqrt2, sqrt2 - 1) and ending at (1/2*sqrt2 + 1, 1), Segment in polygon 0 starting at (-1/2*sqrt2, 1) and ending at (0, sqrt2 + 1)]) It has length: 17 }}} {{{id=43| traj.is_saddle_connection() /// True }}}We can draw a picture of this saddle connection by converting it to a GraphicalStraightLineTrajectory.
{{{id=44| gtraj = traj.graphical_trajectory(gs) /// }}} {{{id=53| gs.plot()+gtraj.plot() /// }}}