ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Mar 2021 18:20:01 +0100Oriented vertices of Polyhedronhttps://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/ Hi, I wonder what is the most convenient way to extract the ordered/oriented vertices of a Polyhedron/PolyhedronFace.
Specifically, say that we have a cube:
sage: cb = Polyhedron(vertices=[(0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), (1,1,1)])
which consists of 6 facets:
sage: cb.facets()
(A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices,
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices,
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices,
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices,
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices,
A 2-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 4 vertices)
I can easily know the indices of vertices (in `cb.Vrepresentation`) that form each facets, e.g., for the first facet:
sage: cb.facets()[0].ambient_V_indices()
(0, 1, 4, 5)
However, the four vertices are not properly ordered (linked) as I inspect the adjacency matrix:
sage: cb.vertex_adjacency_matrix()
[0 1 1 0 1 0 0 0]
[1 0 0 1 0 1 0 0]
[1 0 0 1 0 0 1 0]
[0 1 1 0 0 0 0 1]
[1 0 0 0 0 1 1 0]
[0 1 0 0 1 0 0 1]
[0 0 1 0 1 0 0 1]
[0 0 0 1 0 1 1 0]
(from the adjacent matrix the ordered indices of the four vertices should be 0->1->5->4, or reversed as 4->5->1->0).
The proper orientation of the vertices is needed for B-rep. Though I can extract the proper ordering with `vertex_adjacency_matrix()`, how to make sure they're consistently CCW orientated (seen from outside) still confuses me.
I'm kinda sure these are well managed in Sage, because the `obj_repr()` method in [plot3d](https://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/base.html?highlight=obj_repr#sage.plot.plot3d.base.Graphics3d.obj_repr) seems working well providing a consistent facet-vertex representation:
sage: cb_render = cb.render_solid()
sage: cb_render.obj_repr(cb_render.default_render_params())
['g obj_1',
'usemtl texture7',
['v 0 0 0',
'v 0 0 1',
'v 0 1 0',
'v 0 1 1',
'v 1 0 0',
'v 1 0 1',
'v 1 1 0',
'v 1 1 1'],
['f 8 4 2 6',
'f 7 3 4 8',
'f 8 6 5 7',
'f 3 1 2 4',
'f 5 1 3 7',
'f 6 2 1 5'],
['f 6 2 4 8',
'f 8 4 3 7',
'f 7 5 6 8',
'f 4 2 1 3',
'f 7 3 1 5',
'f 5 1 2 6']]
(notice that the vertex index in OBJ representation starts from 1 instead of 0; the line `f 6 2 1 5` corresponds to the ordering `4->5->1->0` that I want)
Is there a native method for Polyhedron or PolyhdronFace that I can directly use for this?zhaiyuTue, 16 Mar 2021 18:20:01 +0100https://ask.sagemath.org/question/56186/