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
Changed to use parent

fixed tests

reverted changes on truncations
  • Loading branch information
jplab committed Jan 31, 2020
1 parent 2cbd93e commit 2f114d8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4640,8 +4640,7 @@ def face_truncation(self, face, linear_coefficients=None, cut_frac=None):

B = - normal_vector * (face_vertices[0].vector())

linear_evaluation = set(-normal_vector * (v.vector()) for v in
self.vertices())
linear_evaluation = set(-normal_vector * (v.vector()) for v in self.vertices())

if B == max(linear_evaluation):
C = max(linear_evaluation.difference(set([B])))
Expand Down
52 changes: 52 additions & 0 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,55 @@ 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 2f114d8

Please sign in to comment.