《Sage》中的多面体简介

如果你已经知道一些凸几何知识 a la 如果您是Grünbaum或Brndsted,那么您可能渴望通过一些多面体计算来弄脏自己的双手。这里有一个迷你指南,教你如何做到这一点。

基础知识

首先,让我们将多面体定义为一组点的凸包,即给定的 S 我们计算 P={rm conv}(S)

sage: P1 = Polyhedron(vertices = [[-5,2], [4,4], [3,0], [1,0], [2,-4], [-3,-1], [-5,-3]])
sage: P1
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices

请注意,Sage会告诉您多面体的尺寸以及环境空间的尺寸。

当然,您想知道这个对象是什么样子:

sage: P1.plot()
Graphics object consisting of 6 graphics primitives

即使在只有2维的情况下,要弄清楚支持超平面是一件痛苦的事情。幸运的是,Sage会帮我们解决这个问题。

sage: for q in P1.Hrepresentation():
....:    print(q)
An inequality (-4, 1) x + 12 >= 0
An inequality (1, 7) x + 26 >= 0
An inequality (1, 0) x + 5 >= 0
An inequality (2, -9) x + 28 >= 0

这种表示法不能立即解析,因为说真的,它们看起来不像直线方程(或半空间方程,这才是它们的真正含义)。

(-4, 1) x + 12 >= 0 真正的意思是 (-4, 1)cdotvec{x} + 12 geq 0

So... if you want to define a polytope via inequalities, you have to translate each inequality into a vector. For example, (-4, 1)cdotvec{x} + 12 geq 0 becomes (12, -4, 1).

sage: altP1 = Polyhedron(ieqs=[(12, -4, 1), (26, 1, 7),(5,1,0), (28, 2, -9)])
sage: altP1.plot()
Graphics object consisting of 6 graphics primitives

您可能希望从Sage中提取有关多面体的其他信息是顶点列表,这可以通过两种方式完成:

sage: for q in P1.Vrepresentation():
....:    print(q)
A vertex at (-5, -3)
A vertex at (-5, 2)
A vertex at (4, 4)
A vertex at (2, -4)
sage: P1.vertices()
(A vertex at (-5, -3), A vertex at (-5, 2), A vertex at (4, 4), A vertex at (2, -4))

极地双打

当然,您想要计算极对偶:

sage: P1dual = P1.polar()
sage: P1dual
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4 vertices

Check it out---we started with an integer-lattice polytope and dualized to a rational-lattice polytope. Let's look at that.

sage: P1dual.plot()
Graphics object consisting of 6 graphics primitives
sage: P1.plot() + P1dual.plot()
Graphics object consisting of 12 graphics primitives

哦,是的,除非多面体是单位球体大小,否则对偶的大小将非常不同。让我们再来一次。

sage: ((1/4)*P1).plot() + (4*P1dual).plot()
Graphics object consisting of 12 graphics primitives

如果你认为这看起来有点可疑,那么你是对的。这里有一个例子,可以让这个问题变得更清楚一些。

sage: P2 = Polyhedron(vertices = [[-5,0], [-1,1], [-2,0], [1,0], [-2,-1], [-3,-1], [-5,-1]])
sage: P2
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 5 vertices
sage: P2dual = P2.polar(); P2dual
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 5 vertices
sage: P2.plot() + P2dual.plot()
Graphics object consisting of 14 graphics primitives

这显然不是在计算我们所认为的极地对偶。但看看这个。

sage: P2.plot() + (-1*P2dual).plot()
Graphics object consisting of 14 graphics primitives

以下是正在发生的事情。

如果一个多面体 P vt.在.中 ZZ 然后..。

  1. ...对偶在某种程度上是反转的,对于多边形来说是垂直的。

  2. ...双重奏是从P本身出发的。

  3. ...如果原点不在P中,则返回错误。

然而,如果多面体是 not 在……里面 ZZ ,例如,如果它在 QQRDF 然后..。

(1‘)...对偶不是反转的。

(2') ...the dual is taken of P-translated-so-barycenter-is-at-origin.

当你进行极地双人对决时,请记住这一切。

多面体结构

明科夫斯基和!现在使用两种语法!

sage: P1+P2
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 8 vertices
sage: P1.minkowski_sum(P2)
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 8 vertices

好吧。我们至少应该有一些三维的例子。(请注意,为了有效地显示多面体,您需要安装可视化软件,如Javaview和JMOL。)

sage: P3 = Polyhedron(vertices=[(0,0,0), (0,0,1/2), (0,1/2,0), (1/2,0,0), (3/4,1/5,3/2)]); P3
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 5 vertices
sage: P4 = Polyhedron(vertices=[(-1,1,0),(1,1,0),(-1,0,1), (1,0,1),(0,-1,1),(0,1,1)]); P4
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices
sage: P3.plot() + P4.plot()
Graphics3d Object
sage: (P3+P4).plot()
Graphics3d Object

我们还可以找到两个多面体的交点。这也有两种语法!

sage: int12 = P1.intersection(P2*.5); int12.plot()
Graphics object consisting of 7 graphics primitives
sage: int34 = P3 & P4; int34.plot()
Graphics3d Object

如果一个人想要翻译,他可以。

sage: transP2 = P2.translation([2,1])
sage: P2.plot() + transP2.plot()
Graphics object consisting of 14 graphics primitives

当然,我们可以用棱柱、金字塔和多面体的双金字塔……

sage: P2.prism().plot()
Graphics3d Object
sage: P1.pyramid().plot()
Graphics3d Object
sage: P2dual.bipyramid().plot()
Graphics3d Object

好吧。是的,Sage内置了一些多面体。如果您键入 polytopes. 然后按下 TAB 在这段时间之后,你会得到一份预制多面体的清单。

sage: P5 = polytopes.hypercube(5)
sage: P6 = polytopes.cross_polytope(3)
sage: P7 = polytopes.simplex(7)

让我们来看看一个四维多面体。

sage: P8 = polytopes.hypercube(4)
sage: P8.plot()
Graphics3d Object

我们可以从不同的角度来看待它:

sage: P8.schlegel_projection(position=1/2).plot()
Graphics3d Object

对多面体的查询

一旦你构建了一些多面体,你就可以问Sage关于它的问题了。

sage: P1.contains([1,0])
True
sage: P1.interior_contains([3,0])
False
sage: P3.contains([1,0,0])
False

面部信息可能会很有用。

sage: int34.f_vector()
(1, 8, 12, 6, 1)

嗯,几何信息可能是 more 有帮助..。在这里,我们被告知哪个顶点构成每个两个面:

sage: [f.ambient_V_indices() for f in int34.faces(2)]
[(2, 6, 7), (0, 1, 3, 5), (1, 3, 4), (0, 5, 6, 7), (0, 1, 2, 4, 6), (2, 3, 4, 5, 7)]

是啊,这可没那么有用。让我们计算出列表中第一个面的顶点和超平面表示。

sage: first2faceofint34 = int34.faces(2)[0]
sage: first2faceofint34.ambient_Hrepresentation(); first2faceofint34.vertices()
(An inequality (0, 0, -1) x + 1 >= 0,)
(A vertex at (2/3, 2/15, 1), A vertex at (3/8, 1/10, 1), A vertex at (1/2, 3/10, 1))

如果你想要更多..。 sage.geometry.polyhedron.base 是你第一个想去的地方。