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

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
jplab committed Jul 23, 2019
1 parent a1e1a8f commit 302ec46
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,58 @@ def as_polyhedron(self):
parent = P.parent()
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]]
"""
from sage.geometry.polyhedron.constructor import Polyhedron

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'")
the_poly = self._polyhedron
br = the_poly.base_ring()
backend = the_poly.backend()
return Polyhedron(rays=normal_vectors, base_ring=br, backend=backend)

0 comments on commit 302ec46

Please sign in to comment.