Beispiel #1
0
 def circle_plot(self):
     pts = []
     pi = RR.pi()
     for angle in self.angles:
         angle = RR(angle) * pi
         c = angle.cos()
         s = angle.sin()
         if abs(s) < 0.00000001:
             pts.append((c, s))
         else:
             pts.extend([(c, s), (c, -s)])
     P = points(pts, size=100) + circle((0, 0), 1, color='black')
     P.axes(False)
     P.set_aspect_ratio(1)
     return encode_plot(P)
Beispiel #2
0
 def circle_plot(self):
     pts = []
     pi = RR.pi()
     for angle in self.angles:
         angle = RR(angle)*pi
         c = angle.cos()
         s = angle.sin()
         if abs(s) < 0.00000001:
             pts.append((c,s))
         else:
             pts.extend([(c,s),(c,-s)])
     P = points(pts,size=100) + circle((0,0),1,color='black')
     P.axes(False)
     P.set_aspect_ratio(1)
     return encode_plot(P)
Beispiel #3
0
 def circle_plot(self):
     pts = []
     pi = RR.pi()
     for angle in self.angles:
         angle = RR(angle) * pi
         c = angle.cos()
         s = angle.sin()
         if abs(s) < 0.00000001:
             pts.append((c, s))
         else:
             pts.extend([(c, s), (c, -s)])
     P = circle((0, 0), 1, color="black", thickness=2.5)
     P[0].set_zorder(-1)
     P += points(pts, size=300, rgbcolor="darkblue")
     P.axes(False)
     P.set_aspect_ratio(1)
     return encode_plot(P, pad=0, pad_inches=None, transparent=True, axes_pad=0.04)
Beispiel #4
0
    def regular_polygon(self, n, base_ring=QQ):
        """
        Return a regular polygon with `n` vertices.  Over the rational
        field the vertices may not be exact.

        INPUT:

        - ``n`` -- a positive integer, the number of vertices.

        - ``base_ring`` -- a ring in which the coordinates will lie.

        EXAMPLES::

            sage: octagon = polytopes.regular_polygon(8)
            sage: len(octagon.vertices())
            8
            sage: polytopes.regular_polygon(3).vertices()
            (A vertex at (-125283617/144665060, -500399958596723/1000799917193445),
             A vertex at (0, 1),
             A vertex at (94875313/109552575, -1000799917193444/2001599834386889))
            sage: polytopes.regular_polygon(3, base_ring=RealField(100)).vertices()
            (A vertex at (0.00000000000000000000000000000, 1.0000000000000000000000000000),
             A vertex at (0.86602540378443864676372317075, -0.50000000000000000000000000000),
             A vertex at (-0.86602540378443864676372317076, -0.50000000000000000000000000000))
            sage: polytopes.regular_polygon(3, base_ring=RealField(10)).vertices()
            (A vertex at (0.00, 1.0),
             A vertex at (0.87, -0.50),
             A vertex at (-0.86, -0.50))
        """
        try:
            omega = 2*base_ring.pi()/n
        except AttributeError:
            omega = 2*RR.pi()/n
        verts = []
        for i in range(n):
            t = omega*i
            verts.append([base_ring(t.sin()), base_ring(t.cos())])
        return Polyhedron(vertices=verts, base_ring=base_ring)
Beispiel #5
0
    def regular_polygon(self, n, base_ring=QQ):
        """
        Return a regular polygon with `n` vertices.  Over the rational
        field the vertices may not be exact.

        INPUT:

        - ``n`` -- a positive integer, the number of vertices.

        - ``base_ring`` -- a ring in which the coordinates will lie.

        EXAMPLES::

            sage: octagon = polytopes.regular_polygon(8)
            sage: len(octagon.vertices())
            8
            sage: polytopes.regular_polygon(3).vertices()
            (A vertex at (-125283617/144665060, -500399958596723/1000799917193445),
             A vertex at (0, 1),
             A vertex at (94875313/109552575, -1000799917193444/2001599834386889))
            sage: polytopes.regular_polygon(3, base_ring=RealField(100)).vertices()
            (A vertex at (0.00000000000000000000000000000, 1.0000000000000000000000000000),
             A vertex at (0.86602540378443864676372317075, -0.50000000000000000000000000000),
             A vertex at (-0.86602540378443864676372317076, -0.50000000000000000000000000000))
            sage: polytopes.regular_polygon(3, base_ring=RealField(10)).vertices()
            (A vertex at (0.00, 1.0),
             A vertex at (0.87, -0.50),
             A vertex at (-0.86, -0.50))
        """
        try:
            omega = 2 * base_ring.pi() / n
        except AttributeError:
            omega = 2 * RR.pi() / n
        verts = []
        for i in range(n):
            t = omega * i
            verts.append([base_ring(t.sin()), base_ring(t.cos())])
        return Polyhedron(vertices=verts, base_ring=base_ring)