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.Thu, 25 Mar 2021 19:50:49 +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?Tue, 16 Mar 2021 18:20:01 +0100https://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/Comment by Jonathan Kliem for <p>Hi, I wonder what is the most convenient way to extract the ordered/oriented vertices of a Polyhedron/PolyhedronFace. </p>
<p>Specifically, say that we have a cube:</p>
<pre><code>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)])
</code></pre>
<p>which consists of 6 facets:</p>
<pre><code>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)
</code></pre>
<p>I can easily know the indices of vertices (in <code>cb.Vrepresentation</code>) that form each facets, e.g., for the first facet:</p>
<pre><code>sage: cb.facets()[0].ambient_V_indices()
(0, 1, 4, 5)
</code></pre>
<p>However, the four vertices are not properly ordered (linked) as I inspect the adjacency matrix:</p>
<pre><code>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]
</code></pre>
<p>(from the adjacent matrix the ordered indices of the four vertices should be 0->1->5->4, or reversed as 4->5->1->0).</p>
<p>The proper orientation of the vertices is needed for B-rep. Though I can extract the proper ordering with <code>vertex_adjacency_matrix()</code>, how to make sure they're consistently CCW orientated (seen from outside) still confuses me.</p>
<p>I'm kinda sure these are well managed in Sage, because the <code>obj_repr()</code> method in <a href="https://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/base.html?highlight=obj_repr#sage.plot.plot3d.base.Graphics3d.obj_repr">plot3d</a> seems working well providing a consistent facet-vertex representation:</p>
<pre><code>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']]
</code></pre>
<p>(notice that the vertex index in OBJ representation starts from 1 instead of 0; the line <code>f 6 2 1 5</code> corresponds to the ordering <code>4->5->1->0</code> that I want)</p>
<p>Is there a native method for Polyhedron or PolyhdronFace that I can directly use for this?</p>
https://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/?comment=56376#post-id-56376Am I understanding correctly that you are referring only to 3-dimensional polytopes? (Because I woudn't even understand the question for higher dimensions).Thu, 25 Mar 2021 19:50:49 +0100https://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/?comment=56376#post-id-56376Comment by Max Alekseyev for <p>Hi, I wonder what is the most convenient way to extract the ordered/oriented vertices of a Polyhedron/PolyhedronFace. </p>
<p>Specifically, say that we have a cube:</p>
<pre><code>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)])
</code></pre>
<p>which consists of 6 facets:</p>
<pre><code>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)
</code></pre>
<p>I can easily know the indices of vertices (in <code>cb.Vrepresentation</code>) that form each facets, e.g., for the first facet:</p>
<pre><code>sage: cb.facets()[0].ambient_V_indices()
(0, 1, 4, 5)
</code></pre>
<p>However, the four vertices are not properly ordered (linked) as I inspect the adjacency matrix:</p>
<pre><code>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]
</code></pre>
<p>(from the adjacent matrix the ordered indices of the four vertices should be 0->1->5->4, or reversed as 4->5->1->0).</p>
<p>The proper orientation of the vertices is needed for B-rep. Though I can extract the proper ordering with <code>vertex_adjacency_matrix()</code>, how to make sure they're consistently CCW orientated (seen from outside) still confuses me.</p>
<p>I'm kinda sure these are well managed in Sage, because the <code>obj_repr()</code> method in <a href="https://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/base.html?highlight=obj_repr#sage.plot.plot3d.base.Graphics3d.obj_repr">plot3d</a> seems working well providing a consistent facet-vertex representation:</p>
<pre><code>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']]
</code></pre>
<p>(notice that the vertex index in OBJ representation starts from 1 instead of 0; the line <code>f 6 2 1 5</code> corresponds to the ordering <code>4->5->1->0</code> that I want)</p>
<p>Is there a native method for Polyhedron or PolyhdronFace that I can directly use for this?</p>
https://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/?comment=56194#post-id-56194I suggest to look into `obj_repr()` source code to see how it does the job.Tue, 16 Mar 2021 23:17:49 +0100https://ask.sagemath.org/question/56186/oriented-vertices-of-polyhedron/?comment=56194#post-id-56194