{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial: Tropical arithmetics and tropical geometry\n",
    "\n",
    "This tutorial showcases the main features of application tropical, such as\n",
    "\n",
    "* Tropical arithmetics\n",
    "* Tropical convex hull computations\n",
    "* Tropical cycles and hypersurfaces.\n",
    "* Tropical intersection theory\n",
    "\n",
    "To use the full palette of tools for tropical geometry, switch to the corresponding application by typing the following in the `polymake` shell:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "application 'tropical';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Disclaimer: Min or Max - you have to choose!\n",
    "\n",
    "Most objects and data types related to tropical computations have a template parameter which tells it whether Min or Max is used as tropical addition. There is **no default** for this, so you have to choose! \n",
    "\n",
    "#### a-tint\n",
    "\n",
    "For a while now, polymake comes bundled with the extension [a-tint](https://github.com/simonhampe/atint) by Simon Hampe, which specializes in (but is not limited to) tropical intersection theory, and in fact supplies a big part of polymakes functionality related to tropical geometry. You can find a non-comprehensive list of features [here](https://github.com/simonhampe/atint/wiki/Feature-list).\n",
    "\n",
    "#### Further reading\n",
    "\n",
    "If you want to learn more you might want to check out:\n",
    "\n",
    "* Simon Hampe & Michael Joswig: <a href=\"https://link.springer.com/chapter/10.1007/978-3-319-70566-8_14\">Tropical Computations in <tt>polymake</tt></a>, Algorithmic and Experimental Methods in Algebra, Geometry, and Number Theory, pp 361-385 (2018)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tropical arithmetics\n",
    "\n",
    "You can create an element of the tropical semiring (over the rationals) simply by writing something like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "$a = new TropicalNumber<Max>(4);\n",
    "$b = new TropicalNumber<Min>(4);\n",
    "$c = new TropicalNumber<Min>(\"inf\");"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "You can now do basic arithmetic - that is **tropical** addition and multiplication with these. Note that tropical numbers with different tropical additions don't mix!\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $a * $a;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $b + $c*$b;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print $a + $b; # this won't work!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Tropical vector/matrix arithmetics also work - you can even ask for the tropical determinant!\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0 1 2\n",
       "0 -inf 3\n",
       "0 0 -inf\n"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$m = new Matrix<TropicalNumber<Max>>([[0,1,2],[0,\"-inf\",3],[0,0,\"-inf\"]]);\n",
    "$v = new Vector<TropicalNumber<Max>>(1,1,2);\n",
    "print $m + $m;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4 5 1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $m * $v;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print tdet($m);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, you can also create tropical polynomials. This can be done with the special toTropicalPolynomial parser:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "x_0^2 + x_1*x_2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$q = toTropicalPolynomial(\"min(2a,b+c)\");\n",
    "print $q;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Homogeneous and extended coordinates\n",
    "\n",
    "All higher tropical objects (trop. polytopes, cycles, ...) live in the *tropical projective torus* $ \\mathbb R^n/\\mathbb R\\mathbf 1\\cong \\mathbb R^{n-1}$ (or in its natural compactification, the tropical projective space), i.e. they are defined in (tropically) homogeneous coordinates, and points are given via their unique representative whose first entry is $0$ (e.g. $(1,2,3)$ becomes $(0,1,2)$ etc.).\n",
    "\n",
    "At the same time many properties (e.g. `VERTICES`) expect coordinates to be \"extended\" with an additional leading entry, which signals whether the vector should be interpreted as a conventional point in the torus (leading entry $ \\mathbf 1$), or as a ray/direction/\"point at infinity\" (leading entry $ \\mathbf 0$).\n",
    "You can read [here](coordinates.ipynb) for how this makes sense, or just think of the leading entry as purely symbolic.\n",
    "\n",
    "Note that this contrasts to conventional real/complex/... projective coordinates, where this extension is not needed, since there the leading entry naturally indicates either an affine point ($1$) or point at infinity ($0$) - again, see [here](coordinates.ipynb).\n",
    "\n",
    "**Example**: the standard tropical max-line in the trop. 2-torus can be defined by 4 points in extended homogeneous coordinates: a point $(\\mathbf 1,0,0,0)$ and 3 \"rays\" $(\\mathbf 0,0,-1,0)$, $(\\mathbf 0,0,0,-1)$, and $(\\mathbf 0,0,1,1)$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Helper functions\n",
    "\n",
    "Since it can be tedious to write everything in tropically homogeneous coordinates, especially when you are already working with affine coordinates, Polymake provides the functions `thomog` and `tdehomog` to homogenize or dehomogenize (extended) coordinates, respectively.\n",
    "\n",
    "Both have signature `(matrix, chart=0, has_leading_coordinate=1)`, where `matrix` is a list of vectors that you want to (de)homogenize, `has_leading coordinate` is a boolean indicating whether we are dealing with extended coordinates (i.e. vectors have an additional leading coordinate), and `chart` is the index of the coordinate that is set to $0$ when identifying $ \\mathbb R^n/\\mathbb R\\mathbf 1$ with $ \\mathbb R^{n-1}$ (i.e. homogenizing works by simply adding a $0$ entry at index `chart`, dehomogenizing works by taking the representative whose entry at position `chart` is $0$, and then deleting that entry), all while ignoring the first entry if `has_leading_coordinate` is `1`.\n",
    "\n",
    "Some examples:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 0 3 4\n",
       "0 0 5 6\n"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print thomog([[1,3,4],[0,5,6]]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2 0 3 4\n"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print thomog([[2,3,4]], 1, 0);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 1 2\n"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print tdehomog([[1,3,4,5]]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1 1 2\n"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print tdehomog([[2,3,4,5]], 1, 0);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tropical convex hull computations\n",
    "\n",
    "The basic object for tropical convex hull computations is `Polytope` (**Careful:** If you're not in application tropical, be sure to use the namespace identifier `tropical::Polytope` to distinguish it from the `polytope::Polytope`).\n",
    "\n",
    "A tropical polytope should always be created via `POINTS` (i.e. not `VERTICES`), since they determine the combinatorial structure. The following creates a tropical line segment in the tropical projective plane. Note that the point (0,1,1) is not a vertex, as it is in the tropical convex hull of the other two points. However, it does play a role when computing the corresponding subdivision of the tropical projective torus into covector cells:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0 0 0\n",
       "0 2 1\n"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$c = new Polytope<Min>(POINTS=>[[0,0,0],[0,1,1],[0,2,1]]);\n",
    "print $c->VERTICES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0:1 0 1 1\n",
       "1:0 0 -1 0\n",
       "2:1 0 0 0\n",
       "3:1 0 2 1\n",
       "4:0 0 0 -1\n",
       "5:0 0 1 1\n"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details><summary><pre style=\"display:inline\"><small>Click here for additional output</small></pre></summary>\n",
       "<pre>\n",
       "polymake: used package cdd\n",
       "  cddlib\n",
       "  Implementation of the double description method of Motzkin et al.\n",
       "  Copyright by Komei Fukuda.\n",
       "  http://www-oldurls.inf.ethz.ch/personal/fukudak/cdd_home/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print rows_labeled($c->PSEUDOVERTICES);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0 1 2}\n",
       "{0 1 5}\n",
       "{0 2 4}\n",
       "{0 3 4}\n",
       "{0 3 5}\n",
       "{1 2 4}\n",
       "{3 4 5}\n"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $c->MAXIMAL_COVECTOR_CELLS; #Sets of PSEUDOVERTICES. They are maximal cells of the induced subdivision of the torus."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0 2}\n",
       "{0 3}\n"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $c->POLYTOPE_MAXIMAL_COVECTOR_CELLS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are many visualization backends in <tt>polymake</tt>.  Calling <tt>svg</tt> suits best for (static) Jupyter notebooks.  The default is <tt>threejs</tt>, which is interactive."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n",
       "<svg height=\"841pt\" id=\"document\" viewBox=\"0 -354 572 354\" width=\"595pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "\t<title id=\"document_title\">pcom:</title>\n",
       "\t<polygon points=\"33.5,-224.323529411765 33.5,-146.676470588235 219.852941176471,-146.676470588235 297.5,-224.323529411765 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"219.852941176471\" cy=\"-146.676470588235\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"390.676470588235,-317.5 33.5,-317.5 33.5,-224.323529411765 297.5,-224.323529411765 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"297.5,-224.323529411765 219.852941176471,-146.676470588235 219.852941176471,-53.5 297.5,-53.5 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"219.852941176471\" cy=\"-146.676470588235\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"375.147058823529,-224.323529411765 297.5,-224.323529411765 297.5,-53.5 375.147058823529,-53.5 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<circle cx=\"375.147058823529\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"468.323529411765,-317.5 390.676470588235,-317.5 297.5,-224.323529411765 375.147058823529,-224.323529411765 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"375.147058823529\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"219.852941176471,-146.676470588235 33.5,-146.676470588235 33.5,-53.5 219.852941176471,-53.5 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"219.852941176471\" cy=\"-146.676470588235\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<polygon points=\"375.147058823529,-53.5 561.5,-53.5 561.5,-317.5 468.323529411765,-317.5 375.147058823529,-224.323529411765 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"375.147058823529\" cy=\"-224.323529411765\" r=\"2\" style=\"fill: rgb(255,255,0)\" />\n",
       "\t<!--\n",
       "\tGenerated using the Perl SVG Module V2.84\n",
       "\tby Ronan Oger\n",
       "\tInfo: http://www.roitsystems.com/\n",
       "\t-->\n",
       "</svg>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<details><summary><pre style=\"display:inline\"><small>Click here for additional output</small></pre></summary>\n",
       "<pre>\n",
       "polymake: used package SVG\n",
       "   Generated using the Perl SVG Module\n",
       "   by Ronan Oger\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "svg($c->VISUAL_SUBDIVISION);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In case you're just interested in either the subdivision of the full torus, or the polyhedral structure of the tropical polytope, the following will give you those structures as `fan::PolyhedralComplex` objects in *affine* coordinates:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 1 1\n",
       "1 0 0\n",
       "1 2 1\n"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$t = $c->torus_subdivision_as_complex;\n",
    "$p = $c->polytope_subdivision_as_complex;\n",
    "print $p->VERTICES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0 2}\n",
       "{0 3}\n"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->MAXIMAL_POLYTOPES;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that by default, the affine chart is {x_0 = 0}. You can choose any chart {x_i = 0} by passing i as an argument to `.._subdivision_as_complex`.\n",
    "\n",
    "Polymake computes the full subdivision of both the torus and the polytope as a `CovectorLattice`, which is just a `FaceLattice` with an additional map that attaches to each cell in the subdivision its covector. For more details on this data structure see the [ reference documentation](http://polymake.org/release_docs/latest/tropical.html ). You can visualize the covector lattice with"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n",
       "<svg height=\"841pt\" id=\"document\" viewBox=\"0 -824 570 824\" width=\"595pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "\t<title id=\"document_title\">unnamed</title>\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"296.482545008711\" x2=\"315.483791793803\" y1=\"-66.5\" y2=\"-243.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"296.482545008711\" x2=\"125.471323942883\" y1=\"-66.5\" y2=\"-243.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"296.482545008711\" x2=\"374.598781791868\" y1=\"-66.5\" y2=\"-243.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"315.483791793803\" x2=\"178.252565012583\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"315.483791793803\" x2=\"355.597535006775\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"315.483791793803\" x2=\"414.71252500484\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"315.483791793803\" x2=\"237.367555010647\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"315.483791793803\" x2=\"532.942505000968\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"125.471323942883\" x2=\"178.252565012583\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"125.471323942883\" x2=\"119.137575014519\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"125.471323942883\" x2=\"60.0225850164548\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"374.598781791868\" x2=\"355.597535006775\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"374.598781791868\" x2=\"296.482545008711\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"374.598781791868\" x2=\"473.827515002904\" y1=\"-243.5\" y2=\"-420.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"178.252565012583\" x2=\"239.478804653435\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"178.252565012583\" x2=\"163.473817513067\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"355.597535006775\" x2=\"298.593794651499\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"355.597535006775\" x2=\"433.380416583176\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"414.71252500484\" x2=\"239.478804653435\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"414.71252500484\" x2=\"492.49540658124\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"237.367555010647\" x2=\"163.473817513067\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"237.367555010647\" x2=\"298.593794651499\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"532.942505000968\" x2=\"433.380416583176\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"532.942505000968\" x2=\"492.49540658124\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"119.137575014519\" x2=\"239.478804653435\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"119.137575014519\" x2=\"100.469683436183\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"60.0225850164548\" x2=\"163.473817513067\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"60.0225850164548\" x2=\"100.469683436183\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"296.482545008711\" x2=\"298.593794651499\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"296.482545008711\" x2=\"374.265426585112\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"473.827515002904\" x2=\"433.380416583176\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"473.827515002904\" x2=\"374.265426585112\" y1=\"-420.5\" y2=\"-597.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"239.478804653435\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"163.473817513067\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"298.593794651499\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"433.380416583176\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"492.49540658124\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"100.469683436183\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"374.265426585112\" x2=\"296.482545008711\" y1=\"-597.5\" y2=\"-774.5\" />\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"5.1727753758792\" x=\"293.896157320772\" y=\"-69.3500139812007\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"296.482545008711\" y=\"-65.6093706308748\"></text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"290.852545961277\" y=\"-246.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"315.483791793803\" y=\"-242.609370630875\">{0}\\\\( 1 2 , 0 1 , 0 1 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"42.4794583897959\" x=\"104.231594747985\" y=\"-246.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"125.471323942883\" y=\"-242.609370630875\">{2}\\\\( 0 1 2 , 0 , 0 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"42.4794583897959\" x=\"353.35905259697\" y=\"-246.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"374.598781791868\" y=\"-242.609370630875\">{3}\\\\( 2 , 0 1 2 , 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"42.4794583897959\" x=\"157.012835817685\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"178.252565012583\" y=\"-419.609370630875\">{0 2}\\\\( 1 2 , 0 , 0 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"42.4794583897959\" x=\"334.357805811878\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"355.597535006775\" y=\"-419.609370630875\">{0 3}\\\\( 2 , 0 1 , 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"390.081279172313\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"414.71252500484\" y=\"-419.609370630875\">{0 1}\\\\( 1 2 , - , 0 1 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"214.432067496935\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"237.367555010647\" y=\"-419.609370630875\">{0 4}\\\\( 1 2 , 0 1 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"508.311259168441\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"532.942505000968\" y=\"-419.609370630875\">{0 5}\\\\( - , 0 1 , 0 1 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"96.2020875008066\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"119.137575014519\" y=\"-419.609370630875\">{1 2}\\\\( 0 1 2 , - , 0 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"37.0870975027425\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"60.0225850164548\" y=\"-419.609370630875\">{2 4}\\\\( 0 1 2 , 0 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"273.547057494999\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"296.482545008711\" y=\"-419.609370630875\">{3 4}\\\\( 2 , 0 1 2 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"450.892027489191\" y=\"-423.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"473.827515002904\" y=\"-419.609370630875\">{3 5}\\\\( - , 0 1 2 , 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"216.543317139723\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"239.478804653435\" y=\"-596.609370630875\">{0 1 2}\\\\( 1 2 , - , 0 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"140.538329999355\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"163.473817513067\" y=\"-596.609370630875\">{0 2 4}\\\\( 1 2 , 0 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"275.658307137787\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"298.593794651499\" y=\"-596.609370630875\">{0 3 4}\\\\( 2 , 0 1 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"45.8709750274247\" x=\"410.444929069463\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"433.380416583176\" y=\"-596.609370630875\">{0 3 5}\\\\( - , 0 1 , 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"467.864160748713\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"492.49540658124\" y=\"-596.609370630875\">{0 1 5}\\\\( - , - , 0 1 2 )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"75.8384376036561\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"100.469683436183\" y=\"-596.609370630875\">{1 2 4}\\\\( 0 1 2 , - , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"49.2624916650535\" x=\"349.634180752585\" y=\"-600.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"374.265426585112\" y=\"-596.609370630875\">{3 4 5}\\\\( - , 0 1 2 , - )</text>\n",
       "\t<rect height=\"4.80939859327612\" rx=\"0\" ry=\"0\" style=\"fill: rgb(0,0,0); stroke: rgb(0,0,0); stroke-width: 0.356251747650083\" width=\"5.1727753758792\" x=\"293.896157320772\" y=\"-777.350013981201\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"3.56251747650083\" text-anchor=\"middle\" x=\"296.482545008711\" y=\"-773.609370630875\"></text>\n",
       "\t<!--\n",
       "\tGenerated using the Perl SVG Module V2.84\n",
       "\tby Ronan Oger\n",
       "\tInfo: http://www.roitsystems.com/\n",
       "\t-->\n",
       "</svg>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n",
       "<svg height=\"841pt\" id=\"document\" viewBox=\"0 -824 570 824\" width=\"595pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "\t<title id=\"document_title\">unnamed</title>\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"297.5\" x2=\"297.5\" y1=\"-66.5\" y2=\"-302.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"297.5\" x2=\"482.665234967155\" y1=\"-66.5\" y2=\"-302.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"297.5\" x2=\"112.334765032845\" y1=\"-66.5\" y2=\"-302.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"297.5\" x2=\"377.813000794052\" y1=\"-302.5\" y2=\"-538.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"297.5\" x2=\"218.143470728362\" y1=\"-302.5\" y2=\"-538.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"482.665234967155\" x2=\"377.813000794052\" y1=\"-302.5\" y2=\"-538.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"112.334765032845\" x2=\"218.143470728362\" y1=\"-302.5\" y2=\"-538.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"377.813000794052\" x2=\"297.5\" y1=\"-538.5\" y2=\"-774.5\" />\n",
       "\t<line stroke=\"rgb(0,0,0)\" stroke-width=\"1\" x1=\"218.143470728362\" x2=\"297.5\" y1=\"-538.5\" y2=\"-774.5\" />\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"14.52\" x=\"290.24\" y=\"-74.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"297.5\" y=\"-64\"></text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"138.28\" x=\"228.36\" y=\"-310.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"297.5\" y=\"-300\">{0}\\\\( 1 2 , 0 1 , 0 1 2 )</text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"119.24\" x=\"423.045234967155\" y=\"-310.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"482.665234967155\" y=\"-300\">{2}\\\\( 0 1 2 , 0 , 0 )</text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"119.24\" x=\"52.7147650328448\" y=\"-310.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"112.334765032845\" y=\"-300\">{3}\\\\( 2 , 0 1 2 , 2 )</text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"119.24\" x=\"318.193000794052\" y=\"-546.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"377.813000794052\" y=\"-536\">{0 2}\\\\( 1 2 , 0 , 0 )</text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(255,255,255); stroke: rgb(0,0,0); stroke-width: 1\" width=\"119.24\" x=\"158.523470728362\" y=\"-546.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"218.143470728362\" y=\"-536\">{0 3}\\\\( 2 , 0 1 , 2 )</text>\n",
       "\t<rect height=\"13.5\" rx=\"0\" ry=\"0\" style=\"fill: rgb(0,0,0); stroke: rgb(0,0,0); stroke-width: 1\" width=\"14.52\" x=\"290.24\" y=\"-782.5\" />\n",
       "\t<text font-family=\"Times-Roman\" font-size=\"10\" text-anchor=\"middle\" x=\"297.5\" y=\"-772\"></text>\n",
       "\t<!--\n",
       "\tGenerated using the Perl SVG Module V2.84\n",
       "\tby Ronan Oger\n",
       "\tInfo: http://www.roitsystems.com/\n",
       "\t-->\n",
       "</svg>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "svg($c->TORUS_COVECTOR_DECOMPOSITION->VISUAL);\n",
    "svg($c->POLYTOPE_COVECTOR_DECOMPOSITION->VISUAL);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Each node in the lattice is a cell of the subdivision. The top row describes the vertices and rays of the subdivision. The bottom row is the covector of that cell with respect to the `POINTS`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tropical cycles"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The main object here is `Cycle`, which represents a weighted and balanced, rational pure polyhedral complex in the tropical projective torus (see this [section](#Homogeneous-and-extended-coordinates) above, if you're confused by coordinates in the following examples).\n",
    "\n",
    "A tropical cycle can be created, like a `PolyhedralComplex`, by specifying its vertices and maximal cells (and possibly a lineality space). The only additional data are the weights on the maximal cells."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "$x = new Cycle<Max>(PROJECTIVE_VERTICES=>[[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,-1]],MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "This creates the standard tropical (max-)line in the plane. There are two caveats to observe here:\n",
    " 1.  The use of `POINTS` and `INPUT_POLYTOPES` is strongly discouraged. `WEIGHTS` always refer to `MAXIMAL_POLYTOPES` and the order of the latter can be different from the order in `INPUT_POLYTOPES`.\n",
    " 2.  You can also define a cycle using `VERTICES` instead of `PROJECTIVE_VERTICES`. However, in that case all vertices have to be normalized such that the second coordinate (i.e. the one after the leading 0/1) is 0. I.e. in the above example, the point (0,-1,0,0) would have to be replaced by (0,0,1,1).\n",
    "\n",
    "Entering projective coordinates can be a little tedious, since it usually just means adding a zero in front of your affine coordinates. There is a convenience function that does this for you. The following creates the excact same cycle as above:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "$x = new Cycle<Max>(VERTICES=>thomog([[1,0,0],[0,1,1],[0,-1,0],[0,0,-1]]),MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "One can now ask for basic properties of the cycle, e.g., if it's balanced:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print is_balanced($x);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Hypersurfaces\n",
    "\n",
    "Most of the time you probably won't want to input your tropical cycle directly as above. Polymake has a special data type `Hypersurface` for hypersurfaces of *homogeneous* tropical polynomials. The following creates the standard tropical min-line in the plane:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 0 0 0\n",
       "0 0 -1 -1\n",
       "0 0 1 0\n",
       "0 0 0 1\n"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$H = new Hypersurface<Min>(POLYNOMIAL=>toTropicalPolynomial(\"min(a,b,c)\"));\n",
    "print $H->VERTICES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0 1}\n",
       "{0 2}\n",
       "{0 3}\n"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $H->MAXIMAL_POLYTOPES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 1 1"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $H->WEIGHTS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tropical intersection theory\n",
    "\n",
    "Functionality related to tropical intersection theory is provided by the bundled extension atint by Simon Hampe, see [here](https://github.com/simonhampe/atint/wiki/User-Manual) for a more extensive, but also slightly outdated documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Basic examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Computing the divisor of a tropical polynomial in $ \\mathbb R^n$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n",
       "<svg height=\"841pt\" id=\"document\" viewBox=\"0 -614.4 568.4 614.4\" width=\"595pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "\t<title id=\"document_title\">unnamed</title>\n",
       "\t<polygon points=\"297.5,-317.5 297.5,-317.5 297.5,-51.7 297.5,-51.7 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<polygon points=\"297.5,-317.5 297.5,-317.5 31.7,-317.5 31.7,-317.5 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<polygon points=\"297.5,-51.7 297.5,-317.5 31.7,-317.5 31.7,-51.7 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<polygon points=\"297.5,-317.5 297.5,-317.5 563.3,-583.3 563.3,-583.3 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"563.3\" cy=\"-583.3\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"563.3\" cy=\"-583.3\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<polygon points=\"297.5,-51.7 297.5,-317.5 563.3,-583.3 563.3,-51.7 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"563.3\" cy=\"-583.3\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"563.3\" cy=\"-51.7\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<polygon points=\"297.5,-317.5 563.3,-583.3 31.7,-583.3 31.7,-317.5 \" style=\"fill: rgb(119,236,158); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t<circle cx=\"563.3\" cy=\"-583.3\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-317.5\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<circle cx=\"31.7\" cy=\"-583.3\" r=\"0.2\" style=\"fill: rgb(255,0,0)\" />\n",
       "\t<!--\n",
       "\tGenerated using the Perl SVG Module V2.84\n",
       "\tby Ronan Oger\n",
       "\tInfo: http://www.roitsystems.com/\n",
       "\t-->\n",
       "</svg>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<details><summary><pre style=\"display:inline\"><small>Click here for additional output</small></pre></summary>\n",
       "<pre>\n",
       "polymake: used package atint\n",
       "  [[wiki:external_software#a-tint]] is an extension for tropical intersection theory.\n",
       "  (C) 2011 - 2015 Simon Hampe, simon.hampe@googlemail.com\n",
       "  See also: https://github.com/simonhampe/atint \n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "$f = toTropicalPolynomial(\"max(0,x,y,z)\");\n",
    "$div = divisor(projective_torus<Max>(3), rational_fct_from_affine_numerator($f));\n",
    "svg($div->VISUAL);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, `projective_torus` creates the tropical projective 3-torus (aka $ \\mathbb R^3$) as a tropical fan with weight 1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Visualizing a curve in a tropical surface\n",
    "\n",
    "Let's create the standard tropical hyperplane in 3-space:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "$l = uniform_linear_space<Min>(3,2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Furthermore, we compute a curve as the divisor of a rational function on `$l`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "$div = divisor($l, rational_fct_from_affine_numerator(toTropicalPolynomial(\"min(3x+4,x-y-z,y+z+3)\")));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now want to visualize these together and since we want to put the resulting picture in a slide show, we want the picture to look a bit nicer, e.g. we want to intersect both the surface and the curve with the same bounding box (we don't want the curve to continue \"beyond the surface\")."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 0 0 0\n",
       "1 0 0 0\n"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $l->bounding_box();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 -1 -1 -1\n",
       "1 3 0 0\n"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $div->bounding_box();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The method bounding_box returns 2 opposing vertices of the smallest acceptable bounding box for the hyperplane's, respectively the curve's affine chart. Obviously the curve's box contains the one of the hyperplane, thus we may use it for both objects. The `BoundingFacets` option, however, expects a H-description. Along with additional options we may obtain it like that: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "$bbfacets = polytope::bounding_box_facets($div->bounding_box(), offset=>1, surplus_k=>0.1, fulldim=>0);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For zero or undefined offset it is advisable to set `fulldim=>1`. Visualizing several objects at the same time can be done with `compose`.  Here we use `threejs` instead of `svg`; hence it might look less impressive in the static web version; try it yourself!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!--\n",
       "polymake for knusper\n",
       "Thu Aug 27 10:41:16 2020\n",
       "l\n",
       "-->\n",
       "\n",
       "\n",
       "<html>\n",
       "   <head>\n",
       "      <meta charset=utf-8>\n",
       "      <title>l</title>\n",
       "      <style>\n",
       "/*\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "*/\n",
       "         html {overflow: scroll;}\n",
       "         strong{font-size: 18px;}\n",
       "         canvas { z-index: 8; }\n",
       "         input[type='radio'] {margin-left:0;}\n",
       "         input[type='checkbox'] {margin-right:7px; margin-left: 0px; padding-left:0px;}\n",
       "         .group{padding-bottom: 15px;}\n",
       "         .settings * {z-index: 11; }\n",
       "         .settings{z-index: 10; font-family: Arial, Helvetica, sans-serif; margin-left: 30px; visibility: hidden; width: 14em; height: 96%; border: solid 1px silver; padding: 2px; overflow-y: scroll; box-sizing: border-box; background-color: white; position: absolute;}\n",
       "         .indented{margin-left: 20px; margin-top: 10px; padding-bottom: 0px;} \n",
       "         .shownObjectsList{overflow: auto; max-width: 150px; max-height: 150px;}\n",
       "         .showSettingsButton{visibility: visible; z-index: 12; position: absolute }\n",
       "         .hideSettingsButton{visibility: hidden; z-index: 12; position: absolute; opacity: 0.5}\n",
       "         button{margin-left: 0; margin-top: 10px}\n",
       "         img{cursor: pointer;}\n",
       "         .suboption{padding-top: 15px;}\n",
       "         #model86725736044 { width: 100%; height: 100%; }\n",
       "         .threejs_container { width: 100%; height: 75vh;}\n",
       "         .settings{max-height: 74vh} \n",
       "         input[type=range] {\n",
       "           -webkit-appearance: none;\n",
       "           padding:0; \n",
       "           width:90%; \n",
       "           margin-left: auto;\n",
       "           margin-right: auto;\n",
       "           margin-top: 15px;\n",
       "           margin-bottom: 15px;\n",
       "           display: block;\t\n",
       "         }\n",
       "         input[type=range]:focus {\n",
       "           outline: none;\n",
       "         }\n",
       "         input[type=range]::-webkit-slider-runnable-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "           background: #E3E3E3;\n",
       "           border-radius: 0px;\n",
       "           border: 0px solid #000000;\n",
       "         }\n",
       "         input[type=range]::-webkit-slider-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "           -webkit-appearance: none;\n",
       "           margin-top: -5px;\n",
       "         }\n",
       "         input[type=range]:focus::-webkit-slider-runnable-track {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "         input[type=range]::-moz-range-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "           background: #E3E3E3;\n",
       "           border-radius: 0px;\n",
       "           border: 0px solid #000000;\n",
       "         }\n",
       "         input[type=range]::-moz-range-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "         }\n",
       "         input[type=range]::-ms-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           background: transparent;\n",
       "           border-color: transparent;\n",
       "           color: transparent;\n",
       "         }\n",
       "         input[type=range]::-ms-fill-lower {\n",
       "           background: #E3E3E3;\n",
       "           border: 0px solid #000000;\n",
       "           border-radius: 0px;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "         }\n",
       "         input[type=range]::-ms-fill-upper {\n",
       "           background: #E3E3E3;\n",
       "           border: 0px solid #000000;\n",
       "           border-radius: 0px;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "         }\n",
       "         input[type=range]::-ms-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "         }\n",
       "         input[type=range]:focus::-ms-fill-lower {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "         input[type=range]:focus::-ms-fill-upper {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "/*\n",
       "// COMMON_CODE_BLOCK_END\n",
       "*/\n",
       "\t\t</style>\n",
       "   </head>\n",
       "<body>\n",
       "   <div class='threejs_container'>\n",
       "\t\t<div id='settings_0' class='settings'>\n",
       "\t\t\t<div class=group id='explode_0'>\n",
       "\t\t\t\t<strong>Explode</strong>\n",
       "\t\t\t\t<input id='explodeRange_0' type='range' min=0 max=6 step=0.01 value=0>\n",
       "\t\t\t\t<div class=indented><input id='explodeCheckbox_0' type='checkbox'>Automatic explosion</div>\n",
       "\t\t\t\t<div class=suboption>Exploding speed</div>\n",
       "\t\t\t\t<input id='explodingSpeedRange_0' type='range' min=0 max=0.5 step=0.001 value=0.05>\n",
       "\t\t\t</div>\n",
       "\t\n",
       "\t\t\t<div class=group id='transparency_0' class='transparency'>\n",
       "\t\t\t\t<strong>Transparency</strong>\n",
       "\t\t\t\t<input id='transparencyRange_0' type='range' min=0 max=1 step=0.01 value=0>\n",
       "\t\t\t</div>\n",
       "\t\t\t\n",
       "\t\t\t<div class=group id='rotation_0'>\n",
       "\t\t\t\t<strong>Rotation</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationX_0'> x-axis</div>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationY_0'> y-axis</div>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationZ_0'> z-axis</div>\n",
       "\t\t\t\t\t<button id='resetButton_0'>Reset</button>\n",
       "\t\t\t\t</div>\n",
       "\n",
       "\t\t\t\t<div class=suboption>Rotation speed</div>\n",
       "\t\t\t\t<input id='rotationSpeedRange_0' type='range' min=0 max=5 step=0.01 value=2>\n",
       "\t\t\t</div>\n",
       "\n",
       "\n",
       "\t\t\t<div class=group id='display_0'>\n",
       "\t\t\t\t<strong>Display</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<div id='shownObjectTypesList_0' class='shownObjectsList'></div>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t\t<div class=suboption>Objects</div>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t   <div id='shownObjectsList_0' class='shownObjectsList'></div>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t</div>\n",
       "         \n",
       "         <div class=group id='camera_0'>\n",
       "            <strong>Camera</strong>\n",
       "            <div class=indented>\n",
       "               <form>\n",
       "                  <select id=\"cameraType_0\">\n",
       "                     <option value='perspective' selected> Perspective<br></option>\n",
       "                     <option value='orthographic' > Orthographic<br></option>\n",
       "                  </select>\n",
       "               </form>\n",
       "            </div>\n",
       "         </div>\n",
       "\n",
       "\t\t\t<div class=group id='svg_0'>\n",
       "\t\t\t\t<strong>SVG</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<form>\n",
       "\t\t\t\t\t\t<input type=\"radio\" name='screenshotMode' value='download' id='download_0' checked> Download<br>\n",
       "\t\t\t\t\t\t<input type=\"radio\" name='screenshotMode' value='tab' id='tab_0' > New tab<br>\n",
       "\t\t\t\t\t</form>\n",
       "\t\t\t\t\t<button id='takeScreenshot_0'>Screenshot</button>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t</div>\n",
       "\n",
       "\t\t</div>\t<!-- end of settings -->\n",
       "\t\t<img id='hideSettingsButton_0' class='hideSettingsButton' src='/kernelspecs/polymake/close.svg' width=20px\">\n",
       "\t\t<img id='showSettingsButton_0' class='showSettingsButton' src='/kernelspecs/polymake/menu.svg' width=20px\">\n",
       "<div id=\"model86725736044\"></div>\n",
       "</div>\n",
       "   <script>\n",
       "    requirejs.config({\n",
       "      paths: {\n",
       "        three: '/kernelspecs/polymake/three',\n",
       "        TrackballControls: '/kernelspecs/polymake/TrackballControls',\n",
       "        OrbitControls: '/kernelspecs/polymake/OrbitControls',\n",
       "        Projector: '/kernelspecs/polymake/Projector',\n",
       "        SVGRenderer: '/kernelspecs/polymake/SVGRenderer',\n",
       "        WEBGL: '/kernelspecs/polymake/WebGL',\n",
       "      },\n",
       "      shim: {\n",
       "        'three': { exports: 'THREE'},\n",
       "        'SVGRenderer': { deps: [ 'three' ], exports: 'THREE.SVGRenderer' },\n",
       "        'WEBGL': { deps: [ 'three' ], exports: 'THREE.WEBGL' },\n",
       "        'Projector': { deps: [ 'three' ], exports: 'THREE.Projector' },\n",
       "        'TrackballControls': { deps: [ 'three' ], exports: 'THREE.TrackballControls' },\n",
       "        'OrbitControls': { deps: [ 'three' ], exports: 'THREE.OrbitControls' },\n",
       "      }\n",
       "    });\n",
       "    \n",
       "    require(['three'],function(THREE){\n",
       "        window.THREE = THREE;\n",
       "      require(['TrackballControls', 'OrbitControls', 'Projector', 'SVGRenderer', 'WEBGL'],\n",
       "               function(TrackballControls, OrbitControls, Projector, SVGRenderer, WEBGL) {\n",
       "    THREE.TrackballControls = TrackballControls;\n",
       "    THREE.OrbitControls = OrbitControls;\n",
       "    THREE.Projector = Projector;\n",
       "    THREE.SVGRenderer = SVGRenderer;\n",
       "    THREE.WEBGL = WEBGL;\n",
       "\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "\n",
       "const intervalLength = 25; // for automatic animations\n",
       "const explodableModel = true; \n",
       "const modelContains = { points: false, pointlabels: false, lines: false, edgelabels: false, faces: false, arrowheads: false };\n",
       "const foldables = [];\n",
       "\n",
       "var three = document.getElementById(\"model86725736044\");\n",
       "var scene = new THREE.Scene();\n",
       "var renderer = new THREE.WebGLRenderer( { antialias: true } );\n",
       "var svgRenderer = new THREE.SVGRenderer( { antialias: true } );\n",
       "renderer.setPixelRatio( window.devicePixelRatio );\n",
       "renderer.setClearColor(0xFFFFFF, 1);\n",
       "svgRenderer.setClearColor(0xFFFFFF, 1);\n",
       "three.appendChild(renderer.domElement);\n",
       "\n",
       "var frustumSize = 4;\n",
       "var cameras = [new THREE.PerspectiveCamera(75, 1, 0.1, 1000), new THREE.OrthographicCamera()];\n",
       "cameras.forEach(function(cam) {\n",
       "    cam.position.set(0, 0, 5);\n",
       "    cam.lookAt(0, 0, 0);  \n",
       "    cam.up.set(0, 1, 0);         \n",
       "});\n",
       "var controls = [new THREE.TrackballControls(cameras[0], three), new THREE.OrbitControls(cameras[1], three)];\n",
       "var camera, control;\n",
       "\n",
       "controls[0].zoomSpeed = 0.2;\n",
       "controls[0].rotateSpeed = 4;\n",
       "\n",
       "\n",
       "// class to allow move points together with labels and spheres\n",
       "var PMPoint = function (x,y,z) {\n",
       "   this.vector = new THREE.Vector3(x,y,z);\n",
       "   this.sprite = null;\n",
       "   this.sphere = null;\n",
       "}\n",
       "PMPoint.prototype.addLabel = function(labelsprite) {\n",
       "   this.sprite = labelsprite;\n",
       "   this.sprite.position.copy(this.vector);\n",
       "}\n",
       "PMPoint.prototype.addSphere = function(spheremesh) {\n",
       "   this.sphere = spheremesh;\n",
       "   this.sphere.position.copy(this.vector);\n",
       "}\n",
       "PMPoint.prototype.set = function(x,y,z) {\n",
       "   this.vector.set(x,y,z);\n",
       "   if (this.sprite) {\n",
       "      this.sprite.position.copy(this.vector);\n",
       "   }\n",
       "   if (this.sphere) {\n",
       "      this.sphere.position.copy(this.vector);\n",
       "   }\n",
       "}\n",
       "PMPoint.prototype.radius = function() {\n",
       "   if (this.sphere) {\n",
       "      return this.sphere.geometry.parameters.radius;\n",
       "   } else {\n",
       "      return 0;\n",
       "   }\n",
       "};\n",
       "// select the target node\n",
       "var target = document.querySelector('#model86725736044');\n",
       "\n",
       "// create an observer instance\n",
       "var observer = new MutationObserver(function(mutations) {\n",
       "   mutations.forEach(function(mutation) {\n",
       "      if (mutation.removedNodes && mutation.removedNodes.length > 0) {\n",
       "         cancelAnimationFrame(renderId);\n",
       "         observer.disconnect();\n",
       "         console.log(\"cancelled frame \"+renderId);\n",
       "      }\n",
       "   });\n",
       "});\n",
       "\n",
       "// configuration of the observer:\n",
       "var config = { childList: true, characterData: true }\n",
       "\n",
       "// pass in the target node, as well as the observer options\n",
       "while (target) {\n",
       "   if (target.className==\"output\") {\n",
       "      observer.observe(target, config);\n",
       "      break;\n",
       "   }\n",
       "   target = target.parentNode;\n",
       "}\n",
       "\n",
       "// COMMON_CODE_BLOCK_END\n",
       "\n",
       "var obj0 = new THREE.Object3D();\n",
       "obj0.name = \"unnamed__1\";\n",
       "obj0.userData.explodable = 1;\n",
       "obj0.userData.points = [];\n",
       "obj0.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj0.userData.points.push(new PMPoint(-2.1, -2.1, -2.1));\n",
       "obj0.userData.points.push(new PMPoint(4.4, 0, 0));\n",
       "obj0.userData.points.push(new PMPoint(4.4, -2.1, -2.1));\n",
       "\n",
       "obj0.userData.edgeindices = [0, 1, 0, 2, 1, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj0.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj0.userData.facets = [[0, 2, 3, 1]];\n",
       "   <!-- Facet style -->\n",
       "obj0.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj0);\n",
       "scene.add(obj0);\n",
       "\n",
       "var obj1 = new THREE.Object3D();\n",
       "obj1.name = \"unnamed__2\";\n",
       "obj1.userData.explodable = 1;\n",
       "obj1.userData.points = [];\n",
       "obj1.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj1.userData.points.push(new PMPoint(0, 1.1, 0));\n",
       "obj1.userData.points.push(new PMPoint(-2.1, -2.1, -2.1));\n",
       "obj1.userData.points.push(new PMPoint(-2.1, 1.1, -2.1));\n",
       "\n",
       "obj1.userData.edgeindices = [0, 1, 0, 2, 1, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj1.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj1.userData.facets = [[0, 1, 3, 2]];\n",
       "   <!-- Facet style -->\n",
       "obj1.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj1);\n",
       "scene.add(obj1);\n",
       "\n",
       "var obj2 = new THREE.Object3D();\n",
       "obj2.name = \"unnamed__3\";\n",
       "obj2.userData.explodable = 1;\n",
       "obj2.userData.points = [];\n",
       "obj2.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj2.userData.points.push(new PMPoint(0, 0, 1.1));\n",
       "obj2.userData.points.push(new PMPoint(-2.1, -2.1, 1.1));\n",
       "obj2.userData.points.push(new PMPoint(-2.1, -2.1, -2.1));\n",
       "\n",
       "obj2.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj2.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj2.userData.facets = [[0, 1, 2, 3]];\n",
       "   <!-- Facet style -->\n",
       "obj2.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj2);\n",
       "scene.add(obj2);\n",
       "\n",
       "var obj3 = new THREE.Object3D();\n",
       "obj3.name = \"unnamed__4\";\n",
       "obj3.userData.explodable = 1;\n",
       "obj3.userData.points = [];\n",
       "obj3.userData.points.push(new PMPoint(0, 1.1, 0));\n",
       "obj3.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj3.userData.points.push(new PMPoint(4.4, 0, 0));\n",
       "obj3.userData.points.push(new PMPoint(4.4, 1.1, 0));\n",
       "\n",
       "obj3.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj3.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj3.userData.facets = [[1, 0, 3, 2]];\n",
       "   <!-- Facet style -->\n",
       "obj3.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj3);\n",
       "scene.add(obj3);\n",
       "\n",
       "var obj4 = new THREE.Object3D();\n",
       "obj4.name = \"unnamed__5\";\n",
       "obj4.userData.explodable = 1;\n",
       "obj4.userData.points = [];\n",
       "obj4.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj4.userData.points.push(new PMPoint(0, 0, 1.1));\n",
       "obj4.userData.points.push(new PMPoint(4.4, 0, 0));\n",
       "obj4.userData.points.push(new PMPoint(4.4, 0, 1.1));\n",
       "\n",
       "obj4.userData.edgeindices = [0, 1, 0, 2, 1, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj4.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj4.userData.facets = [[0, 1, 3, 2]];\n",
       "   <!-- Facet style -->\n",
       "obj4.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj4);\n",
       "scene.add(obj4);\n",
       "\n",
       "var obj5 = new THREE.Object3D();\n",
       "obj5.name = \"unnamed__6\";\n",
       "obj5.userData.explodable = 1;\n",
       "obj5.userData.points = [];\n",
       "obj5.userData.points.push(new PMPoint(0, 1.1, 0));\n",
       "obj5.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj5.userData.points.push(new PMPoint(0, 0, 1.1));\n",
       "obj5.userData.points.push(new PMPoint(0, 1.1, 1.1));\n",
       "\n",
       "obj5.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj5.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj5.userData.facets = [[0, 3, 2, 1]];\n",
       "   <!-- Facet style -->\n",
       "obj5.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj5);\n",
       "scene.add(obj5);\n",
       "\n",
       "var obj6 = new THREE.Object3D();\n",
       "obj6.name = \"unnamed__7\";\n",
       "obj6.userData.explodable = 1;\n",
       "obj6.userData.points = [];\n",
       "obj6.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj6.userData.points.push(new PMPoint(-1.73333, -2.1, -2.1));\n",
       "\n",
       "obj6.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj6.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj6);\n",
       "scene.add(obj6);\n",
       "\n",
       "var obj7 = new THREE.Object3D();\n",
       "obj7.name = \"unnamed__8\";\n",
       "obj7.userData.explodable = 1;\n",
       "obj7.userData.points = [];\n",
       "obj7.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj7.userData.points.push(new PMPoint(3, 0, 0));\n",
       "\n",
       "obj7.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj7.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj7);\n",
       "scene.add(obj7);\n",
       "\n",
       "var obj8 = new THREE.Object3D();\n",
       "obj8.name = \"unnamed__9\";\n",
       "obj8.userData.explodable = 1;\n",
       "obj8.userData.points = [];\n",
       "obj8.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj8.userData.points.push(new PMPoint(-1.7, 1.1, -1.7));\n",
       "\n",
       "obj8.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj8.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj8);\n",
       "scene.add(obj8);\n",
       "\n",
       "var obj9 = new THREE.Object3D();\n",
       "obj9.name = \"unnamed__10\";\n",
       "obj9.userData.explodable = 1;\n",
       "obj9.userData.points = [];\n",
       "obj9.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj9.userData.points.push(new PMPoint(-1.7, -1.7, 1.1));\n",
       "\n",
       "obj9.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj9.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj9);\n",
       "scene.add(obj9);\n",
       "\n",
       "var obj10 = new THREE.Object3D();\n",
       "obj10.name = \"unnamed__11\";\n",
       "obj10.userData.explodable = 1;\n",
       "obj10.userData.points = [];\n",
       "obj10.userData.points.push(new PMPoint(3, 0, 0));\n",
       "obj10.userData.points.push(new PMPoint(4.4, 0.7, 0));\n",
       "\n",
       "obj10.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj10.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj10);\n",
       "scene.add(obj10);\n",
       "\n",
       "var obj11 = new THREE.Object3D();\n",
       "obj11.name = \"unnamed__12\";\n",
       "obj11.userData.explodable = 1;\n",
       "obj11.userData.points = [];\n",
       "obj11.userData.points.push(new PMPoint(3, 0, 0));\n",
       "obj11.userData.points.push(new PMPoint(4.4, 0, 0.7));\n",
       "\n",
       "obj11.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj11.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj11);\n",
       "scene.add(obj11);\n",
       "\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "function textSpriteMaterial(message, parameters) {\n",
       "    if ( parameters === undefined ) parameters = {};\n",
       "    var fontface = \"Helvetica\";\n",
       "    var fontsize = parameters.hasOwnProperty(\"fontsize\") ? parameters[\"fontsize\"] : 15;\n",
       "    fontsize = fontsize*10;\n",
       "    var lines = message.split('\\\\n');\n",
       "    var size = 512;\n",
       "    for(var i = 0; i<lines.length; i++){\n",
       "        var tmp = lines[i].length;\n",
       "        while(tmp*fontsize > size){\n",
       "           fontsize--;\n",
       "        }\n",
       "    }\n",
       "    \n",
       "    var canvas = document.createElement('canvas');\n",
       "    canvas.width = size;\n",
       "    canvas.height = size;\n",
       "    var context = canvas.getContext('2d');\n",
       "    context.fillStyle = \"rgba(255, 255, 255, 0)\";\n",
       "    context.fill();\n",
       "    context.font = fontsize + \"px \" + fontface;\n",
       "    \n",
       "    // text color\n",
       "    context.fillStyle = \"rgba(0, 0, 0, 1.0)\";\n",
       "     for(var i = 0; i<lines.length; i++){\n",
       "        context.fillText(lines[i], size/2, size/2+i*fontsize);\n",
       "     }\n",
       "    \n",
       "    // canvas contents will be used for a texture\n",
       "    var texture = new THREE.Texture(canvas);\n",
       "    texture.needsUpdate = true;\n",
       "    \n",
       "    var spriteMaterial = new THREE.SpriteMaterial({map: texture, depthTest: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: 1 });\n",
       "    return spriteMaterial;\n",
       "}\n",
       "\n",
       "\n",
       "// ---------------------- INITIALIZING OBJECTS--------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "function init_object(obj) {\n",
       "    if (obj.userData.hasOwnProperty(\"pointmaterial\")) {\n",
       "        init_points(obj);\n",
       "        modelContains.points = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"pointlabels\")) {\n",
       "        init_pointlabels(obj);\n",
       "        modelContains.pointlabels = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"edgematerial\")) {\n",
       "        init_lines(obj);\n",
       "        modelContains.lines = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"edgelabels\")) {\n",
       "        init_edgelabels(obj);\n",
       "        modelContains.edgelabels = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"arrowstyle\")) {\n",
       "        init_arrowheads(obj);\n",
       "        modelContains.arrowheads = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"facetmaterial\")) {\n",
       "        init_faces(obj);\n",
       "        modelContains.faces = true;\n",
       "    }\n",
       "}\n",
       "\n",
       "function init_points(obj) {\n",
       "    var pointgroup = new THREE.Group();\n",
       "    pointgroup.name = \"points\";\n",
       "    var points = obj.userData.points;\n",
       "    var radii = obj.userData.pointradii;\n",
       "    var materials = obj.userData.pointmaterial;\n",
       "    var geometry,material;\n",
       "    if (!Array.isArray(radii)) {\n",
       "        geometry = new THREE.SphereBufferGeometry(radii);  \n",
       "    }\n",
       "    if (!Array.isArray(materials)) {\n",
       "        material = materials;\n",
       "    }\n",
       "    for (var i=0; i<points.length; i++) {\n",
       "        var point = points[i];\n",
       "        if (Array.isArray(radii)) {\n",
       "            if (radii[i] == 0) {\n",
       "                continue;\n",
       "            }\n",
       "            geometry = new THREE.SphereBufferGeometry(radii[i]);  \n",
       "        } \n",
       "        if (Array.isArray(materials)) {\n",
       "            material = materials[i];     \n",
       "        } \n",
       "        var sphere = new THREE.Mesh(geometry, material);\n",
       "        point.addSphere(sphere);\n",
       "        pointgroup.add(sphere);\n",
       "    }\n",
       "    obj.add(pointgroup);\n",
       "}\n",
       "\n",
       "function init_pointlabels(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var labels = obj.userData.pointlabels;\n",
       "    var pointlabels = new THREE.Group();\n",
       "    pointlabels.name = \"pointlabels\";\n",
       "    if (Array.isArray(labels)) {\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "            var spriteMaterial = textSpriteMaterial( labels[i] );\n",
       "\t        var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            point.addLabel(sprite);\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    } else {\n",
       "        var spriteMaterial = textSpriteMaterial( labels );\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "\t        var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            point.addLabel(sprite);\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    }\n",
       "    obj.add(pointlabels);\n",
       "}\n",
       "\n",
       "function init_lines(obj) {\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var points = obj.userData.points;\n",
       "    var materials = obj.userData.edgematerial;\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    var bufarr = new Float32Array( obj.userData.edgeindices.length * 3 );\n",
       "    var bufattr = new THREE.Float32BufferAttribute( bufarr, 3 );\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    geometry.setAttribute('position', bufattr);\n",
       "    if (Array.isArray(materials)) {     \n",
       "        for (var i=0; i<materials.length; i++) {\n",
       "            geometry.addGroup(2*i,2,i);\n",
       "        }\n",
       "    }\n",
       "    var lines = new THREE.LineSegments(geometry, materials);\n",
       "    lines.name = \"lines\";\n",
       "    obj.add(lines);\n",
       "    updateEdgesPosition(obj);\n",
       "}\n",
       "\n",
       "function init_edgelabels(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var labels = obj.userData.edgelabels;\n",
       "    var edgelabels = new THREE.Group();\n",
       "    edgelabels.name = \"edgelabels\";\n",
       "    if (Array.isArray(labels)) {\n",
       "        for (var i=0; i<edgeindices.length; i=i+2) {\n",
       "            var point = points[i];\n",
       "            var spriteMaterial = textSpriteMaterial( labels[i] );\n",
       "            var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            sprite.position.copy(new THREE.Vector3().addVectors(points[edgeindices[i]].vector,points[edgeindices[i+1]].vector).multiplyScalar(0.5));\n",
       "            edgelabels.add(sprite);\n",
       "        }\n",
       "    } else {\n",
       "        var spriteMaterial = textSpriteMaterial( labels );\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "            var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            sprite.position.copy(new THREE.Vector3().addVectors(points[edgeindices[i]].vector,points[edgeindices[i+1]].vector).multiplyScalar(0.5));\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    }\n",
       "    obj.add(edgelabels);\n",
       "}\n",
       "\n",
       "function init_arrowheads(obj) {\n",
       "    var arrowheads = new THREE.Group();\n",
       "    arrowheads.name = \"arrowheads\";\n",
       "    var arrowstyle = obj.userData.arrowstyle;\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var edgematerials = obj.userData.edgematerial;\n",
       "    var points = obj.userData.points;\n",
       "    var material;\n",
       "    if (!Array.isArray(edgematerials)) {\n",
       "        material = new THREE.MeshBasicMaterial( {color: edgematerials.color} );\n",
       "    }\n",
       "\n",
       "    for (var i=0; i<edgeindices.length; i=i+2) {\n",
       "        var start = points[edgeindices[i]];\n",
       "        var end = points[edgeindices[i+1]];\n",
       "        var dist = start.vector.distanceTo( end.vector ) - start.radius() - end.radius();\n",
       "        if (dist <= 0) {\n",
       "            continue;\n",
       "        }\n",
       "        var dir = new THREE.Vector3().subVectors(end.vector,start.vector);\n",
       "        dir.normalize();\n",
       "        var axis = new THREE.Vector3().set(dir.z,0,-dir.x);\n",
       "        axis.normalize();\n",
       "        var radians = Math.acos( dir.y );\n",
       "        var radius = dist/25;\n",
       "        var height = dist/5;\n",
       "        var geometry = new THREE.ConeBufferGeometry(radius,height);\n",
       "        var position = new THREE.Vector3().addVectors(start.vector,dir.clone().multiplyScalar(start.radius()+dist-height/2));\n",
       "        if (Array.isArray(edgematerials)) {\n",
       "            material = new THREE.MeshBasicMaterial( {color: edgematerials[i].color} );\n",
       "        }\n",
       "        var cone = new THREE.Mesh( geometry, material );\n",
       "        cone.quaternion.setFromAxisAngle(axis,radians);;\n",
       "        cone.position.copy(position);;\n",
       "        arrowheads.add(cone);\n",
       "    }\n",
       "    obj.add(arrowheads);\n",
       "}\n",
       "\n",
       "function init_faces(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var facets = obj.userData.facets;\n",
       "    obj.userData.triangleindices = [];\n",
       "    for (var i=0; i<facets.length; i++) {\n",
       "        facet = facets[i];\n",
       "        for (var t=0; t<facet.length-2; t++) {\n",
       "            obj.userData.triangleindices.push(facet[0],facet[t+1],facet[t+2]);  \n",
       "        }\n",
       "    }\n",
       "    var bufarr = new Float32Array( obj.userData.triangleindices.length * 3 );\n",
       "    var bufattr = new THREE.Float32BufferAttribute(bufarr,3);\n",
       "    \n",
       "    var materials = obj.userData.facetmaterial;\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    geometry.setAttribute('position',bufattr);\n",
       "    if (Array.isArray(materials)) {\n",
       "        var tricount = 0;\n",
       "        var facet;\n",
       "        for (var i=0; i<facets.length; i++) {\n",
       "            facet = facets[i];\n",
       "            geometry.addGroup(tricount,(facet.length-2)*3,i);\n",
       "            tricount += (facet.length-2)*3;\n",
       "        }\n",
       "    }\n",
       "    var mesh = new THREE.Mesh(geometry, materials);\n",
       "    mesh.name = \"faces\";\n",
       "    obj.add(mesh); \n",
       "    updateFacesPosition(obj);\n",
       "}\n",
       "// //INITIALIZING\n",
       "\n",
       "\n",
       "function updateFacesPosition(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var indices = obj.userData.triangleindices;\n",
       "    var faces = obj.getObjectByName(\"faces\");\n",
       "    var ba = faces.geometry.getAttribute(\"position\");\n",
       "    for (var i=0; i<indices.length; i++) {\n",
       "        ba.setXYZ(i, points[indices[i]].vector.x, points[indices[i]].vector.y ,points[indices[i]].vector.z); \n",
       "    }\n",
       "    faces.geometry.attributes.position.needsUpdate = true;\n",
       "    \n",
       "}\n",
       "\n",
       "function updateEdgesPosition(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var indices = obj.userData.edgeindices;\n",
       "    var lines = obj.getObjectByName(\"lines\");\n",
       "    var ba = lines.geometry.getAttribute(\"position\"); \n",
       "    for (var i=0; i<indices.length; i++) {\n",
       "        ba.setXYZ(i, points[indices[i]].vector.x, points[indices[i]].vector.y ,points[indices[i]].vector.z); \n",
       "    }\n",
       "    lines.geometry.attributes.position.needsUpdate = true;\n",
       "}\n",
       "\n",
       "function onWindowResize() {\n",
       "    renderer.setSize( three.clientWidth, three.clientHeight );\n",
       "    svgRenderer.setSize( three.clientWidth, three.clientHeight );\n",
       "    updateCamera();\n",
       "}\n",
       "\n",
       "function updateCamera() {\n",
       "    var width = three.clientWidth;\n",
       "    var height = three.clientHeight;\n",
       "    var aspect = width / height;\n",
       "    if (camera.type == \"OrthographicCamera\") {\n",
       "        camera.left = frustumSize * aspect / - 2;\n",
       "        camera.right = frustumSize * aspect / 2;\n",
       "        camera.top = frustumSize / 2;\n",
       "        camera.bottom = - frustumSize / 2;\n",
       "    } else if (camera.type == \"PerspectiveCamera\") {\n",
       "        camera.aspect = aspect;\n",
       "    }\n",
       "    camera.updateProjectionMatrix();\n",
       "}\n",
       "\n",
       "function changeCamera(event) {\n",
       "    var selindex = event.currentTarget.selectedIndex;\n",
       "    camera = cameras[selindex];\n",
       "    control = controls[selindex];\n",
       "    control.enabled = true; \n",
       "    for (var i=0; i<controls.length; i++) {\n",
       "        if (i!=selindex) {\n",
       "            controls[i].enabled = false;\n",
       "        }\n",
       "    }\n",
       "    updateCamera();\n",
       "}\n",
       "\n",
       "var camtypenode = document.getElementById('cameraType_0');\n",
       "camtypenode.onchange = changeCamera;\n",
       "camtypenode.dispatchEvent(new Event('change'));\n",
       "\n",
       "onWindowResize();\n",
       "window.addEventListener('resize', onWindowResize);\t\n",
       "\n",
       "\n",
       "var xRotationEnabled = false;\n",
       "var yRotationEnabled = false;\n",
       "var zRotationEnabled = false;\n",
       "var rotationSpeedFactor = 1;\n",
       "var settingsShown = false;\n",
       "var labelsShown = true;\n",
       "var intervals = [];\n",
       "var timeouts = [];\n",
       "var explodingSpeed = 0.05;\n",
       "var explodeScale = 0;\n",
       "var XMLS = new XMLSerializer();\n",
       "var svgElement;\n",
       "var renderId;\n",
       "\n",
       "var render = function () {\n",
       "\n",
       "\trenderId = requestAnimationFrame(render);\n",
       "\n",
       "//\tcomment in for automatic explosion\n",
       "//\texplode(updateFactor());\n",
       "\n",
       "    var phi = 0.02 * rotationSpeedFactor;\n",
       "\n",
       "    if (xRotationEnabled) {\n",
       "        scene.rotation.x += phi;\n",
       "    }\n",
       "    if (yRotationEnabled) {\n",
       "        scene.rotation.y += phi;\n",
       "    }\n",
       "    if (zRotationEnabled) {\n",
       "        scene.rotation.z += phi;\n",
       "    }\n",
       "\n",
       "    control.update();\n",
       "    renderer.render(scene, camera);\n",
       "};\n",
       "\n",
       "if ( THREE.WEBGL.isWebGLAvailable() ) {\n",
       "\trender();\n",
       "} else {\n",
       "\tvar warning = WEBGL.getWebGLErrorMessage();\n",
       "\tthree.appendChild( warning );\n",
       "}\n",
       "    \n",
       "function changeTransparency() {\n",
       "    var opacity = 1-Number(event.currentTarget.value);\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        child = scene.children[i];\n",
       "        if ( child.userData.hasOwnProperty(\"facetmaterial\") ) {\n",
       "            if (Array.isArray(child.userData.facetmaterial)) {\n",
       "                for (var j=0; j<child.userData.facetmaterial.length; j++) {\n",
       "                    child.userData.facetmaterial[j].opacity = opacity;\n",
       "                }\n",
       "            } else {\n",
       "                child.userData.facetmaterial.opacity = opacity;\n",
       "            }    \n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function changeRotationX(event){\n",
       "    xRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "function changeRotationY(event){\n",
       "    yRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "function changeRotationZ(event){\n",
       "    zRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "\n",
       "function changeRotationSpeedFactor(event){\n",
       "    rotationSpeedFactor = Number(event.currentTarget.value);\n",
       "}\n",
       "\n",
       "function resetScene(){\n",
       "    scene.rotation.set(0,0,0);\n",
       "    camera.position.set(0,0,5);\n",
       "    camera.up.set(0,1,0);\n",
       "}\n",
       "\n",
       "function showSettings(event){\n",
       "    document.getElementById('settings_0').style.visibility = 'visible';\n",
       "    document.getElementById('showSettingsButton_0').style.visibility = 'hidden';\n",
       "    document.getElementById('hideSettingsButton_0').style.visibility = 'visible';\n",
       "    settingsShown = true;\n",
       "}\n",
       "\n",
       "function hideSettings(event){\n",
       "    document.getElementById('settings_0').style.visibility = 'hidden';\n",
       "    document.getElementById('showSettingsButton_0').style.visibility = 'visible';\n",
       "    document.getElementById('hideSettingsButton_0').style.visibility = 'hidden';\n",
       "    settingsShown = false;\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "var pos = 150* Math.PI;\n",
       "\n",
       "function updateFactor() {\n",
       "    pos++;\n",
       "    return Math.sin(.01*pos)+1;\n",
       "}\n",
       "\n",
       "// ------------------------ FOLDING ------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "// rotate point p around axis defined by points p1 and p2 by given angle\n",
       "function rotate(p, p1, p2, angle ){   \n",
       "    angle = -angle;\n",
       "    var x = p.x, y = p.y, z = p.z, \n",
       "    a = p1.x, b = p1.y, c = p1.z, \n",
       "    u = p2.x-p1.x, v = p2.y-p1.y, w = p2.z-p1.z;\n",
       "    var result = [];\n",
       "    var L = u*u + v*v + w*w;\n",
       "    var sqrt = Math.sqrt;\n",
       "    var cos = Math.cos;\n",
       "    var sin = Math.sin;\n",
       "\n",
       "    result[0] = ((a*(v*v+w*w)-u*(b*v+c*w-u*x-v*y-w*z))*(1-cos(angle))+L*x*cos(angle)+sqrt(L)*(-c*v+b*w-w*y+v*z)*sin(angle))/L;\n",
       "    result[1] = ((b*(u*u+w*w)-v*(a*u+c*w-u*x-v*y-w*z))*(1-cos(angle))+L*y*cos(angle)+sqrt(L)*(c*u-a*w+w*x-u*z)*sin(angle))/L;\n",
       "    result[2] = ((c*(u*u+v*v)-w*(a*u+b*v-u*x-v*y-w*z))*(1-cos(angle))+L*z*cos(angle)+sqrt(L)*(-b*u+a*v-v*x+u*y)*sin(angle))/L;\n",
       "\n",
       "    return result;\n",
       "}\n",
       "\n",
       "var fold = function(event){\n",
       "    var obj = foldables[Number(event.currentTarget.name)];\n",
       "    var foldvalue = Number(event.currentTarget.value);\n",
       "    var scale = foldvalue - obj.userData.oldscale;\n",
       "\n",
       "    for (var j=0; j<obj.userData.axes.length; j++) {\n",
       "        rotateVertices(obj, j, scale);\n",
       "    }\n",
       "    update(obj);\n",
       "    obj.userData.oldscale += scale;\n",
       "    lookAtBarycenter(obj);\n",
       "}\n",
       "\n",
       "function lookAtBarycenter(obj){\n",
       "    control.target = barycenter(obj);\n",
       "}\n",
       "\n",
       "function barycenter(obj) {\n",
       "    var center = new THREE.Vector3(0,0,0);\n",
       "    var points = obj.userData.points;\n",
       "    for (var i=0; i<points.length; i++){\n",
       "        center.add(points[i].vector);\n",
       "    }\n",
       "    center.divideScalar(points.length);\n",
       "    return center;\n",
       "}\n",
       "\n",
       "function rotateVertices(obj, edge, scale) {\n",
       "    var axes = obj.userData.axes;\n",
       "    var subtrees = obj.userData.subtrees;\n",
       "    var points = obj.userData.points;\n",
       "    var angles = obj.userData.angles;\n",
       "    if (edge < axes.length){\n",
       "        for (var j=0; j<subtrees[edge].length; j++){\n",
       "            var rotP = rotate(points[subtrees[edge][j]].vector, points[axes[edge][0]].vector,points[axes[edge][1]].vector, scale * (Math.PI - angles[edge]));\n",
       "            points[subtrees[edge][j]].set(rotP[0],rotP[1],rotP[2]);\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function update(obj) {\n",
       "   updateFacesPosition(obj);\n",
       "   updateEdgesPosition(obj);\n",
       "}\n",
       "\n",
       "if (foldables.length) {\n",
       "    var settings = document.getElementById('settings_0');\n",
       "    var foldDiv = document.createElement('div');\n",
       "    foldDiv.id = 'fold_0';\n",
       "    var title = document.createElement('strong');\n",
       "    title.innerHTML = 'Fold';\n",
       "    foldDiv.appendChild(title);\n",
       "    foldDiv.className = 'group';\n",
       "    for (var i=0; i<foldables.length; i++) {\n",
       "        var range = document.createElement('input');\n",
       "        range.type = 'range';\n",
       "        range.min = 0;\n",
       "        range.max = 1;\n",
       "        range.value = 0;\n",
       "        range.step = 0.001;\n",
       "        range.name = String(i);\n",
       "        range.oninput = fold;\n",
       "        foldDiv.appendChild(range);\n",
       "    }\n",
       "    lookAtBarycenter(foldables[0]);\n",
       "    settings.insertBefore(foldDiv,settings.childNodes[0]);\n",
       "}\n",
       "\n",
       "    \n",
       "// ---------------------- EXPLOSION ------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "if (explodableModel) {\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        obj = scene.children[i];\n",
       "        if ( obj.userData.explodable ) {\n",
       "            computeCentroid(obj);\n",
       "        }\n",
       "    }\n",
       "    document.getElementById('explodeRange_0').oninput = triggerExplode;\n",
       "    document.getElementById('explodeCheckbox_0').onchange = triggerAutomaticExplode;\n",
       "    document.getElementById('explodingSpeedRange_0').oninput = setExplodingSpeed;\n",
       "}\n",
       "\n",
       "function computeCentroid(obj) {\n",
       "    centroid = new THREE.Vector3();\n",
       "    obj.userData.points.forEach(function(pmpoint) {\n",
       "        centroid.add(pmpoint.vector);\t\t\t\n",
       "    });\n",
       "    centroid.divideScalar(obj.userData.points.length);\n",
       "    obj.userData.centroid = centroid;\n",
       "}\n",
       "\n",
       "function explode(factor) {\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        var obj = scene.children[i];\n",
       "        if (obj.userData.hasOwnProperty(\"centroid\")) { \n",
       "            var c = obj.userData.centroid;\n",
       "            obj.position.set(c.x*factor, c.y*factor, c.z*factor);\n",
       "        }\n",
       "    }\t\n",
       "}\n",
       "\n",
       "function triggerExplode(event){\n",
       "    explodeScale = Number(event.currentTarget.value);\n",
       "    explode(explodeScale);\n",
       "}\n",
       "\n",
       "function setExplodingSpeed(event){\n",
       "    explodingSpeed = Number(event.currentTarget.value);\n",
       "}\n",
       "\n",
       "function triggerAutomaticExplode(event){\n",
       "    if (event.currentTarget.checked){\n",
       "        startExploding();\n",
       "    } else {\n",
       "        clearIntervals();\n",
       "    }\t\n",
       "}\n",
       "\n",
       "function startExploding(){\n",
       "    intervals.push(setInterval(explodingInterval, 25));\n",
       "}\n",
       "\n",
       "\n",
       "function explodingInterval(){\n",
       "    explodeScale += explodingSpeed;\n",
       "    if (explodeScale <= 6){ \n",
       "        explode(explodeScale);\n",
       "    }\n",
       "    else{\n",
       "        explode(6);\n",
       "        explodeScale = 6;\n",
       "        clearIntervals();\n",
       "        timeouts.push(setTimeout(startUnexploding, 3000));\n",
       "    }\n",
       "    document.getElementById('explodeRange_0').value = explodeScale;\n",
       "}\n",
       "\n",
       "\n",
       "function startUnexploding(){\n",
       "    intervals.push(setInterval(unexplodingInterval, 25));\n",
       "}\n",
       "\n",
       "function unexplodingInterval(){\n",
       "    explodeScale -= explodingSpeed;\n",
       "    if (explodeScale >= 0){\t\n",
       "        explode(explodeScale);\n",
       "    }\n",
       "    else {\n",
       "        explode(0);\n",
       "        explodeScale = 0;\n",
       "        clearIntervals();\n",
       "        timeouts.push(setTimeout(startExploding, 3000));\n",
       "    }\n",
       "    document.getElementById('explodeRange_0').value = explodeScale;\n",
       "}\n",
       "\n",
       "function clearIntervals(){\n",
       "    intervals.forEach(function(interval){\n",
       "        clearInterval(interval);\n",
       "    });\n",
       "    intervals = [];\n",
       "    timeouts.forEach(function(timeout){\n",
       "        clearTimeout(timeout);\n",
       "    });\n",
       "    timeouts = [];\n",
       "}\n",
       "\n",
       "// ---------------------- DISPLAY --------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "const objectTypeInnerHTMLs = { points: \"Points\", pointlabels: \"Point labels\", lines: \"Edges\", edgelabels: \"Edge labels\", faces: \"Faces\", arrowheads: \"Arrow heads\" };\n",
       "const objectTypeVisible = {};\n",
       "Object.assign(objectTypeVisible,modelContains);\n",
       "const sortedObjectTypeKeys = Object.keys(objectTypeInnerHTMLs).sort();\n",
       "const shownObjectTypesList = document.getElementById('shownObjectTypesList_0');\n",
       "\n",
       "function setVisibility(bool,objname) {\n",
       "    for (var i=0; i<scene.children.length; i++){\n",
       "        var obj = scene.children[i].getObjectByName(objname);\n",
       "        if (obj) {\n",
       "            obj.visible = bool;\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function toggleObjectTypeVisibility(event){\n",
       "    var name = event.currentTarget.name;\n",
       "    var checked = event.currentTarget.checked;\n",
       "    objectTypeVisible[name] = checked;\n",
       "    setVisibility(checked,name);\n",
       "}\n",
       "\n",
       "for (var i=0; i<sortedObjectTypeKeys.length; i++){\n",
       "    var key = sortedObjectTypeKeys[i];\n",
       "    if (modelContains[key]) {\n",
       "        var objTypeNode = document.createElement('span');\n",
       "        objTypeNode.innerHTML = objectTypeInnerHTMLs[key] + '<br>';\n",
       "        var checkbox = document.createElement('input');\n",
       "        checkbox.type = 'checkbox';\n",
       "        checkbox.checked = true;\n",
       "        checkbox.name = key;\n",
       "        checkbox.onchange = toggleObjectTypeVisibility;\n",
       "        shownObjectTypesList.appendChild(checkbox);\n",
       "        shownObjectTypesList.appendChild(objTypeNode);\n",
       "    }\n",
       "}\n",
       "\n",
       "// ------------------------------------------------------\n",
       "\n",
       "function toggleObjectVisibility(event){\n",
       "    var nr = Number(event.currentTarget.name);\n",
       "    scene.children[nr].visible = event.currentTarget.checked;\n",
       "}\n",
       "\n",
       "// append checkboxes for displaying or hiding objects\n",
       "var shownObjectsList = document.getElementById('shownObjectsList_0');\n",
       "for (var i=0; i<scene.children.length; i++){\n",
       "    obj = scene.children[i];\n",
       "    var objNode = document.createElement('span');\n",
       "    objNode.innerHTML = obj.name + '<br>';\n",
       "    var checkbox = document.createElement('input');\n",
       "    checkbox.type = 'checkbox';\n",
       "    checkbox.checked = true;\n",
       "    checkbox.name = String(i);\n",
       "    checkbox.onchange = toggleObjectVisibility;\n",
       "    shownObjectsList.appendChild(checkbox);\n",
       "    shownObjectsList.appendChild(objNode);\n",
       "}\n",
       "\n",
       "// ---------------------- SVG ------------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "function takeSvgScreenshot() {\n",
       "    if (objectTypeVisible[\"pointlabels\"]) {\n",
       "        setVisibility(false,\"pointlabels\");\n",
       "    }\n",
       "    if (objectTypeVisible[\"edgelabels\"]) {\n",
       "        setVisibility(false,\"edgelabels\");\n",
       "    }\n",
       "    svgRenderer.render(scene,camera);\n",
       "    svgElement = XMLS.serializeToString(svgRenderer.domElement);\n",
       "    \n",
       "    if (objectTypeVisible[\"pointlabels\"]) {\n",
       "        setVisibility(true,\"pointlabels\");\n",
       "    }\n",
       "    if (objectTypeVisible[\"edgelabels\"]) {\n",
       "        setVisibility(true,\"edgelabels\");\n",
       "    }\n",
       "\n",
       "    if (document.getElementById('tab_0').checked){\n",
       "        //show in new tab\n",
       "        var myWindow = window.open(\"\",\"\");\n",
       "        myWindow.document.body.innerHTML = svgElement;\n",
       "    } else{\n",
       "        // download svg file \n",
       "        download(\"screenshot.svg\", svgElement);\n",
       "    }\n",
       "}\n",
       "\n",
       "function download(filename, text) {\n",
       "    var element = document.createElement('a');\n",
       "    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));\n",
       "    element.setAttribute('download', filename);\n",
       "\n",
       "    element.style.display = 'none';\n",
       "    document.body.appendChild(element);\n",
       "\n",
       "    element.click();\n",
       "\n",
       "    document.body.removeChild(element);\n",
       "}\n",
       "\n",
       "\n",
       "document.getElementById('transparencyRange_0').oninput = changeTransparency;\n",
       "document.getElementById('changeRotationX_0').onchange = changeRotationX;\n",
       "document.getElementById('changeRotationY_0').onchange = changeRotationY;\n",
       "document.getElementById('changeRotationZ_0').onchange = changeRotationZ;\n",
       "document.getElementById('resetButton_0').onclick = resetScene;\n",
       "document.getElementById('rotationSpeedRange_0').oninput = changeRotationSpeedFactor;\n",
       "document.getElementById('takeScreenshot_0').onclick = takeSvgScreenshot;\n",
       "document.getElementById('showSettingsButton_0').onclick = showSettings;\n",
       "document.getElementById('hideSettingsButton_0').onclick = hideSettings;\n",
       "\n",
       "\n",
       "// ------------------ SHORTCUTS --------------------------------------------\n",
       "// -------------------------------------------------------------------------\n",
       "\n",
       "/**\n",
       " * http://www.openjs.com/scripts/events/keyboard_shortcuts/\n",
       " * Version : 2.01.B\n",
       " * By Binny V A\n",
       " * License : BSD\n",
       " */\n",
       "shortcut = {\n",
       "\t'all_shortcuts':{},//All the shortcuts are stored in this array\n",
       "\t'add': function(shortcut_combination,callback,opt) {\n",
       "\t\t//Provide a set of default options\n",
       "\t\tvar default_options = {\n",
       "\t\t\t'type':'keydown',\n",
       "\t\t\t'propagate':false,\n",
       "\t\t\t'disable_in_input':false,\n",
       "\t\t\t'target':document,\n",
       "\t\t\t'keycode':false\n",
       "\t\t}\n",
       "\t\tif(!opt) opt = default_options;\n",
       "\t\telse {\n",
       "\t\t\tfor(var dfo in default_options) {\n",
       "\t\t\t\tif(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];\n",
       "\t\t\t}\n",
       "\t\t}\n",
       "\n",
       "\t\tvar ele = opt.target;\n",
       "\t\tif(typeof opt.target == 'string') ele = document.getElementById(opt.target);\n",
       "\t\tvar ths = this;\n",
       "\t\tshortcut_combination = shortcut_combination.toLowerCase();\n",
       "\n",
       "\t\t//The function to be called at keypress\n",
       "\t\tvar func = function(e) {\n",
       "\t\t\te = e || window.event;\n",
       "\t\t\t\n",
       "\t\t\tif(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields\n",
       "\t\t\t\tvar element;\n",
       "\t\t\t\tif(e.target) element=e.target;\n",
       "\t\t\t\telse if(e.srcElement) element=e.srcElement;\n",
       "\t\t\t\tif(element.nodeType==3) element=element.parentNode;\n",
       "\n",
       "\t\t\t\tif(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;\n",
       "\t\t\t}\n",
       "\t\n",
       "\t\t\t//Find Which key is pressed\n",
       "\t\t\tif (e.keyCode) code = e.keyCode;\n",
       "\t\t\telse if (e.which) code = e.which;\n",
       "\t\t\tvar character = String.fromCharCode(code).toLowerCase();\n",
       "\t\t\t\n",
       "\t\t\tif(code == 188) character=\",\"; //If the user presses , when the type is onkeydown\n",
       "\t\t\tif(code == 190) character=\".\"; //If the user presses , when the type is onkeydown\n",
       "\n",
       "\t\t\tvar keys = shortcut_combination.split(\"+\");\n",
       "\t\t\t//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked\n",
       "\t\t\tvar kp = 0;\n",
       "\t\t\t\n",
       "\t\t\t//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken\n",
       "\t\t\tvar shift_nums = {\n",
       "\t\t\t\t\"`\":\"~\",\n",
       "\t\t\t\t\"1\":\"!\",\n",
       "\t\t\t\t\"2\":\"@\",\n",
       "\t\t\t\t\"3\":\"#\",\n",
       "\t\t\t\t\"4\":\"$\",\n",
       "\t\t\t\t\"5\":\"%\",\n",
       "\t\t\t\t\"6\":\"^\",\n",
       "\t\t\t\t\"7\":\"&\",\n",
       "\t\t\t\t\"8\":\"*\",\n",
       "\t\t\t\t\"9\":\"(\",\n",
       "\t\t\t\t\"0\":\")\",\n",
       "\t\t\t\t\"-\":\"_\",\n",
       "\t\t\t\t\"=\":\"+\",\n",
       "\t\t\t\t\";\":\":\",\n",
       "\t\t\t\t\"'\":\"\\\"\",\n",
       "\t\t\t\t\",\":\"<\",\n",
       "\t\t\t\t\".\":\">\",\n",
       "\t\t\t\t\"/\":\"?\",\n",
       "\t\t\t\t\"\\\\\":\"|\"\n",
       "\t\t\t}\n",
       "\t\t\t//Special Keys - and their codes\n",
       "\t\t\tvar special_keys = {\n",
       "\t\t\t\t'esc':27,\n",
       "\t\t\t\t'escape':27,\n",
       "\t\t\t\t'tab':9,\n",
       "\t\t\t\t'space':32,\n",
       "\t\t\t\t'return':13,\n",
       "\t\t\t\t'enter':13,\n",
       "\t\t\t\t'backspace':8,\n",
       "\t\n",
       "\t\t\t\t'scrolllock':145,\n",
       "\t\t\t\t'scroll_lock':145,\n",
       "\t\t\t\t'scroll':145,\n",
       "\t\t\t\t'capslock':20,\n",
       "\t\t\t\t'caps_lock':20,\n",
       "\t\t\t\t'caps':20,\n",
       "\t\t\t\t'numlock':144,\n",
       "\t\t\t\t'num_lock':144,\n",
       "\t\t\t\t'num':144,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'pause':19,\n",
       "\t\t\t\t'break':19,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'insert':45,\n",
       "\t\t\t\t'home':36,\n",
       "\t\t\t\t'delete':46,\n",
       "\t\t\t\t'end':35,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'pageup':33,\n",
       "\t\t\t\t'page_up':33,\n",
       "\t\t\t\t'pu':33,\n",
       "\t\n",
       "\t\t\t\t'pagedown':34,\n",
       "\t\t\t\t'page_down':34,\n",
       "\t\t\t\t'pd':34,\n",
       "\t\n",
       "\t\t\t\t'left':37,\n",
       "\t\t\t\t'up':38,\n",
       "\t\t\t\t'right':39,\n",
       "\t\t\t\t'down':40,\n",
       "\t\n",
       "\t\t\t\t'f1':112,\n",
       "\t\t\t\t'f2':113,\n",
       "\t\t\t\t'f3':114,\n",
       "\t\t\t\t'f4':115,\n",
       "\t\t\t\t'f5':116,\n",
       "\t\t\t\t'f6':117,\n",
       "\t\t\t\t'f7':118,\n",
       "\t\t\t\t'f8':119,\n",
       "\t\t\t\t'f9':120,\n",
       "\t\t\t\t'f10':121,\n",
       "\t\t\t\t'f11':122,\n",
       "\t\t\t\t'f12':123\n",
       "\t\t\t}\n",
       "\t\n",
       "\t\t\tvar modifiers = { \n",
       "\t\t\t\tshift: { wanted:false, pressed:false},\n",
       "\t\t\t\tctrl : { wanted:false, pressed:false},\n",
       "\t\t\t\talt  : { wanted:false, pressed:false},\n",
       "\t\t\t\tmeta : { wanted:false, pressed:false}\t//Meta is Mac specific\n",
       "\t\t\t};\n",
       "                        \n",
       "\t\t\tif(e.ctrlKey)\tmodifiers.ctrl.pressed = true;\n",
       "\t\t\tif(e.shiftKey)\tmodifiers.shift.pressed = true;\n",
       "\t\t\tif(e.altKey)\tmodifiers.alt.pressed = true;\n",
       "\t\t\tif(e.metaKey)   modifiers.meta.pressed = true;\n",
       "                        \n",
       "\t\t\tfor(var i=0; k=keys[i],i<keys.length; i++) {\n",
       "\t\t\t\t//Modifiers\n",
       "\t\t\t\tif(k == 'ctrl' || k == 'control') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.ctrl.wanted = true;\n",
       "\n",
       "\t\t\t\t} else if(k == 'shift') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.shift.wanted = true;\n",
       "\n",
       "\t\t\t\t} else if(k == 'alt') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.alt.wanted = true;\n",
       "\t\t\t\t} else if(k == 'meta') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.meta.wanted = true;\n",
       "\t\t\t\t} else if(k.length > 1) { //If it is a special key\n",
       "\t\t\t\t\tif(special_keys[k] == code) kp++;\n",
       "\t\t\t\t\t\n",
       "\t\t\t\t} else if(opt['keycode']) {\n",
       "\t\t\t\t\tif(opt['keycode'] == code) kp++;\n",
       "\n",
       "\t\t\t\t} else { //The special keys did not match\n",
       "\t\t\t\t\tif(character == k) kp++;\n",
       "\t\t\t\t\telse {\n",
       "\t\t\t\t\t\tif(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase\n",
       "\t\t\t\t\t\t\tcharacter = shift_nums[character]; \n",
       "\t\t\t\t\t\t\tif(character == k) kp++;\n",
       "\t\t\t\t\t\t}\n",
       "\t\t\t\t\t}\n",
       "\t\t\t\t}\n",
       "\t\t\t}\n",
       "\t\t\t\n",
       "\t\t\tif(kp == keys.length && \n",
       "\t\t\t\t\t\tmodifiers.ctrl.pressed == modifiers.ctrl.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.shift.pressed == modifiers.shift.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.alt.pressed == modifiers.alt.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.meta.pressed == modifiers.meta.wanted) {\n",
       "\t\t\t\tcallback(e);\n",
       "\t\n",
       "\t\t\t\tif(!opt['propagate']) { //Stop the event\n",
       "\t\t\t\t\t//e.cancelBubble is supported by IE - this will kill the bubbling process.\n",
       "\t\t\t\t\te.cancelBubble = true;\n",
       "\t\t\t\t\te.returnValue = false;\n",
       "\t\n",
       "\t\t\t\t\t//e.stopPropagation works in Firefox.\n",
       "\t\t\t\t\tif (e.stopPropagation) {\n",
       "\t\t\t\t\t\te.stopPropagation();\n",
       "\t\t\t\t\t\te.preventDefault();\n",
       "\t\t\t\t\t}\n",
       "\t\t\t\t\treturn false;\n",
       "\t\t\t\t}\n",
       "\t\t\t}\n",
       "\t\t}\n",
       "\t\tthis.all_shortcuts[shortcut_combination] = {\n",
       "\t\t\t'callback':func, \n",
       "\t\t\t'target':ele, \n",
       "\t\t\t'event': opt['type']\n",
       "\t\t};\n",
       "\t\t//Attach the function with the event\n",
       "\t\tif(ele.addEventListener) ele.addEventListener(opt['type'], func, false);\n",
       "\t\telse if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);\n",
       "\t\telse ele['on'+opt['type']] = func;\n",
       "\t},\n",
       "\n",
       "\t//Remove the shortcut - just specify the shortcut and I will remove the binding\n",
       "\t'remove':function(shortcut_combination) {\n",
       "\t\tshortcut_combination = shortcut_combination.toLowerCase();\n",
       "\t\tvar binding = this.all_shortcuts[shortcut_combination];\n",
       "\t\tdelete(this.all_shortcuts[shortcut_combination])\n",
       "\t\tif(!binding) return;\n",
       "\t\tvar type = binding['event'];\n",
       "\t\tvar ele = binding['target'];\n",
       "\t\tvar callback = binding['callback'];\n",
       "\n",
       "\t\tif(ele.detachEvent) ele.detachEvent('on'+type, callback);\n",
       "\t\telse if(ele.removeEventListener) ele.removeEventListener(type, callback, false);\n",
       "\t\telse ele['on'+type] = false;\n",
       "\t}\n",
       "}\n",
       "\n",
       "shortcut.add(\"Alt+Left\",function() {\n",
       "\tvar event = new Event('click');\n",
       "\tif (settingsShown){\n",
       "\t\tdocument.getElementById('hideSettingsButton_0').dispatchEvent(event);\n",
       "\t} else {\n",
       "\t\tdocument.getElementById('showSettingsButton_0').dispatchEvent(event);\n",
       "\t}\n",
       "});\n",
       "\n",
       "\n",
       "// COMMON_CODE_BLOCK_END\n",
       "\n",
       "});});\n",
       "      </script>\n",
       "   </body>\n",
       "</html>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<details><summary><pre style=\"display:inline\"><small>Click here for additional output</small></pre></summary>\n",
       "<pre>\n",
       "polymake: used package threejs\n",
       "   Three.js is a lightweight cross-browser JavaScript library/API used to create and display animated 3D computer graphics on a Web browser.\n",
       "   See http://github.com/mrdoob for the source code.\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "compose($l->VISUAL(VertexStyle=>\"hidden\",BoundingFacets=>$bbfacets), $div->VISUAL(VertexStyle=>\"hidden\",EdgeColor=>\"red\", BoundingFacets=>$bbfacets));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alternatively, we could simply specify an explicit bounding box to make the surface look more symmetric:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!--\n",
       "polymake for knusper\n",
       "Thu Aug 27 10:41:16 2020\n",
       "l\n",
       "-->\n",
       "\n",
       "\n",
       "<html>\n",
       "   <head>\n",
       "      <meta charset=utf-8>\n",
       "      <title>l</title>\n",
       "      <style>\n",
       "/*\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "*/\n",
       "         html {overflow: scroll;}\n",
       "         strong{font-size: 18px;}\n",
       "         canvas { z-index: 8; }\n",
       "         input[type='radio'] {margin-left:0;}\n",
       "         input[type='checkbox'] {margin-right:7px; margin-left: 0px; padding-left:0px;}\n",
       "         .group{padding-bottom: 15px;}\n",
       "         .settings * {z-index: 11; }\n",
       "         .settings{z-index: 10; font-family: Arial, Helvetica, sans-serif; margin-left: 30px; visibility: hidden; width: 14em; height: 96%; border: solid 1px silver; padding: 2px; overflow-y: scroll; box-sizing: border-box; background-color: white; position: absolute;}\n",
       "         .indented{margin-left: 20px; margin-top: 10px; padding-bottom: 0px;} \n",
       "         .shownObjectsList{overflow: auto; max-width: 150px; max-height: 150px;}\n",
       "         .showSettingsButton{visibility: visible; z-index: 12; position: absolute }\n",
       "         .hideSettingsButton{visibility: hidden; z-index: 12; position: absolute; opacity: 0.5}\n",
       "         button{margin-left: 0; margin-top: 10px}\n",
       "         img{cursor: pointer;}\n",
       "         .suboption{padding-top: 15px;}\n",
       "         #model87219611680 { width: 100%; height: 100%; }\n",
       "         .threejs_container { width: 100%; height: 75vh;}\n",
       "         .settings{max-height: 74vh} \n",
       "         input[type=range] {\n",
       "           -webkit-appearance: none;\n",
       "           padding:0; \n",
       "           width:90%; \n",
       "           margin-left: auto;\n",
       "           margin-right: auto;\n",
       "           margin-top: 15px;\n",
       "           margin-bottom: 15px;\n",
       "           display: block;\t\n",
       "         }\n",
       "         input[type=range]:focus {\n",
       "           outline: none;\n",
       "         }\n",
       "         input[type=range]::-webkit-slider-runnable-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "           background: #E3E3E3;\n",
       "           border-radius: 0px;\n",
       "           border: 0px solid #000000;\n",
       "         }\n",
       "         input[type=range]::-webkit-slider-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "           -webkit-appearance: none;\n",
       "           margin-top: -5px;\n",
       "         }\n",
       "         input[type=range]:focus::-webkit-slider-runnable-track {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "         input[type=range]::-moz-range-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "           background: #E3E3E3;\n",
       "           border-radius: 0px;\n",
       "           border: 0px solid #000000;\n",
       "         }\n",
       "         input[type=range]::-moz-range-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "         }\n",
       "         input[type=range]::-ms-track {\n",
       "           height: 4px;\n",
       "           cursor: pointer;\n",
       "           animate: 0.2s;\n",
       "           background: transparent;\n",
       "           border-color: transparent;\n",
       "           color: transparent;\n",
       "         }\n",
       "         input[type=range]::-ms-fill-lower {\n",
       "           background: #E3E3E3;\n",
       "           border: 0px solid #000000;\n",
       "           border-radius: 0px;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "         }\n",
       "         input[type=range]::-ms-fill-upper {\n",
       "           background: #E3E3E3;\n",
       "           border: 0px solid #000000;\n",
       "           border-radius: 0px;\n",
       "           box-shadow: 0px 0px 0px #000000;\n",
       "         }\n",
       "         input[type=range]::-ms-thumb {\n",
       "           box-shadow: 1px 1px 2px #B8B8B8;\n",
       "           border: 1px solid #ABABAB;\n",
       "           height: 13px;\n",
       "           width: 25px;\n",
       "           border-radius: 20px;\n",
       "           background: #E0E0E0;\n",
       "           cursor: pointer;\n",
       "         }\n",
       "         input[type=range]:focus::-ms-fill-lower {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "         input[type=range]:focus::-ms-fill-upper {\n",
       "           background: #E3E3E3;\n",
       "         }\n",
       "/*\n",
       "// COMMON_CODE_BLOCK_END\n",
       "*/\n",
       "\t\t</style>\n",
       "   </head>\n",
       "<body>\n",
       "   <div class='threejs_container'>\n",
       "\t\t<div id='settings_1' class='settings'>\n",
       "\t\t\t<div class=group id='explode_1'>\n",
       "\t\t\t\t<strong>Explode</strong>\n",
       "\t\t\t\t<input id='explodeRange_1' type='range' min=0 max=6 step=0.01 value=0>\n",
       "\t\t\t\t<div class=indented><input id='explodeCheckbox_1' type='checkbox'>Automatic explosion</div>\n",
       "\t\t\t\t<div class=suboption>Exploding speed</div>\n",
       "\t\t\t\t<input id='explodingSpeedRange_1' type='range' min=0 max=0.5 step=0.001 value=0.05>\n",
       "\t\t\t</div>\n",
       "\t\n",
       "\t\t\t<div class=group id='transparency_1' class='transparency'>\n",
       "\t\t\t\t<strong>Transparency</strong>\n",
       "\t\t\t\t<input id='transparencyRange_1' type='range' min=0 max=1 step=0.01 value=0>\n",
       "\t\t\t</div>\n",
       "\t\t\t\n",
       "\t\t\t<div class=group id='rotation_1'>\n",
       "\t\t\t\t<strong>Rotation</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationX_1'> x-axis</div>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationY_1'> y-axis</div>\n",
       "\t\t\t\t\t<div><input type='checkbox' id='changeRotationZ_1'> z-axis</div>\n",
       "\t\t\t\t\t<button id='resetButton_1'>Reset</button>\n",
       "\t\t\t\t</div>\n",
       "\n",
       "\t\t\t\t<div class=suboption>Rotation speed</div>\n",
       "\t\t\t\t<input id='rotationSpeedRange_1' type='range' min=0 max=5 step=0.01 value=2>\n",
       "\t\t\t</div>\n",
       "\n",
       "\n",
       "\t\t\t<div class=group id='display_1'>\n",
       "\t\t\t\t<strong>Display</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<div id='shownObjectTypesList_1' class='shownObjectsList'></div>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t\t<div class=suboption>Objects</div>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t   <div id='shownObjectsList_1' class='shownObjectsList'></div>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t</div>\n",
       "         \n",
       "         <div class=group id='camera_1'>\n",
       "            <strong>Camera</strong>\n",
       "            <div class=indented>\n",
       "               <form>\n",
       "                  <select id=\"cameraType_1\">\n",
       "                     <option value='perspective' selected> Perspective<br></option>\n",
       "                     <option value='orthographic' > Orthographic<br></option>\n",
       "                  </select>\n",
       "               </form>\n",
       "            </div>\n",
       "         </div>\n",
       "\n",
       "\t\t\t<div class=group id='svg_1'>\n",
       "\t\t\t\t<strong>SVG</strong>\n",
       "\t\t\t\t<div class=indented>\n",
       "\t\t\t\t\t<form>\n",
       "\t\t\t\t\t\t<input type=\"radio\" name='screenshotMode' value='download' id='download_1' checked> Download<br>\n",
       "\t\t\t\t\t\t<input type=\"radio\" name='screenshotMode' value='tab' id='tab_1' > New tab<br>\n",
       "\t\t\t\t\t</form>\n",
       "\t\t\t\t\t<button id='takeScreenshot_1'>Screenshot</button>\n",
       "\t\t\t\t</div>\n",
       "\t\t\t</div>\n",
       "\n",
       "\t\t</div>\t<!-- end of settings -->\n",
       "\t\t<img id='hideSettingsButton_1' class='hideSettingsButton' src='/kernelspecs/polymake/close.svg' width=20px\">\n",
       "\t\t<img id='showSettingsButton_1' class='showSettingsButton' src='/kernelspecs/polymake/menu.svg' width=20px\">\n",
       "<div id=\"model87219611680\"></div>\n",
       "</div>\n",
       "   <script>\n",
       "    requirejs.config({\n",
       "      paths: {\n",
       "        three: '/kernelspecs/polymake/three',\n",
       "        TrackballControls: '/kernelspecs/polymake/TrackballControls',\n",
       "        OrbitControls: '/kernelspecs/polymake/OrbitControls',\n",
       "        Projector: '/kernelspecs/polymake/Projector',\n",
       "        SVGRenderer: '/kernelspecs/polymake/SVGRenderer',\n",
       "        WEBGL: '/kernelspecs/polymake/WebGL',\n",
       "      },\n",
       "      shim: {\n",
       "        'three': { exports: 'THREE'},\n",
       "        'SVGRenderer': { deps: [ 'three' ], exports: 'THREE.SVGRenderer' },\n",
       "        'WEBGL': { deps: [ 'three' ], exports: 'THREE.WEBGL' },\n",
       "        'Projector': { deps: [ 'three' ], exports: 'THREE.Projector' },\n",
       "        'TrackballControls': { deps: [ 'three' ], exports: 'THREE.TrackballControls' },\n",
       "        'OrbitControls': { deps: [ 'three' ], exports: 'THREE.OrbitControls' },\n",
       "      }\n",
       "    });\n",
       "    \n",
       "    require(['three'],function(THREE){\n",
       "        window.THREE = THREE;\n",
       "      require(['TrackballControls', 'OrbitControls', 'Projector', 'SVGRenderer', 'WEBGL'],\n",
       "               function(TrackballControls, OrbitControls, Projector, SVGRenderer, WEBGL) {\n",
       "    THREE.TrackballControls = TrackballControls;\n",
       "    THREE.OrbitControls = OrbitControls;\n",
       "    THREE.Projector = Projector;\n",
       "    THREE.SVGRenderer = SVGRenderer;\n",
       "    THREE.WEBGL = WEBGL;\n",
       "\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "\n",
       "const intervalLength = 25; // for automatic animations\n",
       "const explodableModel = true; \n",
       "const modelContains = { points: false, pointlabels: false, lines: false, edgelabels: false, faces: false, arrowheads: false };\n",
       "const foldables = [];\n",
       "\n",
       "var three = document.getElementById(\"model87219611680\");\n",
       "var scene = new THREE.Scene();\n",
       "var renderer = new THREE.WebGLRenderer( { antialias: true } );\n",
       "var svgRenderer = new THREE.SVGRenderer( { antialias: true } );\n",
       "renderer.setPixelRatio( window.devicePixelRatio );\n",
       "renderer.setClearColor(0xFFFFFF, 1);\n",
       "svgRenderer.setClearColor(0xFFFFFF, 1);\n",
       "three.appendChild(renderer.domElement);\n",
       "\n",
       "var frustumSize = 4;\n",
       "var cameras = [new THREE.PerspectiveCamera(75, 1, 0.1, 1000), new THREE.OrthographicCamera()];\n",
       "cameras.forEach(function(cam) {\n",
       "    cam.position.set(0, 0, 5);\n",
       "    cam.lookAt(0, 0, 0);  \n",
       "    cam.up.set(0, 1, 0);         \n",
       "});\n",
       "var controls = [new THREE.TrackballControls(cameras[0], three), new THREE.OrbitControls(cameras[1], three)];\n",
       "var camera, control;\n",
       "\n",
       "controls[0].zoomSpeed = 0.2;\n",
       "controls[0].rotateSpeed = 4;\n",
       "\n",
       "\n",
       "// class to allow move points together with labels and spheres\n",
       "var PMPoint = function (x,y,z) {\n",
       "   this.vector = new THREE.Vector3(x,y,z);\n",
       "   this.sprite = null;\n",
       "   this.sphere = null;\n",
       "}\n",
       "PMPoint.prototype.addLabel = function(labelsprite) {\n",
       "   this.sprite = labelsprite;\n",
       "   this.sprite.position.copy(this.vector);\n",
       "}\n",
       "PMPoint.prototype.addSphere = function(spheremesh) {\n",
       "   this.sphere = spheremesh;\n",
       "   this.sphere.position.copy(this.vector);\n",
       "}\n",
       "PMPoint.prototype.set = function(x,y,z) {\n",
       "   this.vector.set(x,y,z);\n",
       "   if (this.sprite) {\n",
       "      this.sprite.position.copy(this.vector);\n",
       "   }\n",
       "   if (this.sphere) {\n",
       "      this.sphere.position.copy(this.vector);\n",
       "   }\n",
       "}\n",
       "PMPoint.prototype.radius = function() {\n",
       "   if (this.sphere) {\n",
       "      return this.sphere.geometry.parameters.radius;\n",
       "   } else {\n",
       "      return 0;\n",
       "   }\n",
       "};\n",
       "// select the target node\n",
       "var target = document.querySelector('#model87219611680');\n",
       "\n",
       "// create an observer instance\n",
       "var observer = new MutationObserver(function(mutations) {\n",
       "   mutations.forEach(function(mutation) {\n",
       "      if (mutation.removedNodes && mutation.removedNodes.length > 0) {\n",
       "         cancelAnimationFrame(renderId);\n",
       "         observer.disconnect();\n",
       "         console.log(\"cancelled frame \"+renderId);\n",
       "      }\n",
       "   });\n",
       "});\n",
       "\n",
       "// configuration of the observer:\n",
       "var config = { childList: true, characterData: true }\n",
       "\n",
       "// pass in the target node, as well as the observer options\n",
       "while (target) {\n",
       "   if (target.className==\"output\") {\n",
       "      observer.observe(target, config);\n",
       "      break;\n",
       "   }\n",
       "   target = target.parentNode;\n",
       "}\n",
       "\n",
       "// COMMON_CODE_BLOCK_END\n",
       "\n",
       "var obj0 = new THREE.Object3D();\n",
       "obj0.name = \"unnamed__1\";\n",
       "obj0.userData.explodable = 1;\n",
       "obj0.userData.points = [];\n",
       "obj0.userData.points.push(new PMPoint(5, 0, 0));\n",
       "obj0.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj0.userData.points.push(new PMPoint(5, -5, -5));\n",
       "obj0.userData.points.push(new PMPoint(-5, -5, -5));\n",
       "\n",
       "obj0.userData.edgeindices = [0, 1, 0, 2, 1, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj0.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj0.userData.facets = [[1, 0, 2, 3]];\n",
       "   <!-- Facet style -->\n",
       "obj0.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj0);\n",
       "scene.add(obj0);\n",
       "\n",
       "var obj1 = new THREE.Object3D();\n",
       "obj1.name = \"unnamed__2\";\n",
       "obj1.userData.explodable = 1;\n",
       "obj1.userData.points = [];\n",
       "obj1.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj1.userData.points.push(new PMPoint(0, 5, 0));\n",
       "obj1.userData.points.push(new PMPoint(-5, 5, -5));\n",
       "obj1.userData.points.push(new PMPoint(-5, -5, -5));\n",
       "\n",
       "obj1.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj1.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj1.userData.facets = [[0, 1, 2, 3]];\n",
       "   <!-- Facet style -->\n",
       "obj1.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj1);\n",
       "scene.add(obj1);\n",
       "\n",
       "var obj2 = new THREE.Object3D();\n",
       "obj2.name = \"unnamed__3\";\n",
       "obj2.userData.explodable = 1;\n",
       "obj2.userData.points = [];\n",
       "obj2.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj2.userData.points.push(new PMPoint(0, 0, 5));\n",
       "obj2.userData.points.push(new PMPoint(-5, -5, 5));\n",
       "obj2.userData.points.push(new PMPoint(-5, -5, -5));\n",
       "\n",
       "obj2.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj2.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj2.userData.facets = [[0, 1, 2, 3]];\n",
       "   <!-- Facet style -->\n",
       "obj2.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj2);\n",
       "scene.add(obj2);\n",
       "\n",
       "var obj3 = new THREE.Object3D();\n",
       "obj3.name = \"unnamed__4\";\n",
       "obj3.userData.explodable = 1;\n",
       "obj3.userData.points = [];\n",
       "obj3.userData.points.push(new PMPoint(5, 0, 0));\n",
       "obj3.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj3.userData.points.push(new PMPoint(0, 5, 0));\n",
       "obj3.userData.points.push(new PMPoint(5, 5, 0));\n",
       "\n",
       "obj3.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj3.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj3.userData.facets = [[0, 3, 2, 1]];\n",
       "   <!-- Facet style -->\n",
       "obj3.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj3);\n",
       "scene.add(obj3);\n",
       "\n",
       "var obj4 = new THREE.Object3D();\n",
       "obj4.name = \"unnamed__5\";\n",
       "obj4.userData.explodable = 1;\n",
       "obj4.userData.points = [];\n",
       "obj4.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj4.userData.points.push(new PMPoint(5, 0, 0));\n",
       "obj4.userData.points.push(new PMPoint(0, 0, 5));\n",
       "obj4.userData.points.push(new PMPoint(5, 0, 5));\n",
       "\n",
       "obj4.userData.edgeindices = [0, 1, 0, 2, 1, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj4.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj4.userData.facets = [[0, 2, 3, 1]];\n",
       "   <!-- Facet style -->\n",
       "obj4.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj4);\n",
       "scene.add(obj4);\n",
       "\n",
       "var obj5 = new THREE.Object3D();\n",
       "obj5.name = \"unnamed__6\";\n",
       "obj5.userData.explodable = 1;\n",
       "obj5.userData.points = [];\n",
       "obj5.userData.points.push(new PMPoint(0, 5, 0));\n",
       "obj5.userData.points.push(new PMPoint(0, 0, 0));\n",
       "obj5.userData.points.push(new PMPoint(0, 0, 5));\n",
       "obj5.userData.points.push(new PMPoint(0, 5, 5));\n",
       "\n",
       "obj5.userData.edgeindices = [0, 1, 1, 2, 0, 3, 2, 3];\n",
       "   <!-- Edge style -->\n",
       "obj5.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "obj5.userData.facets = [[0, 3, 2, 1]];\n",
       "   <!-- Facet style -->\n",
       "obj5.userData.facetmaterial = new THREE.MeshBasicMaterial( { color: 0x77EC9E, depthFunc: THREE.LessDepth, opacity: 1, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.5, side: THREE.DoubleSide, transparent: true } );\n",
       "init_object(obj5);\n",
       "scene.add(obj5);\n",
       "\n",
       "var obj6 = new THREE.Object3D();\n",
       "obj6.name = \"unnamed__7\";\n",
       "obj6.userData.explodable = 1;\n",
       "obj6.userData.points = [];\n",
       "obj6.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj6.userData.points.push(new PMPoint(-3.66667, -5, -5));\n",
       "\n",
       "obj6.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj6.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj6);\n",
       "scene.add(obj6);\n",
       "\n",
       "var obj7 = new THREE.Object3D();\n",
       "obj7.name = \"unnamed__8\";\n",
       "obj7.userData.explodable = 1;\n",
       "obj7.userData.points = [];\n",
       "obj7.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj7.userData.points.push(new PMPoint(3, 0, 0));\n",
       "\n",
       "obj7.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj7.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj7);\n",
       "scene.add(obj7);\n",
       "\n",
       "var obj8 = new THREE.Object3D();\n",
       "obj8.name = \"unnamed__9\";\n",
       "obj8.userData.explodable = 1;\n",
       "obj8.userData.points = [];\n",
       "obj8.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj8.userData.points.push(new PMPoint(-3, 5, -3));\n",
       "\n",
       "obj8.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj8.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj8);\n",
       "scene.add(obj8);\n",
       "\n",
       "var obj9 = new THREE.Object3D();\n",
       "obj9.name = \"unnamed__10\";\n",
       "obj9.userData.explodable = 1;\n",
       "obj9.userData.points = [];\n",
       "obj9.userData.points.push(new PMPoint(-1, -1, -1));\n",
       "obj9.userData.points.push(new PMPoint(-3, -3, 5));\n",
       "\n",
       "obj9.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj9.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj9);\n",
       "scene.add(obj9);\n",
       "\n",
       "var obj10 = new THREE.Object3D();\n",
       "obj10.name = \"unnamed__11\";\n",
       "obj10.userData.explodable = 1;\n",
       "obj10.userData.points = [];\n",
       "obj10.userData.points.push(new PMPoint(5, 1, 0));\n",
       "obj10.userData.points.push(new PMPoint(3, 0, 0));\n",
       "\n",
       "obj10.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj10.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj10);\n",
       "scene.add(obj10);\n",
       "\n",
       "var obj11 = new THREE.Object3D();\n",
       "obj11.name = \"unnamed__12\";\n",
       "obj11.userData.explodable = 1;\n",
       "obj11.userData.points = [];\n",
       "obj11.userData.points.push(new PMPoint(5, 0, 1));\n",
       "obj11.userData.points.push(new PMPoint(3, 0, 0));\n",
       "\n",
       "obj11.userData.edgeindices = [1, 0];\n",
       "   <!-- Edge style -->\n",
       "obj11.userData.edgematerial = new THREE.LineBasicMaterial( { color: 0xFF0000, depthTest: true, linewidth: 1.5, transparent: false } );\n",
       "init_object(obj11);\n",
       "scene.add(obj11);\n",
       "\n",
       "// COMMON_CODE_BLOCK_BEGIN\n",
       "function textSpriteMaterial(message, parameters) {\n",
       "    if ( parameters === undefined ) parameters = {};\n",
       "    var fontface = \"Helvetica\";\n",
       "    var fontsize = parameters.hasOwnProperty(\"fontsize\") ? parameters[\"fontsize\"] : 15;\n",
       "    fontsize = fontsize*10;\n",
       "    var lines = message.split('\\\\n');\n",
       "    var size = 512;\n",
       "    for(var i = 0; i<lines.length; i++){\n",
       "        var tmp = lines[i].length;\n",
       "        while(tmp*fontsize > size){\n",
       "           fontsize--;\n",
       "        }\n",
       "    }\n",
       "    \n",
       "    var canvas = document.createElement('canvas');\n",
       "    canvas.width = size;\n",
       "    canvas.height = size;\n",
       "    var context = canvas.getContext('2d');\n",
       "    context.fillStyle = \"rgba(255, 255, 255, 0)\";\n",
       "    context.fill();\n",
       "    context.font = fontsize + \"px \" + fontface;\n",
       "    \n",
       "    // text color\n",
       "    context.fillStyle = \"rgba(0, 0, 0, 1.0)\";\n",
       "     for(var i = 0; i<lines.length; i++){\n",
       "        context.fillText(lines[i], size/2, size/2+i*fontsize);\n",
       "     }\n",
       "    \n",
       "    // canvas contents will be used for a texture\n",
       "    var texture = new THREE.Texture(canvas);\n",
       "    texture.needsUpdate = true;\n",
       "    \n",
       "    var spriteMaterial = new THREE.SpriteMaterial({map: texture, depthTest: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: 1 });\n",
       "    return spriteMaterial;\n",
       "}\n",
       "\n",
       "\n",
       "// ---------------------- INITIALIZING OBJECTS--------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "function init_object(obj) {\n",
       "    if (obj.userData.hasOwnProperty(\"pointmaterial\")) {\n",
       "        init_points(obj);\n",
       "        modelContains.points = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"pointlabels\")) {\n",
       "        init_pointlabels(obj);\n",
       "        modelContains.pointlabels = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"edgematerial\")) {\n",
       "        init_lines(obj);\n",
       "        modelContains.lines = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"edgelabels\")) {\n",
       "        init_edgelabels(obj);\n",
       "        modelContains.edgelabels = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"arrowstyle\")) {\n",
       "        init_arrowheads(obj);\n",
       "        modelContains.arrowheads = true;\n",
       "    }\n",
       "    if (obj.userData.hasOwnProperty(\"facetmaterial\")) {\n",
       "        init_faces(obj);\n",
       "        modelContains.faces = true;\n",
       "    }\n",
       "}\n",
       "\n",
       "function init_points(obj) {\n",
       "    var pointgroup = new THREE.Group();\n",
       "    pointgroup.name = \"points\";\n",
       "    var points = obj.userData.points;\n",
       "    var radii = obj.userData.pointradii;\n",
       "    var materials = obj.userData.pointmaterial;\n",
       "    var geometry,material;\n",
       "    if (!Array.isArray(radii)) {\n",
       "        geometry = new THREE.SphereBufferGeometry(radii);  \n",
       "    }\n",
       "    if (!Array.isArray(materials)) {\n",
       "        material = materials;\n",
       "    }\n",
       "    for (var i=0; i<points.length; i++) {\n",
       "        var point = points[i];\n",
       "        if (Array.isArray(radii)) {\n",
       "            if (radii[i] == 0) {\n",
       "                continue;\n",
       "            }\n",
       "            geometry = new THREE.SphereBufferGeometry(radii[i]);  \n",
       "        } \n",
       "        if (Array.isArray(materials)) {\n",
       "            material = materials[i];     \n",
       "        } \n",
       "        var sphere = new THREE.Mesh(geometry, material);\n",
       "        point.addSphere(sphere);\n",
       "        pointgroup.add(sphere);\n",
       "    }\n",
       "    obj.add(pointgroup);\n",
       "}\n",
       "\n",
       "function init_pointlabels(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var labels = obj.userData.pointlabels;\n",
       "    var pointlabels = new THREE.Group();\n",
       "    pointlabels.name = \"pointlabels\";\n",
       "    if (Array.isArray(labels)) {\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "            var spriteMaterial = textSpriteMaterial( labels[i] );\n",
       "\t        var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            point.addLabel(sprite);\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    } else {\n",
       "        var spriteMaterial = textSpriteMaterial( labels );\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "\t        var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            point.addLabel(sprite);\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    }\n",
       "    obj.add(pointlabels);\n",
       "}\n",
       "\n",
       "function init_lines(obj) {\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var points = obj.userData.points;\n",
       "    var materials = obj.userData.edgematerial;\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    var bufarr = new Float32Array( obj.userData.edgeindices.length * 3 );\n",
       "    var bufattr = new THREE.Float32BufferAttribute( bufarr, 3 );\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    geometry.setAttribute('position', bufattr);\n",
       "    if (Array.isArray(materials)) {     \n",
       "        for (var i=0; i<materials.length; i++) {\n",
       "            geometry.addGroup(2*i,2,i);\n",
       "        }\n",
       "    }\n",
       "    var lines = new THREE.LineSegments(geometry, materials);\n",
       "    lines.name = \"lines\";\n",
       "    obj.add(lines);\n",
       "    updateEdgesPosition(obj);\n",
       "}\n",
       "\n",
       "function init_edgelabels(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var labels = obj.userData.edgelabels;\n",
       "    var edgelabels = new THREE.Group();\n",
       "    edgelabels.name = \"edgelabels\";\n",
       "    if (Array.isArray(labels)) {\n",
       "        for (var i=0; i<edgeindices.length; i=i+2) {\n",
       "            var point = points[i];\n",
       "            var spriteMaterial = textSpriteMaterial( labels[i] );\n",
       "            var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            sprite.position.copy(new THREE.Vector3().addVectors(points[edgeindices[i]].vector,points[edgeindices[i+1]].vector).multiplyScalar(0.5));\n",
       "            edgelabels.add(sprite);\n",
       "        }\n",
       "    } else {\n",
       "        var spriteMaterial = textSpriteMaterial( labels );\n",
       "        for (var i=0; i<points.length; i++) {\n",
       "            var point = points[i];\n",
       "            var sprite = new THREE.Sprite(spriteMaterial);\n",
       "            sprite.position.copy(new THREE.Vector3().addVectors(points[edgeindices[i]].vector,points[edgeindices[i+1]].vector).multiplyScalar(0.5));\n",
       "            pointlabels.add(sprite);\n",
       "        }\n",
       "    }\n",
       "    obj.add(edgelabels);\n",
       "}\n",
       "\n",
       "function init_arrowheads(obj) {\n",
       "    var arrowheads = new THREE.Group();\n",
       "    arrowheads.name = \"arrowheads\";\n",
       "    var arrowstyle = obj.userData.arrowstyle;\n",
       "    var edgeindices = obj.userData.edgeindices;\n",
       "    var edgematerials = obj.userData.edgematerial;\n",
       "    var points = obj.userData.points;\n",
       "    var material;\n",
       "    if (!Array.isArray(edgematerials)) {\n",
       "        material = new THREE.MeshBasicMaterial( {color: edgematerials.color} );\n",
       "    }\n",
       "\n",
       "    for (var i=0; i<edgeindices.length; i=i+2) {\n",
       "        var start = points[edgeindices[i]];\n",
       "        var end = points[edgeindices[i+1]];\n",
       "        var dist = start.vector.distanceTo( end.vector ) - start.radius() - end.radius();\n",
       "        if (dist <= 0) {\n",
       "            continue;\n",
       "        }\n",
       "        var dir = new THREE.Vector3().subVectors(end.vector,start.vector);\n",
       "        dir.normalize();\n",
       "        var axis = new THREE.Vector3().set(dir.z,0,-dir.x);\n",
       "        axis.normalize();\n",
       "        var radians = Math.acos( dir.y );\n",
       "        var radius = dist/25;\n",
       "        var height = dist/5;\n",
       "        var geometry = new THREE.ConeBufferGeometry(radius,height);\n",
       "        var position = new THREE.Vector3().addVectors(start.vector,dir.clone().multiplyScalar(start.radius()+dist-height/2));\n",
       "        if (Array.isArray(edgematerials)) {\n",
       "            material = new THREE.MeshBasicMaterial( {color: edgematerials[i].color} );\n",
       "        }\n",
       "        var cone = new THREE.Mesh( geometry, material );\n",
       "        cone.quaternion.setFromAxisAngle(axis,radians);;\n",
       "        cone.position.copy(position);;\n",
       "        arrowheads.add(cone);\n",
       "    }\n",
       "    obj.add(arrowheads);\n",
       "}\n",
       "\n",
       "function init_faces(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var facets = obj.userData.facets;\n",
       "    obj.userData.triangleindices = [];\n",
       "    for (var i=0; i<facets.length; i++) {\n",
       "        facet = facets[i];\n",
       "        for (var t=0; t<facet.length-2; t++) {\n",
       "            obj.userData.triangleindices.push(facet[0],facet[t+1],facet[t+2]);  \n",
       "        }\n",
       "    }\n",
       "    var bufarr = new Float32Array( obj.userData.triangleindices.length * 3 );\n",
       "    var bufattr = new THREE.Float32BufferAttribute(bufarr,3);\n",
       "    \n",
       "    var materials = obj.userData.facetmaterial;\n",
       "    var geometry = new THREE.BufferGeometry();\n",
       "    geometry.setAttribute('position',bufattr);\n",
       "    if (Array.isArray(materials)) {\n",
       "        var tricount = 0;\n",
       "        var facet;\n",
       "        for (var i=0; i<facets.length; i++) {\n",
       "            facet = facets[i];\n",
       "            geometry.addGroup(tricount,(facet.length-2)*3,i);\n",
       "            tricount += (facet.length-2)*3;\n",
       "        }\n",
       "    }\n",
       "    var mesh = new THREE.Mesh(geometry, materials);\n",
       "    mesh.name = \"faces\";\n",
       "    obj.add(mesh); \n",
       "    updateFacesPosition(obj);\n",
       "}\n",
       "// //INITIALIZING\n",
       "\n",
       "\n",
       "function updateFacesPosition(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var indices = obj.userData.triangleindices;\n",
       "    var faces = obj.getObjectByName(\"faces\");\n",
       "    var ba = faces.geometry.getAttribute(\"position\");\n",
       "    for (var i=0; i<indices.length; i++) {\n",
       "        ba.setXYZ(i, points[indices[i]].vector.x, points[indices[i]].vector.y ,points[indices[i]].vector.z); \n",
       "    }\n",
       "    faces.geometry.attributes.position.needsUpdate = true;\n",
       "    \n",
       "}\n",
       "\n",
       "function updateEdgesPosition(obj) {\n",
       "    var points = obj.userData.points;\n",
       "    var indices = obj.userData.edgeindices;\n",
       "    var lines = obj.getObjectByName(\"lines\");\n",
       "    var ba = lines.geometry.getAttribute(\"position\"); \n",
       "    for (var i=0; i<indices.length; i++) {\n",
       "        ba.setXYZ(i, points[indices[i]].vector.x, points[indices[i]].vector.y ,points[indices[i]].vector.z); \n",
       "    }\n",
       "    lines.geometry.attributes.position.needsUpdate = true;\n",
       "}\n",
       "\n",
       "function onWindowResize() {\n",
       "    renderer.setSize( three.clientWidth, three.clientHeight );\n",
       "    svgRenderer.setSize( three.clientWidth, three.clientHeight );\n",
       "    updateCamera();\n",
       "}\n",
       "\n",
       "function updateCamera() {\n",
       "    var width = three.clientWidth;\n",
       "    var height = three.clientHeight;\n",
       "    var aspect = width / height;\n",
       "    if (camera.type == \"OrthographicCamera\") {\n",
       "        camera.left = frustumSize * aspect / - 2;\n",
       "        camera.right = frustumSize * aspect / 2;\n",
       "        camera.top = frustumSize / 2;\n",
       "        camera.bottom = - frustumSize / 2;\n",
       "    } else if (camera.type == \"PerspectiveCamera\") {\n",
       "        camera.aspect = aspect;\n",
       "    }\n",
       "    camera.updateProjectionMatrix();\n",
       "}\n",
       "\n",
       "function changeCamera(event) {\n",
       "    var selindex = event.currentTarget.selectedIndex;\n",
       "    camera = cameras[selindex];\n",
       "    control = controls[selindex];\n",
       "    control.enabled = true; \n",
       "    for (var i=0; i<controls.length; i++) {\n",
       "        if (i!=selindex) {\n",
       "            controls[i].enabled = false;\n",
       "        }\n",
       "    }\n",
       "    updateCamera();\n",
       "}\n",
       "\n",
       "var camtypenode = document.getElementById('cameraType_1');\n",
       "camtypenode.onchange = changeCamera;\n",
       "camtypenode.dispatchEvent(new Event('change'));\n",
       "\n",
       "onWindowResize();\n",
       "window.addEventListener('resize', onWindowResize);\t\n",
       "\n",
       "\n",
       "var xRotationEnabled = false;\n",
       "var yRotationEnabled = false;\n",
       "var zRotationEnabled = false;\n",
       "var rotationSpeedFactor = 1;\n",
       "var settingsShown = false;\n",
       "var labelsShown = true;\n",
       "var intervals = [];\n",
       "var timeouts = [];\n",
       "var explodingSpeed = 0.05;\n",
       "var explodeScale = 0;\n",
       "var XMLS = new XMLSerializer();\n",
       "var svgElement;\n",
       "var renderId;\n",
       "\n",
       "var render = function () {\n",
       "\n",
       "\trenderId = requestAnimationFrame(render);\n",
       "\n",
       "//\tcomment in for automatic explosion\n",
       "//\texplode(updateFactor());\n",
       "\n",
       "    var phi = 0.02 * rotationSpeedFactor;\n",
       "\n",
       "    if (xRotationEnabled) {\n",
       "        scene.rotation.x += phi;\n",
       "    }\n",
       "    if (yRotationEnabled) {\n",
       "        scene.rotation.y += phi;\n",
       "    }\n",
       "    if (zRotationEnabled) {\n",
       "        scene.rotation.z += phi;\n",
       "    }\n",
       "\n",
       "    control.update();\n",
       "    renderer.render(scene, camera);\n",
       "};\n",
       "\n",
       "if ( THREE.WEBGL.isWebGLAvailable() ) {\n",
       "\trender();\n",
       "} else {\n",
       "\tvar warning = WEBGL.getWebGLErrorMessage();\n",
       "\tthree.appendChild( warning );\n",
       "}\n",
       "    \n",
       "function changeTransparency() {\n",
       "    var opacity = 1-Number(event.currentTarget.value);\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        child = scene.children[i];\n",
       "        if ( child.userData.hasOwnProperty(\"facetmaterial\") ) {\n",
       "            if (Array.isArray(child.userData.facetmaterial)) {\n",
       "                for (var j=0; j<child.userData.facetmaterial.length; j++) {\n",
       "                    child.userData.facetmaterial[j].opacity = opacity;\n",
       "                }\n",
       "            } else {\n",
       "                child.userData.facetmaterial.opacity = opacity;\n",
       "            }    \n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function changeRotationX(event){\n",
       "    xRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "function changeRotationY(event){\n",
       "    yRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "function changeRotationZ(event){\n",
       "    zRotationEnabled = event.currentTarget.checked;\n",
       "}\t\n",
       "\n",
       "\n",
       "function changeRotationSpeedFactor(event){\n",
       "    rotationSpeedFactor = Number(event.currentTarget.value);\n",
       "}\n",
       "\n",
       "function resetScene(){\n",
       "    scene.rotation.set(0,0,0);\n",
       "    camera.position.set(0,0,5);\n",
       "    camera.up.set(0,1,0);\n",
       "}\n",
       "\n",
       "function showSettings(event){\n",
       "    document.getElementById('settings_1').style.visibility = 'visible';\n",
       "    document.getElementById('showSettingsButton_1').style.visibility = 'hidden';\n",
       "    document.getElementById('hideSettingsButton_1').style.visibility = 'visible';\n",
       "    settingsShown = true;\n",
       "}\n",
       "\n",
       "function hideSettings(event){\n",
       "    document.getElementById('settings_1').style.visibility = 'hidden';\n",
       "    document.getElementById('showSettingsButton_1').style.visibility = 'visible';\n",
       "    document.getElementById('hideSettingsButton_1').style.visibility = 'hidden';\n",
       "    settingsShown = false;\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "var pos = 150* Math.PI;\n",
       "\n",
       "function updateFactor() {\n",
       "    pos++;\n",
       "    return Math.sin(.01*pos)+1;\n",
       "}\n",
       "\n",
       "// ------------------------ FOLDING ------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "// rotate point p around axis defined by points p1 and p2 by given angle\n",
       "function rotate(p, p1, p2, angle ){   \n",
       "    angle = -angle;\n",
       "    var x = p.x, y = p.y, z = p.z, \n",
       "    a = p1.x, b = p1.y, c = p1.z, \n",
       "    u = p2.x-p1.x, v = p2.y-p1.y, w = p2.z-p1.z;\n",
       "    var result = [];\n",
       "    var L = u*u + v*v + w*w;\n",
       "    var sqrt = Math.sqrt;\n",
       "    var cos = Math.cos;\n",
       "    var sin = Math.sin;\n",
       "\n",
       "    result[0] = ((a*(v*v+w*w)-u*(b*v+c*w-u*x-v*y-w*z))*(1-cos(angle))+L*x*cos(angle)+sqrt(L)*(-c*v+b*w-w*y+v*z)*sin(angle))/L;\n",
       "    result[1] = ((b*(u*u+w*w)-v*(a*u+c*w-u*x-v*y-w*z))*(1-cos(angle))+L*y*cos(angle)+sqrt(L)*(c*u-a*w+w*x-u*z)*sin(angle))/L;\n",
       "    result[2] = ((c*(u*u+v*v)-w*(a*u+b*v-u*x-v*y-w*z))*(1-cos(angle))+L*z*cos(angle)+sqrt(L)*(-b*u+a*v-v*x+u*y)*sin(angle))/L;\n",
       "\n",
       "    return result;\n",
       "}\n",
       "\n",
       "var fold = function(event){\n",
       "    var obj = foldables[Number(event.currentTarget.name)];\n",
       "    var foldvalue = Number(event.currentTarget.value);\n",
       "    var scale = foldvalue - obj.userData.oldscale;\n",
       "\n",
       "    for (var j=0; j<obj.userData.axes.length; j++) {\n",
       "        rotateVertices(obj, j, scale);\n",
       "    }\n",
       "    update(obj);\n",
       "    obj.userData.oldscale += scale;\n",
       "    lookAtBarycenter(obj);\n",
       "}\n",
       "\n",
       "function lookAtBarycenter(obj){\n",
       "    control.target = barycenter(obj);\n",
       "}\n",
       "\n",
       "function barycenter(obj) {\n",
       "    var center = new THREE.Vector3(0,0,0);\n",
       "    var points = obj.userData.points;\n",
       "    for (var i=0; i<points.length; i++){\n",
       "        center.add(points[i].vector);\n",
       "    }\n",
       "    center.divideScalar(points.length);\n",
       "    return center;\n",
       "}\n",
       "\n",
       "function rotateVertices(obj, edge, scale) {\n",
       "    var axes = obj.userData.axes;\n",
       "    var subtrees = obj.userData.subtrees;\n",
       "    var points = obj.userData.points;\n",
       "    var angles = obj.userData.angles;\n",
       "    if (edge < axes.length){\n",
       "        for (var j=0; j<subtrees[edge].length; j++){\n",
       "            var rotP = rotate(points[subtrees[edge][j]].vector, points[axes[edge][0]].vector,points[axes[edge][1]].vector, scale * (Math.PI - angles[edge]));\n",
       "            points[subtrees[edge][j]].set(rotP[0],rotP[1],rotP[2]);\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function update(obj) {\n",
       "   updateFacesPosition(obj);\n",
       "   updateEdgesPosition(obj);\n",
       "}\n",
       "\n",
       "if (foldables.length) {\n",
       "    var settings = document.getElementById('settings_1');\n",
       "    var foldDiv = document.createElement('div');\n",
       "    foldDiv.id = 'fold_1';\n",
       "    var title = document.createElement('strong');\n",
       "    title.innerHTML = 'Fold';\n",
       "    foldDiv.appendChild(title);\n",
       "    foldDiv.className = 'group';\n",
       "    for (var i=0; i<foldables.length; i++) {\n",
       "        var range = document.createElement('input');\n",
       "        range.type = 'range';\n",
       "        range.min = 0;\n",
       "        range.max = 1;\n",
       "        range.value = 0;\n",
       "        range.step = 0.001;\n",
       "        range.name = String(i);\n",
       "        range.oninput = fold;\n",
       "        foldDiv.appendChild(range);\n",
       "    }\n",
       "    lookAtBarycenter(foldables[0]);\n",
       "    settings.insertBefore(foldDiv,settings.childNodes[0]);\n",
       "}\n",
       "\n",
       "    \n",
       "// ---------------------- EXPLOSION ------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "if (explodableModel) {\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        obj = scene.children[i];\n",
       "        if ( obj.userData.explodable ) {\n",
       "            computeCentroid(obj);\n",
       "        }\n",
       "    }\n",
       "    document.getElementById('explodeRange_1').oninput = triggerExplode;\n",
       "    document.getElementById('explodeCheckbox_1').onchange = triggerAutomaticExplode;\n",
       "    document.getElementById('explodingSpeedRange_1').oninput = setExplodingSpeed;\n",
       "}\n",
       "\n",
       "function computeCentroid(obj) {\n",
       "    centroid = new THREE.Vector3();\n",
       "    obj.userData.points.forEach(function(pmpoint) {\n",
       "        centroid.add(pmpoint.vector);\t\t\t\n",
       "    });\n",
       "    centroid.divideScalar(obj.userData.points.length);\n",
       "    obj.userData.centroid = centroid;\n",
       "}\n",
       "\n",
       "function explode(factor) {\n",
       "    for (var i=0; i<scene.children.length; i++) {\n",
       "        var obj = scene.children[i];\n",
       "        if (obj.userData.hasOwnProperty(\"centroid\")) { \n",
       "            var c = obj.userData.centroid;\n",
       "            obj.position.set(c.x*factor, c.y*factor, c.z*factor);\n",
       "        }\n",
       "    }\t\n",
       "}\n",
       "\n",
       "function triggerExplode(event){\n",
       "    explodeScale = Number(event.currentTarget.value);\n",
       "    explode(explodeScale);\n",
       "}\n",
       "\n",
       "function setExplodingSpeed(event){\n",
       "    explodingSpeed = Number(event.currentTarget.value);\n",
       "}\n",
       "\n",
       "function triggerAutomaticExplode(event){\n",
       "    if (event.currentTarget.checked){\n",
       "        startExploding();\n",
       "    } else {\n",
       "        clearIntervals();\n",
       "    }\t\n",
       "}\n",
       "\n",
       "function startExploding(){\n",
       "    intervals.push(setInterval(explodingInterval, 25));\n",
       "}\n",
       "\n",
       "\n",
       "function explodingInterval(){\n",
       "    explodeScale += explodingSpeed;\n",
       "    if (explodeScale <= 6){ \n",
       "        explode(explodeScale);\n",
       "    }\n",
       "    else{\n",
       "        explode(6);\n",
       "        explodeScale = 6;\n",
       "        clearIntervals();\n",
       "        timeouts.push(setTimeout(startUnexploding, 3000));\n",
       "    }\n",
       "    document.getElementById('explodeRange_1').value = explodeScale;\n",
       "}\n",
       "\n",
       "\n",
       "function startUnexploding(){\n",
       "    intervals.push(setInterval(unexplodingInterval, 25));\n",
       "}\n",
       "\n",
       "function unexplodingInterval(){\n",
       "    explodeScale -= explodingSpeed;\n",
       "    if (explodeScale >= 0){\t\n",
       "        explode(explodeScale);\n",
       "    }\n",
       "    else {\n",
       "        explode(0);\n",
       "        explodeScale = 0;\n",
       "        clearIntervals();\n",
       "        timeouts.push(setTimeout(startExploding, 3000));\n",
       "    }\n",
       "    document.getElementById('explodeRange_1').value = explodeScale;\n",
       "}\n",
       "\n",
       "function clearIntervals(){\n",
       "    intervals.forEach(function(interval){\n",
       "        clearInterval(interval);\n",
       "    });\n",
       "    intervals = [];\n",
       "    timeouts.forEach(function(timeout){\n",
       "        clearTimeout(timeout);\n",
       "    });\n",
       "    timeouts = [];\n",
       "}\n",
       "\n",
       "// ---------------------- DISPLAY --------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "const objectTypeInnerHTMLs = { points: \"Points\", pointlabels: \"Point labels\", lines: \"Edges\", edgelabels: \"Edge labels\", faces: \"Faces\", arrowheads: \"Arrow heads\" };\n",
       "const objectTypeVisible = {};\n",
       "Object.assign(objectTypeVisible,modelContains);\n",
       "const sortedObjectTypeKeys = Object.keys(objectTypeInnerHTMLs).sort();\n",
       "const shownObjectTypesList = document.getElementById('shownObjectTypesList_1');\n",
       "\n",
       "function setVisibility(bool,objname) {\n",
       "    for (var i=0; i<scene.children.length; i++){\n",
       "        var obj = scene.children[i].getObjectByName(objname);\n",
       "        if (obj) {\n",
       "            obj.visible = bool;\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "function toggleObjectTypeVisibility(event){\n",
       "    var name = event.currentTarget.name;\n",
       "    var checked = event.currentTarget.checked;\n",
       "    objectTypeVisible[name] = checked;\n",
       "    setVisibility(checked,name);\n",
       "}\n",
       "\n",
       "for (var i=0; i<sortedObjectTypeKeys.length; i++){\n",
       "    var key = sortedObjectTypeKeys[i];\n",
       "    if (modelContains[key]) {\n",
       "        var objTypeNode = document.createElement('span');\n",
       "        objTypeNode.innerHTML = objectTypeInnerHTMLs[key] + '<br>';\n",
       "        var checkbox = document.createElement('input');\n",
       "        checkbox.type = 'checkbox';\n",
       "        checkbox.checked = true;\n",
       "        checkbox.name = key;\n",
       "        checkbox.onchange = toggleObjectTypeVisibility;\n",
       "        shownObjectTypesList.appendChild(checkbox);\n",
       "        shownObjectTypesList.appendChild(objTypeNode);\n",
       "    }\n",
       "}\n",
       "\n",
       "// ------------------------------------------------------\n",
       "\n",
       "function toggleObjectVisibility(event){\n",
       "    var nr = Number(event.currentTarget.name);\n",
       "    scene.children[nr].visible = event.currentTarget.checked;\n",
       "}\n",
       "\n",
       "// append checkboxes for displaying or hiding objects\n",
       "var shownObjectsList = document.getElementById('shownObjectsList_1');\n",
       "for (var i=0; i<scene.children.length; i++){\n",
       "    obj = scene.children[i];\n",
       "    var objNode = document.createElement('span');\n",
       "    objNode.innerHTML = obj.name + '<br>';\n",
       "    var checkbox = document.createElement('input');\n",
       "    checkbox.type = 'checkbox';\n",
       "    checkbox.checked = true;\n",
       "    checkbox.name = String(i);\n",
       "    checkbox.onchange = toggleObjectVisibility;\n",
       "    shownObjectsList.appendChild(checkbox);\n",
       "    shownObjectsList.appendChild(objNode);\n",
       "}\n",
       "\n",
       "// ---------------------- SVG ------------------------------------------------------\n",
       "// ---------------------------------------------------------------------------------\n",
       "\n",
       "function takeSvgScreenshot() {\n",
       "    if (objectTypeVisible[\"pointlabels\"]) {\n",
       "        setVisibility(false,\"pointlabels\");\n",
       "    }\n",
       "    if (objectTypeVisible[\"edgelabels\"]) {\n",
       "        setVisibility(false,\"edgelabels\");\n",
       "    }\n",
       "    svgRenderer.render(scene,camera);\n",
       "    svgElement = XMLS.serializeToString(svgRenderer.domElement);\n",
       "    \n",
       "    if (objectTypeVisible[\"pointlabels\"]) {\n",
       "        setVisibility(true,\"pointlabels\");\n",
       "    }\n",
       "    if (objectTypeVisible[\"edgelabels\"]) {\n",
       "        setVisibility(true,\"edgelabels\");\n",
       "    }\n",
       "\n",
       "    if (document.getElementById('tab_1').checked){\n",
       "        //show in new tab\n",
       "        var myWindow = window.open(\"\",\"\");\n",
       "        myWindow.document.body.innerHTML = svgElement;\n",
       "    } else{\n",
       "        // download svg file \n",
       "        download(\"screenshot.svg\", svgElement);\n",
       "    }\n",
       "}\n",
       "\n",
       "function download(filename, text) {\n",
       "    var element = document.createElement('a');\n",
       "    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));\n",
       "    element.setAttribute('download', filename);\n",
       "\n",
       "    element.style.display = 'none';\n",
       "    document.body.appendChild(element);\n",
       "\n",
       "    element.click();\n",
       "\n",
       "    document.body.removeChild(element);\n",
       "}\n",
       "\n",
       "\n",
       "document.getElementById('transparencyRange_1').oninput = changeTransparency;\n",
       "document.getElementById('changeRotationX_1').onchange = changeRotationX;\n",
       "document.getElementById('changeRotationY_1').onchange = changeRotationY;\n",
       "document.getElementById('changeRotationZ_1').onchange = changeRotationZ;\n",
       "document.getElementById('resetButton_1').onclick = resetScene;\n",
       "document.getElementById('rotationSpeedRange_1').oninput = changeRotationSpeedFactor;\n",
       "document.getElementById('takeScreenshot_1').onclick = takeSvgScreenshot;\n",
       "document.getElementById('showSettingsButton_1').onclick = showSettings;\n",
       "document.getElementById('hideSettingsButton_1').onclick = hideSettings;\n",
       "\n",
       "\n",
       "// ------------------ SHORTCUTS --------------------------------------------\n",
       "// -------------------------------------------------------------------------\n",
       "\n",
       "/**\n",
       " * http://www.openjs.com/scripts/events/keyboard_shortcuts/\n",
       " * Version : 2.01.B\n",
       " * By Binny V A\n",
       " * License : BSD\n",
       " */\n",
       "shortcut = {\n",
       "\t'all_shortcuts':{},//All the shortcuts are stored in this array\n",
       "\t'add': function(shortcut_combination,callback,opt) {\n",
       "\t\t//Provide a set of default options\n",
       "\t\tvar default_options = {\n",
       "\t\t\t'type':'keydown',\n",
       "\t\t\t'propagate':false,\n",
       "\t\t\t'disable_in_input':false,\n",
       "\t\t\t'target':document,\n",
       "\t\t\t'keycode':false\n",
       "\t\t}\n",
       "\t\tif(!opt) opt = default_options;\n",
       "\t\telse {\n",
       "\t\t\tfor(var dfo in default_options) {\n",
       "\t\t\t\tif(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];\n",
       "\t\t\t}\n",
       "\t\t}\n",
       "\n",
       "\t\tvar ele = opt.target;\n",
       "\t\tif(typeof opt.target == 'string') ele = document.getElementById(opt.target);\n",
       "\t\tvar ths = this;\n",
       "\t\tshortcut_combination = shortcut_combination.toLowerCase();\n",
       "\n",
       "\t\t//The function to be called at keypress\n",
       "\t\tvar func = function(e) {\n",
       "\t\t\te = e || window.event;\n",
       "\t\t\t\n",
       "\t\t\tif(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields\n",
       "\t\t\t\tvar element;\n",
       "\t\t\t\tif(e.target) element=e.target;\n",
       "\t\t\t\telse if(e.srcElement) element=e.srcElement;\n",
       "\t\t\t\tif(element.nodeType==3) element=element.parentNode;\n",
       "\n",
       "\t\t\t\tif(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;\n",
       "\t\t\t}\n",
       "\t\n",
       "\t\t\t//Find Which key is pressed\n",
       "\t\t\tif (e.keyCode) code = e.keyCode;\n",
       "\t\t\telse if (e.which) code = e.which;\n",
       "\t\t\tvar character = String.fromCharCode(code).toLowerCase();\n",
       "\t\t\t\n",
       "\t\t\tif(code == 188) character=\",\"; //If the user presses , when the type is onkeydown\n",
       "\t\t\tif(code == 190) character=\".\"; //If the user presses , when the type is onkeydown\n",
       "\n",
       "\t\t\tvar keys = shortcut_combination.split(\"+\");\n",
       "\t\t\t//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked\n",
       "\t\t\tvar kp = 0;\n",
       "\t\t\t\n",
       "\t\t\t//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken\n",
       "\t\t\tvar shift_nums = {\n",
       "\t\t\t\t\"`\":\"~\",\n",
       "\t\t\t\t\"1\":\"!\",\n",
       "\t\t\t\t\"2\":\"@\",\n",
       "\t\t\t\t\"3\":\"#\",\n",
       "\t\t\t\t\"4\":\"$\",\n",
       "\t\t\t\t\"5\":\"%\",\n",
       "\t\t\t\t\"6\":\"^\",\n",
       "\t\t\t\t\"7\":\"&\",\n",
       "\t\t\t\t\"8\":\"*\",\n",
       "\t\t\t\t\"9\":\"(\",\n",
       "\t\t\t\t\"0\":\")\",\n",
       "\t\t\t\t\"-\":\"_\",\n",
       "\t\t\t\t\"=\":\"+\",\n",
       "\t\t\t\t\";\":\":\",\n",
       "\t\t\t\t\"'\":\"\\\"\",\n",
       "\t\t\t\t\",\":\"<\",\n",
       "\t\t\t\t\".\":\">\",\n",
       "\t\t\t\t\"/\":\"?\",\n",
       "\t\t\t\t\"\\\\\":\"|\"\n",
       "\t\t\t}\n",
       "\t\t\t//Special Keys - and their codes\n",
       "\t\t\tvar special_keys = {\n",
       "\t\t\t\t'esc':27,\n",
       "\t\t\t\t'escape':27,\n",
       "\t\t\t\t'tab':9,\n",
       "\t\t\t\t'space':32,\n",
       "\t\t\t\t'return':13,\n",
       "\t\t\t\t'enter':13,\n",
       "\t\t\t\t'backspace':8,\n",
       "\t\n",
       "\t\t\t\t'scrolllock':145,\n",
       "\t\t\t\t'scroll_lock':145,\n",
       "\t\t\t\t'scroll':145,\n",
       "\t\t\t\t'capslock':20,\n",
       "\t\t\t\t'caps_lock':20,\n",
       "\t\t\t\t'caps':20,\n",
       "\t\t\t\t'numlock':144,\n",
       "\t\t\t\t'num_lock':144,\n",
       "\t\t\t\t'num':144,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'pause':19,\n",
       "\t\t\t\t'break':19,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'insert':45,\n",
       "\t\t\t\t'home':36,\n",
       "\t\t\t\t'delete':46,\n",
       "\t\t\t\t'end':35,\n",
       "\t\t\t\t\n",
       "\t\t\t\t'pageup':33,\n",
       "\t\t\t\t'page_up':33,\n",
       "\t\t\t\t'pu':33,\n",
       "\t\n",
       "\t\t\t\t'pagedown':34,\n",
       "\t\t\t\t'page_down':34,\n",
       "\t\t\t\t'pd':34,\n",
       "\t\n",
       "\t\t\t\t'left':37,\n",
       "\t\t\t\t'up':38,\n",
       "\t\t\t\t'right':39,\n",
       "\t\t\t\t'down':40,\n",
       "\t\n",
       "\t\t\t\t'f1':112,\n",
       "\t\t\t\t'f2':113,\n",
       "\t\t\t\t'f3':114,\n",
       "\t\t\t\t'f4':115,\n",
       "\t\t\t\t'f5':116,\n",
       "\t\t\t\t'f6':117,\n",
       "\t\t\t\t'f7':118,\n",
       "\t\t\t\t'f8':119,\n",
       "\t\t\t\t'f9':120,\n",
       "\t\t\t\t'f10':121,\n",
       "\t\t\t\t'f11':122,\n",
       "\t\t\t\t'f12':123\n",
       "\t\t\t}\n",
       "\t\n",
       "\t\t\tvar modifiers = { \n",
       "\t\t\t\tshift: { wanted:false, pressed:false},\n",
       "\t\t\t\tctrl : { wanted:false, pressed:false},\n",
       "\t\t\t\talt  : { wanted:false, pressed:false},\n",
       "\t\t\t\tmeta : { wanted:false, pressed:false}\t//Meta is Mac specific\n",
       "\t\t\t};\n",
       "                        \n",
       "\t\t\tif(e.ctrlKey)\tmodifiers.ctrl.pressed = true;\n",
       "\t\t\tif(e.shiftKey)\tmodifiers.shift.pressed = true;\n",
       "\t\t\tif(e.altKey)\tmodifiers.alt.pressed = true;\n",
       "\t\t\tif(e.metaKey)   modifiers.meta.pressed = true;\n",
       "                        \n",
       "\t\t\tfor(var i=0; k=keys[i],i<keys.length; i++) {\n",
       "\t\t\t\t//Modifiers\n",
       "\t\t\t\tif(k == 'ctrl' || k == 'control') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.ctrl.wanted = true;\n",
       "\n",
       "\t\t\t\t} else if(k == 'shift') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.shift.wanted = true;\n",
       "\n",
       "\t\t\t\t} else if(k == 'alt') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.alt.wanted = true;\n",
       "\t\t\t\t} else if(k == 'meta') {\n",
       "\t\t\t\t\tkp++;\n",
       "\t\t\t\t\tmodifiers.meta.wanted = true;\n",
       "\t\t\t\t} else if(k.length > 1) { //If it is a special key\n",
       "\t\t\t\t\tif(special_keys[k] == code) kp++;\n",
       "\t\t\t\t\t\n",
       "\t\t\t\t} else if(opt['keycode']) {\n",
       "\t\t\t\t\tif(opt['keycode'] == code) kp++;\n",
       "\n",
       "\t\t\t\t} else { //The special keys did not match\n",
       "\t\t\t\t\tif(character == k) kp++;\n",
       "\t\t\t\t\telse {\n",
       "\t\t\t\t\t\tif(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase\n",
       "\t\t\t\t\t\t\tcharacter = shift_nums[character]; \n",
       "\t\t\t\t\t\t\tif(character == k) kp++;\n",
       "\t\t\t\t\t\t}\n",
       "\t\t\t\t\t}\n",
       "\t\t\t\t}\n",
       "\t\t\t}\n",
       "\t\t\t\n",
       "\t\t\tif(kp == keys.length && \n",
       "\t\t\t\t\t\tmodifiers.ctrl.pressed == modifiers.ctrl.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.shift.pressed == modifiers.shift.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.alt.pressed == modifiers.alt.wanted &&\n",
       "\t\t\t\t\t\tmodifiers.meta.pressed == modifiers.meta.wanted) {\n",
       "\t\t\t\tcallback(e);\n",
       "\t\n",
       "\t\t\t\tif(!opt['propagate']) { //Stop the event\n",
       "\t\t\t\t\t//e.cancelBubble is supported by IE - this will kill the bubbling process.\n",
       "\t\t\t\t\te.cancelBubble = true;\n",
       "\t\t\t\t\te.returnValue = false;\n",
       "\t\n",
       "\t\t\t\t\t//e.stopPropagation works in Firefox.\n",
       "\t\t\t\t\tif (e.stopPropagation) {\n",
       "\t\t\t\t\t\te.stopPropagation();\n",
       "\t\t\t\t\t\te.preventDefault();\n",
       "\t\t\t\t\t}\n",
       "\t\t\t\t\treturn false;\n",
       "\t\t\t\t}\n",
       "\t\t\t}\n",
       "\t\t}\n",
       "\t\tthis.all_shortcuts[shortcut_combination] = {\n",
       "\t\t\t'callback':func, \n",
       "\t\t\t'target':ele, \n",
       "\t\t\t'event': opt['type']\n",
       "\t\t};\n",
       "\t\t//Attach the function with the event\n",
       "\t\tif(ele.addEventListener) ele.addEventListener(opt['type'], func, false);\n",
       "\t\telse if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);\n",
       "\t\telse ele['on'+opt['type']] = func;\n",
       "\t},\n",
       "\n",
       "\t//Remove the shortcut - just specify the shortcut and I will remove the binding\n",
       "\t'remove':function(shortcut_combination) {\n",
       "\t\tshortcut_combination = shortcut_combination.toLowerCase();\n",
       "\t\tvar binding = this.all_shortcuts[shortcut_combination];\n",
       "\t\tdelete(this.all_shortcuts[shortcut_combination])\n",
       "\t\tif(!binding) return;\n",
       "\t\tvar type = binding['event'];\n",
       "\t\tvar ele = binding['target'];\n",
       "\t\tvar callback = binding['callback'];\n",
       "\n",
       "\t\tif(ele.detachEvent) ele.detachEvent('on'+type, callback);\n",
       "\t\telse if(ele.removeEventListener) ele.removeEventListener(type, callback, false);\n",
       "\t\telse ele['on'+type] = false;\n",
       "\t}\n",
       "}\n",
       "\n",
       "shortcut.add(\"Alt+Left\",function() {\n",
       "\tvar event = new Event('click');\n",
       "\tif (settingsShown){\n",
       "\t\tdocument.getElementById('hideSettingsButton_1').dispatchEvent(event);\n",
       "\t} else {\n",
       "\t\tdocument.getElementById('showSettingsButton_1').dispatchEvent(event);\n",
       "\t}\n",
       "});\n",
       "\n",
       "\n",
       "// COMMON_CODE_BLOCK_END\n",
       "\n",
       "});});\n",
       "      </script>\n",
       "   </body>\n",
       "</html>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#$m = new Matrix<Rational>([[1,-5,-5,-5],[1,5,5,5]]);\n",
    "#$mf = polytope::bounding_box_facets($m);\n",
    "$mf = polytope::scale(polytope::cube(3),5)->FACETS;\n",
    "compose($l->VISUAL(VertexStyle=>\"hidden\",BoundingFacets=>$mf), $div->VISUAL(VertexStyle=>\"hidden\",EdgeColor=>\"red\",BoundingFacets=>$mf));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Creation functions for commonly used tropical cycles\n",
    "\n",
    "##### Uniform linear spaces\n",
    "\n",
    "As a special case of tropical linear spaces, one can create the space associated to the uniform matroid (with trivial valuation) as `uniform_linear_space<Addition>(n,k; w=1)` where \n",
    "* `Addition` is either `Min` or `Max`\n",
    "* `n` is the dimension of the ambient tropical projective torus.\n",
    "* `k` is the (projective) dimension of the linear space.\n",
    "* `w` is the (global) weight of the space. By default, this is 1.\n",
    "In particular, this gives the matroid fan of the uniform matroid $U_{n+1,k+1}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### True linear spaces\n",
    "\n",
    "There are creation function for cycles that are supported on an affine linear space. In the special case, that a cycle is the whole projective torus, this can be created via `projective_torus<Addition>(n;w=1)` where n is the (projective) dimension and w is an integer weight.\n",
    "\n",
    "If the cycle is given by a basis of the lineality space and a translation vector, one can use `affine_linear_space<Addition>(matrix; vector, w =1)`.\n",
    "\n",
    "Note that both the generators of the lineality space in the matrix and the translation vector should be given in tropical homogeneous coordinates, but WITHOUT a leading coordinate. If the translation vector is not given, it is equal to 0. The weight w is equal to 1 by default."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Halfspace subdivision\n",
    "\n",
    "`halfspace_subdivision<Addition>(a,g;w=1)` creates the subdivision of the projective torus along the (true) hyperplane defined by the equation $g\\cdot x = a$, where $a$ is a Rational and $g$ is a Vector.\n",
    "Note that the sum over all entries in $g$ must be 0 for this to be well-defined over tropical homogeneous coordinates."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Matroid fans\n",
    "\n",
    "A-tint uses the algorithms developped by Felipe Rincón to compute matroidal fans.\n",
    "The original algorithm was developed for matrix matroids but has been adapted here to also work on general matroids.\n",
    "You compute a matroidal fan via `$m = matroid_fan<Addition>(m)`, where `m` is either a Matroid object or a matrix, whose column matroid is then considered."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Operations on tropical varieties\n",
    "\n",
    "##### Computing the cartesian product\n",
    "\n",
    "The function `cartesian_product` computes the cartesian product of an arbitrary, comma-separated list of tropical cycles using the same tropical addition, e.g. the product of two uniform linear spaces could be computed via:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "$p = cartesian_product(uniform_linear_space<Max>(3,2), uniform_linear_space<Max>(3,1));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Computing the skeleton\n",
    "\n",
    "This is actually an operation on polyhedral complexes, since taking the skeleton forgets the weights. The function `skeleton_complex(cycle,k,preservesRays)` computes the k-dimensional skeleton of fan. The last argument is optional, by default false and should be set to true, if you are certain that all your rays remain in the skeleton (directional rays may disappear when taking the skeleton of a polyhedral complex). In this case, ray indices will be preserved. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Comparing complexes\n",
    "\n",
    "You can check if two polyhedral complexes are exactly the same, i.e. have the same rays, cones and weights up to reordering and equivalence of tropical coordinates, by calling the function `check_cycle_equality`. Note that this function will not recognize if two complex are equal up to subdivision. The function has an optional parameter, which is TRUE by default, that determines whether weights ought to be checked for equality as well. This will be ignored if any of the complexes does not have any weights."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Refining \n",
    "\n",
    "You can refine a weighted complex along any other complex containing it (as a set), using the function `intersect_container(X,Y)`. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Local computations\n",
    "\n",
    "a-tint has a mechanism to allow computations locally around a given set of cones:\n",
    "Each Cycle has a property LOCAL_RESTRICTION. This is an IncidenceMatrix (or list of sets of ray indices). Each of these sets of ray indices is supposed to describe a cone of the complex - though not necessarily a maximal one. \n",
    "\n",
    "If you define a complex with this property, then all computations will only be done \"around\" these cones. E.g. a-tint will only recognize those codimension one faces that contain one of the cones described in LOCAL_RESTRICTION.\n",
    "\n",
    "**Note:** It is important, that all maximal cones of a restricted complex contain one of the LOCAL_RESTRICTION cones.\n",
    "\n",
    "This way a bounded complex can also be made \"balanced\": "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$w = new Cycle<Max>(VERTICES=>thomog([[1,0],[1,-1],[1,1]]),MAXIMAL_POLYTOPES=>[[0,1],[0,2]],WEIGHTS=>[1,1],LOCAL_RESTRICTION=>[[0]]);\n",
    "print $w->IS_BALANCED;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above example describes the bounded line segment $[-1,1] \\in \\mathbb R$, subdivided at 0. Since we restrict ourselves locally to the vertex 0, the outer codimension one faces are not detected by a-tint and the complex is balanced.\n",
    "\n",
    "This can improve computation speed, e.g. when one is only interested in the weight of a divisor at a certain cone.\n",
    "\n",
    "There are some convenience functions to create a local variety from a global one:\n",
    "* `local_restrict(X,C)`: Takes a variety and localizes at a set of cones C. It removes all maximal cones that do not contain one of these cones. Here, C is an IncidenceMatrix, i.e. it is of the same form as e.g. MAXIMAL_POLYTOPES.\n",
    "* `local_vertex(X,r)`: Takes a variety and localizes at a ray/vertex, given by its row index r in VERTICES.\n",
    "* `local_codim_one(X,c)`: Takes a variety and localizes at a codimension one face, given by its row index in CODIMENSION_ONE_POLYTOPES.\n",
    "* `local_point(X,v)`: Takes a variety and refines it such that a given point v (in homog. coordinates, with leading coordinate) is in the polyhedral structure. Then it localizes at this point. This returns an error message if v is not actually in the complex.\n",
    "\n",
    "Some examples:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "$x = uniform_linear_space<Max>(3, 2);\n",
    "$x1 = local_restrict($x, new IncidenceMatrix([[0],[2,3]])); \n",
    "     #The tropical hyperplane, locally around the 0-th ray and the maximal cone spanned by rays 2 and 3.\n",
    "     #As a set this can be interpreted as the union of an open neighborhood of ray 0 and the interior of the maximal       \n",
    "     #cone <2,3>\n",
    "$x2 = local_vertex($x, 0); #An open neighborhood of ray 0.\n",
    "$x3 = local_codim_one($x, 0); #An open neighborhood of the codimension one face no. 0 (which is a ray)\n",
    "$x4 = local_point($x, new Vector<Rational>([1,0,1,1,0]));\n",
    "     #Refines the surface such that it contains the point (0,1,1,0), then takes an open neighborhood of that"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For details see the internal documentation of these functions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Delocalizing\n",
    "\n",
    "If you have a locally restricted complex and you would like to obtain the same complex without the LOCAL_RESTRICTION, you can call its user method delocalize(), e.g."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "$y = $x->delocalize();"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "polymake",
   "language": "polymake",
   "name": "polymake"
  },
  "language_info": {
   "codemirror_mode": "perl",
   "file_extension": ".pl",
   "mimetype": "text/x-polymake",
   "name": "polymake"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
