Skip to content

Commit

Permalink
Trac #29125: is_inscribed depends on order of vertices
Browse files Browse the repository at this point in the history
Currently the inscription test for polyhedra depends on the order of
vertices:

{{{
sage: Polyhedron(vertices=[[-2,-1], [-2,1], [0,-1],
[0,1]]).is_inscribed()
True
sage: P = Polyhedron(vertices=[[-2,-1], [-2,1], [0,-1], [0,1]],
backend='field')
sage: P.is_inscribed()
False
sage: V = P.Vrepresentation()
sage: H = P.Hrepresentation()
sage: parent = P.parent()
sage: dic = {True: 0, False: 0}
sage: for V1 in Permutations(V):
....:     P1 = parent._element_constructor_(
....:         [V1, [], []], [H, []], Vrep_minimal=True,
Hrep_minimal=True)
....:     dic[P1.is_inscribed()] += 1
....:
sage: dic
{True: 18, False: 6}
}}}

The algorithm constructs a sphere around `dim + 1` vertices in general
position. The circumcenter is computed up to sign. Then, one vertex is
taken to determine, which sign to choose. However, up to `dim` vertices
might lie on the intersection of both spheres.

We fix this by checking distance from the circumcenter for all vertices
of that simplex.

URL: https://trac.sagemath.org/29125
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Jean-Philippe Labbé
  • Loading branch information
Release Manager committed Feb 10, 2020
2 parents 3e754d7 + 3f9cc75 commit 6344f4f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,19 @@ def is_inscribed(self, certificate=False):
....: [+1, 0, 0, 0]])
sage: P.is_inscribed()
True
We check that :trac:`29125` is fixed::
sage: P = Polyhedron(vertices=[[-2,-1], [-2,1], [0,-1], [0,1]], backend='field')
sage: P.is_inscribed()
True
sage: V = P.Vrepresentation()
sage: H = P.Hrepresentation()
sage: parent = P.parent()
sage: for V1 in Permutations(V):
....: P1 = parent._element_constructor_(
....: [V1, [], []], [H, []], Vrep_minimal=True, Hrep_minimal=True)
....: assert P1.is_inscribed()
"""

if not self.is_compact():
Expand Down Expand Up @@ -2895,8 +2908,8 @@ def is_inscribed(self, certificate=False):
squared_circumradius = (sum(m**2 for m in minors) - 4 * a * c) / (4*a**2)

# Checking if the circumcenter has the correct sign
test_vector = vertex.vector() - circumcenter
if sum(i**2 for i in test_vector) != squared_circumradius:
if not all(sum(i**2 for i in v.vector() - circumcenter) == squared_circumradius
for v in vertices if v in simplex_vertices):
circumcenter = - circumcenter

is_inscribed = all(sum(i**2 for i in v.vector() - circumcenter) == squared_circumradius
Expand Down

0 comments on commit 6344f4f

Please sign in to comment.