Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting convex hull of a set of points and plotting the polygon

I'm trying to get the convex hull of a finite set of points, then plotting the polygon. If I just plot the polygon with the vertices directly, I don't get the vertices in the right order to make up a convex polygon (plots edges joining the wrong points). Then I found out about cyclic_sort_vertices_2d which I thought would sort the vertices into the right order, but that's giving me errors. I don't understand the meaning of the errors. Appreciate any help.

here's the relevant code:

hull = Polyhedron(vertices=thePoints);
hull.vertices();
cyclic_sort_vertices_2d(hull.vertices());

And I have this import line at the top of my code for cyclic sort:

from sage.geometry.polyhedron.plot import cyclic_sort_vertices_2d;

Here's my output:

 (A vertex at (9464.0, 10816.0), A vertex at (8736.0, 7735.0), A vertex at (7904.0, 8736.0), A vertex at (11088.0, 5607.0), A vertex at (15552.0, 6480.0), A vertex at (8160.0, 9248.0), A vertex at (8568.0, 9792.0), A vertex at (11076.0, 10140.0), A vertex at (12852.0, 5355.0))

And errors:

Error in lines 28-30
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/plot.py", line 245, in cyclic_sort_vertices_2d
    adjacency_matrix = Vlist[0].polyhedron().vertex_adjacency_matrix()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 1847, in vertex_adjacency_matrix
    return self._vertex_adjacency_matrix()
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 312, in _vertex_adjacency_matrix
    face_lattice = self.face_lattice()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 3172, in face_lattice
    face_constructor=face_constructor, required_atoms=atoms_vertices)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/hasse_diagram.py", line 182, in Hasse_diagram_from_incidences
    for coatom, atoms in enumerate(coatom_to_atoms)]
KeyError: (frozenset([]), frozenset([0]))

Getting convex hull of a set of points and plotting the polygon

I'm using sagemath cloud.

I'm trying to get the convex hull of a finite set of points, then plotting the polygon. If I just plot the polygon with the vertices directly, I don't get the vertices in the right order to make up a convex polygon (plots edges joining the wrong points). Then I found out about cyclic_sort_vertices_2d which I thought would sort the vertices into the right order, but that's giving me errors. I don't understand the meaning of the errors. Appreciate any help.

here's the relevant code:

hull = Polyhedron(vertices=thePoints);
hull.vertices();
cyclic_sort_vertices_2d(hull.vertices());

And I have this import line at the top of my code for cyclic sort:

from sage.geometry.polyhedron.plot import cyclic_sort_vertices_2d;

Here's my output:

 (A vertex at (9464.0, 10816.0), A vertex at (8736.0, 7735.0), A vertex at (7904.0, 8736.0), A vertex at (11088.0, 5607.0), A vertex at (15552.0, 6480.0), A vertex at (8160.0, 9248.0), A vertex at (8568.0, 9792.0), A vertex at (11076.0, 10140.0), A vertex at (12852.0, 5355.0))

And errors:

Error in lines 28-30
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/plot.py", line 245, in cyclic_sort_vertices_2d
    adjacency_matrix = Vlist[0].polyhedron().vertex_adjacency_matrix()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 1847, in vertex_adjacency_matrix
    return self._vertex_adjacency_matrix()
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 312, in _vertex_adjacency_matrix
    face_lattice = self.face_lattice()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 3172, in face_lattice
    face_constructor=face_constructor, required_atoms=atoms_vertices)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/hasse_diagram.py", line 182, in Hasse_diagram_from_incidences
    for coatom, atoms in enumerate(coatom_to_atoms)]
KeyError: (frozenset([]), frozenset([0]))
click to hide/show revision 3
retagged

Getting convex hull of a set of points and plotting the polygon

I'm using sagemath cloud.

I'm trying to get the convex hull of a finite set of points, then plotting the polygon. If I just plot the polygon with the vertices directly, I don't get the vertices in the right order to make up a convex polygon (plots edges joining the wrong points). Then I found out about cyclic_sort_vertices_2d which I thought would sort the vertices into the right order, but that's giving me errors. I don't understand the meaning of the errors. Appreciate any help.

here's the relevant code:

hull = Polyhedron(vertices=thePoints);
hull.vertices();
cyclic_sort_vertices_2d(hull.vertices());

And I have this import line at the top of my code for cyclic sort:

from sage.geometry.polyhedron.plot import cyclic_sort_vertices_2d;

Here's my output:

 (A vertex at (9464.0, 10816.0), A vertex at (8736.0, 7735.0), A vertex at (7904.0, 8736.0), A vertex at (11088.0, 5607.0), A vertex at (15552.0, 6480.0), A vertex at (8160.0, 9248.0), A vertex at (8568.0, 9792.0), A vertex at (11076.0, 10140.0), A vertex at (12852.0, 5355.0))

And errors:

Error in lines 28-30
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/plot.py", line 245, in cyclic_sort_vertices_2d
    adjacency_matrix = Vlist[0].polyhedron().vertex_adjacency_matrix()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 1847, in vertex_adjacency_matrix
    return self._vertex_adjacency_matrix()
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 312, in _vertex_adjacency_matrix
    face_lattice = self.face_lattice()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 3172, in face_lattice
    face_constructor=face_constructor, required_atoms=atoms_vertices)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/hasse_diagram.py", line 182, in Hasse_diagram_from_incidences
    for coatom, atoms in enumerate(coatom_to_atoms)]
KeyError: (frozenset([]), frozenset([0]))