def polygon3d(points, **options): """ Draw a polygon in 3d. INPUT: - ``points`` - the vertices of the polygon Type ``polygon3d.options`` for a dictionary of the default options for polygons. You can change this to change the defaults for all future polygons. Use ``polygon3d.reset()`` to reset to the default options. EXAMPLES: A simple triangle:: sage: polygon3d([[0,0,0], [1,2,3], [3,0,0]]) Some modern art -- a random polygon:: sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)] sage: polygon3d(v) A bent transparent green triangle:: sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7) """ from sage.plot.plot3d.index_face_set import IndexFaceSet return IndexFaceSet([range(len(points))], points, **options)
def plot3d(self, z=0, **kwds): """ Plots a 2D polygon in 3D, with default height zero. INPUT: - ``z`` - optional 3D height above `xy`-plane, or a list of heights corresponding to the list of 2D polygon points. EXAMPLES: A pentagon:: sage: polygon([(cos(t), sin(t)) for t in srange(0, 2*pi, 2*pi/5)]).plot3d() Graphics3d Object Showing behavior of the optional parameter z:: sage: P = polygon([(0,0), (1,2), (0,1), (-1,2)]) sage: p = P[0]; p Polygon defined by 4 points sage: q = p.plot3d() sage: q.obj_repr(q.testing_render_params())[2] ['v 0 0 0', 'v 1 2 0', 'v 0 1 0', 'v -1 2 0'] sage: r = p.plot3d(z=3) sage: r.obj_repr(r.testing_render_params())[2] ['v 0 0 3', 'v 1 2 3', 'v 0 1 3', 'v -1 2 3'] sage: s = p.plot3d(z=[0,1,2,3]) sage: s.obj_repr(s.testing_render_params())[2] ['v 0 0 0', 'v 1 2 1', 'v 0 1 2', 'v -1 2 3'] TESTS: Heights passed as a list should have same length as number of points:: sage: P = polygon([(0,0), (1,2), (0,1), (-1,2)]) sage: p = P[0] sage: q = p.plot3d(z=[2,-2]) Traceback (most recent call last): ... ValueError: Incorrect number of heights given """ from sage.plot.plot3d.index_face_set import IndexFaceSet options = self._plot3d_options() options.update(kwds) zdata = [] if isinstance(z, list): zdata = z else: zdata = [z] * len(self.xdata) if len(zdata) == len(self.xdata): return IndexFaceSet( [[(x, y, z) for x, y, z in zip(self.xdata, self.ydata, zdata)]], **options) else: raise ValueError('Incorrect number of heights given')
def polygons3d(faces, points, **options): """ Draw the union of several polygons in 3d. Useful to plot a polyhedron as just one ``IndexFaceSet``. INPUT: - ``faces`` -- list of faces, every face given by the list of indices of its vertices - ``points`` -- coordinates of the vertices in the union EXAMPLES: Two adjacent triangles:: sage: f = [[0,1,2],[1,2,3]] sage: v = [(-1,0,0),(0,1,1),(0,-1,1),(1,0,0)] sage: polygons3d(f, v, color='red') Graphics3d Object """ from sage.plot.plot3d.index_face_set import IndexFaceSet return IndexFaceSet(faces, points, **options)