Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
moved back the method
Browse files Browse the repository at this point in the history
  • Loading branch information
jplab committed Jan 31, 2020
1 parent 2f114d8 commit 4b803a1
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,58 @@ def as_polyhedron(self):
Vrep = (self.vertices(), self.rays(), self.lines())
return P.__class__(parent, Vrep, None)

@cached_method
def normal_cone(self, direction='outer'):
"""
Return the pointed polyhedral cone consisting of normal vectors to
hyperplanes supporting ``self``.
INPUT:
- ``direction`` -- string (default: ``'outer'``), the direction in
which to consider the normals. The other allowed option is
``'inner'``.
OUTPUT:
A polyhedron.
EXAMPLES::
sage: p = Polyhedron(vertices = [[1,2],[2,1],[-2,2],[-2,-2],[2,-2]])
sage: for v in p.faces(0):
....: vect = v.vertices()[0].vector()
....: nc = v.normal_cone().rays_list()
....: print("{} has outer normal cone spanned by {}".format(vect,nc))
....:
(-2, -2) has outer normal cone spanned by [[-1, 0], [0, -1]]
(-2, 2) has outer normal cone spanned by [[-1, 0], [0, 1]]
(1, 2) has outer normal cone spanned by [[0, 1], [1, 1]]
(2, -2) has outer normal cone spanned by [[0, -1], [1, 0]]
(2, 1) has outer normal cone spanned by [[1, 0], [1, 1]]
sage: for v in p.faces(0):
....: vect = v.vertices()[0].vector()
....: nc = v.normal_cone(direction='inner').rays_list()
....: print("{} has inner normal cone spanned by {}".format(vect,nc))
....:
(-2, -2) has inner normal cone spanned by [[0, 1], [1, 0]]
(-2, 2) has inner normal cone spanned by [[0, -1], [1, 0]]
(1, 2) has inner normal cone spanned by [[-1, -1], [0, -1]]
(2, -2) has inner normal cone spanned by [[-1, 0], [0, 1]]
(2, 1) has inner normal cone spanned by [[-1, -1], [-1, 0]]
"""
if direction == 'outer':
normal_vectors = [-facet.A() for facet in self.ambient_Hrepresentation()]
elif direction == 'inner':
normal_vectors = [facet.A() for facet in self.ambient_Hrepresentation()]
else:
raise ValueError("the direction should be either 'outer' or 'inner'")
parent = self.polyhedron().parent()
origin = parent.zero().vertices()[0].vector()
return parent.element_class(parent,[[origin], normal_vectors, []], None)

def combinatorial_face_to_polyhedral_face(polyhedron, combinatorial_face):
r"""
Convert a combinatorial face to a face of a polyhedron.
Expand Down Expand Up @@ -730,55 +782,3 @@ def combinatorial_face_to_polyhedral_face(polyhedron, combinatorial_face):
raise NotImplementedError("unknown backend")

return PolyhedronFace(polyhedron, V_indices, H_indices)

@cached_method
def normal_cone(self, direction='outer'):
"""
Return the pointed polyhedral cone consisting of normal vectors to
hyperplanes supporting ``self``.
INPUT:
- ``direction`` -- string (default: ``'outer'``), the direction in
which to consider the normals. The other allowed option is
``'inner'``.
OUTPUT:
A polyhedron.
EXAMPLES::
sage: p = Polyhedron(vertices = [[1,2],[2,1],[-2,2],[-2,-2],[2,-2]])
sage: for v in p.faces(0):
....: vect = v.vertices()[0].vector()
....: nc = v.normal_cone().rays_list()
....: print("{} has outer normal cone spanned by {}".format(vect,nc))
....:
(-2, -2) has outer normal cone spanned by [[-1, 0], [0, -1]]
(-2, 2) has outer normal cone spanned by [[-1, 0], [0, 1]]
(1, 2) has outer normal cone spanned by [[0, 1], [1, 1]]
(2, -2) has outer normal cone spanned by [[0, -1], [1, 0]]
(2, 1) has outer normal cone spanned by [[1, 0], [1, 1]]
sage: for v in p.faces(0):
....: vect = v.vertices()[0].vector()
....: nc = v.normal_cone(direction='inner').rays_list()
....: print("{} has inner normal cone spanned by {}".format(vect,nc))
....:
(-2, -2) has inner normal cone spanned by [[0, 1], [1, 0]]
(-2, 2) has inner normal cone spanned by [[0, -1], [1, 0]]
(1, 2) has inner normal cone spanned by [[-1, -1], [0, -1]]
(2, -2) has inner normal cone spanned by [[-1, 0], [0, 1]]
(2, 1) has inner normal cone spanned by [[-1, -1], [-1, 0]]
"""
if direction == 'outer':
normal_vectors = [-facet.A() for facet in self.ambient_Hrepresentation()]
elif direction == 'inner':
normal_vectors = [facet.A() for facet in self.ambient_Hrepresentation()]
else:
raise ValueError("the direction should be either 'outer' or 'inner'")
parent = self.polyhedron().parent()
origin = parent.zero().vertices()[0].vector()
return parent.element_class(parent,[[origin], normal_vectors, []], None)

0 comments on commit 4b803a1

Please sign in to comment.