From 8fec9230f7c3f5d3b36ee113d449fee316b26ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Labb=C3=A9?= Date: Thu, 27 Feb 2025 10:26:17 +0100 Subject: [PATCH 1/4] extract _front_back_facets method out of _tikz_3d_in_3d method in Projection of a polyhedron --- src/sage/geometry/polyhedron/plot.py | 87 +++++++++++++++++++--------- 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index a93690e345f..e54a228c131 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -1815,33 +1815,7 @@ def _tikz_3d_in_3d(self, view, angle, scale, edge_color, proj_vector = (rot**(-1))*vector(RDF, [0, 0, 1]) # First compute the back and front vertices and facets - facets = self.face_inequalities - front_facets = [] - back_facets = [] - for index_facet in range(len(facets)): - A = facets[index_facet].vector()[1:] - B = facets[index_facet].vector()[0] - if A*(2000*proj_vector)+B < 0: - front_facets += [index_facet] - else: - back_facets += [index_facet] - - vertices = list(self.parent_polyhedron.Vrep_generator()) - front_vertices = [] - for index_facet in front_facets: - A = facets[index_facet].vector()[1:] - B = facets[index_facet].vector()[0] - for v in self.points: - if A*self.coords[v]+B < 0.0005 and v not in front_vertices: - front_vertices += [v] - - back_vertices = [] - for index_facet in back_facets: - A = facets[index_facet].vector()[1:] - B = facets[index_facet].vector()[0] - for v in self.points: - if A * self.coords[v] + B < 0.0005 and v not in back_vertices: - back_vertices += [v] + front_facets, back_facets, front_vertices, back_vertices = self._front_back_facets(proj_vector) # Creates the nodes, coordinate and tag for every vertex of the polytope. # The tag is used to draw the front facets later on. @@ -1860,7 +1834,7 @@ def _tikz_3d_in_3d(self, view, angle, scale, edge_color, dict_drawing[vert] = node, coord, tag # Separate the edges between back and front - + facets = self.face_inequalities for index1, index2 in self.lines: # v1 = self.coords[index1] # v2 = self.coords[index2] @@ -1933,6 +1907,7 @@ def _tikz_3d_in_3d(self, view, angle, scale, edge_color, # Draw the facets in the front by going in cycles for every facet. tikz_pic += '%%\n%%\n%% Drawing the facets\n%%\n' + vertices = self.parent_polyhedron.Vrep_generator() vertex_to_index = {v: i for i, v in enumerate(vertices)} for index_facet in front_facets: cyclic_vert = cyclic_sort_vertices_2d(list(facets[index_facet].incident())) @@ -1955,3 +1930,59 @@ def _tikz_3d_in_3d(self, view, angle, scale, edge_color, tikz_pic += dict_drawing[v][0] tikz_pic += '%%\n%%\n\\end{tikzpicture}' return LatexExpr(tikz_pic) + + def _front_back_facets(self, projection_vector): + r""" + Return the front/back vertices/facets of the projected polyhedron + with respect to the projection vector. + + INPUT: + + - ``projection_vector`` -- vector + + EXAMPLES:: + + sage: # needs sage.plot sage.rings.number_field + sage: P = polytopes.small_rhombicuboctahedron() + sage: from sage.geometry.polyhedron.plot import Projection + sage: proj = Projection(P) + sage: v = (-0.544571767341018, 0.8192019648731899, 0.17986030958214505) + sage: v = vector(RDF, v) + sage: proj._front_back_facets(v) + ([0, 2, 4, 5, 8, 9, 10, 17, 18, 19, 20, 22, 24], + [1, 3, 6, 7, 11, 12, 13, 14, 15, 16, 21, 23, 25], + [2, 3, 14, 15, 0, 12, 1, 4, 13, 16, 6, 7, 18, 19, 20, 21, 23], + [4, 9, 16, 21, 3, 5, 15, 17, 10, 22, 2, 6, 8, 7, 11, 20, 23]) + + """ + P = self.parent_polyhedron + facet_ineqs = self.face_inequalities + front_facets = [] + back_facets = [] + for index_facet,f in enumerate(facet_ineqs): + A = f.A() + if A * projection_vector < 0: + front_facets.append(index_facet) + else: + back_facets.append(index_facet) + + front_vertices = [] + for index_facet in front_facets: + f_ineq = facet_ineqs[index_facet] + A = f_ineq.A() + b = f_ineq.b() + for v in self.points: + if A*self.coords[v]+b < 0.0005 and v not in front_vertices: + front_vertices.append(v) + + back_vertices = [] + for index_facet in back_facets: + f_ineq = facet_ineqs[index_facet] + A = f_ineq.A() + b = f_ineq.b() + for v in self.points: + if A * self.coords[v] + b < 0.0005 and v not in back_vertices: + back_vertices.append(v) + + return front_facets, back_facets, front_vertices, back_vertices + From 67892fec1b9bbde4bc8d2632d61b643b387118f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Labb=C3=A9?= Date: Thu, 27 Feb 2025 12:07:49 +0100 Subject: [PATCH 2/4] Update src/sage/geometry/polyhedron/plot.py Removed unnecessary line --- src/sage/geometry/polyhedron/plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index e54a228c131..e65e26eb3cb 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -1955,7 +1955,6 @@ def _front_back_facets(self, projection_vector): [4, 9, 16, 21, 3, 5, 15, 17, 10, 22, 2, 6, 8, 7, 11, 20, 23]) """ - P = self.parent_polyhedron facet_ineqs = self.face_inequalities front_facets = [] back_facets = [] From 0c1b0f243174e78b2dd3e11a2eeac4820b923d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Labb=C3=A9?= Date: Thu, 27 Feb 2025 12:09:24 +0100 Subject: [PATCH 3/4] Update src/sage/geometry/polyhedron/plot.py Removed empty line at the end of file --- src/sage/geometry/polyhedron/plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index e65e26eb3cb..de97b9f498f 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -1984,4 +1984,3 @@ def _front_back_facets(self, projection_vector): back_vertices.append(v) return front_facets, back_facets, front_vertices, back_vertices - From 82f898ba423d1543fb6760b0b9e34e03e25bd3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Labb=C3=A9?= Date: Fri, 28 Feb 2025 11:12:45 +0100 Subject: [PATCH 4/4] Apply suggestions from code review --- src/sage/geometry/polyhedron/plot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index de97b9f498f..28ff12ff7b1 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -1953,7 +1953,6 @@ def _front_back_facets(self, projection_vector): [1, 3, 6, 7, 11, 12, 13, 14, 15, 16, 21, 23, 25], [2, 3, 14, 15, 0, 12, 1, 4, 13, 16, 6, 7, 18, 19, 20, 21, 23], [4, 9, 16, 21, 3, 5, 15, 17, 10, 22, 2, 6, 8, 7, 11, 20, 23]) - """ facet_ineqs = self.face_inequalities front_facets = [] @@ -1971,7 +1970,7 @@ def _front_back_facets(self, projection_vector): A = f_ineq.A() b = f_ineq.b() for v in self.points: - if A*self.coords[v]+b < 0.0005 and v not in front_vertices: + if A * self.coords[v] + b < 0.0005 and v not in front_vertices: front_vertices.append(v) back_vertices = []