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

Commit

Permalink
Trac #27366: fixup (lines forgotten to commit in ~2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Feb 26, 2019
1 parent 2075a6b commit e9ed7ee
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6953,32 +6953,48 @@ def affine_hull(self, as_polyhedron=None, as_affine_map=False,
raise ValueError('The base ring needs to be extended; try with "extend=True"')
M = matrix(AA, M)
A = M.gram_schmidt(orthonormal=orthonormal)[0]
if as_polyhedron:
result['polyhedron'] = Polyhedron(
[A*vector(A.base_ring(), v) for v in Q.vertices()],
base_ring=A.base_ring())
if as_affine_map:
return linear_transformation(A, side='right'), -A*vector(A.base_ring(), self.vertices()[0])
return Polyhedron([A*vector(A.base_ring(), v) for v in Q.vertices()], base_ring=A.base_ring())

# translate one vertex to the origin
v0 = self.vertices()[0].vector()
gens = []
for v in self.vertices()[1:]:
gens.append(v.vector() - v0)
for r in self.rays():
gens.append(r.vector())
for l in self.lines():
gens.append(l.vector())

# Pick subset of coordinates to coordinatize the affine span
pivots = matrix(gens).pivots()

def pivot(indexed):
return [indexed[i] for i in pivots]

vertices = [pivot(_) for _ in self.vertices()]
rays = [pivot(_) for _ in self.rays()]
lines = [pivot(_) for _ in self.lines()]
if as_affine_map:
raise NotImplementedError('"as_affine_map=True" only works with "orthogonal=True" and "orthonormal=True"')
return Polyhedron(vertices=vertices, rays=rays, lines=lines, base_ring=self.base_ring())
result['linear_transformation'] = linear_transformation(A, side='right')
result['shift'] = -A*vector(A.base_ring(), self.vertices()[0])

else:
# translate one vertex to the origin
v0 = self.vertices()[0].vector()
gens = []
for v in self.vertices()[1:]:
gens.append(v.vector() - v0)
for r in self.rays():
gens.append(r.vector())
for l in self.lines():
gens.append(l.vector())

# Pick subset of coordinates to coordinatize the affine span
pivots = matrix(gens).pivots()

def pivot(indexed):
return [indexed[i] for i in pivots]

vertices = [pivot(_) for _ in self.vertices()]
rays = [pivot(_) for _ in self.rays()]
lines = [pivot(_) for _ in self.lines()]
if as_affine_map:
raise NotImplementedError('"as_affine_map=True" only works with "orthogonal=True" and "orthonormal=True"')

result['polyhedron'] = Polyhedron(
vertices=vertices, rays=rays, lines=lines,
base_ring=self.base_ring())

# assemble result
if return_all_data or (as_polyhedron and as_affine_map):
return result
elif as_affine_map:
return result['linear_transformation'], result['shift']
else:
return result['polyhedron']

def _polymake_init_(self):
"""
Expand Down

0 comments on commit e9ed7ee

Please sign in to comment.