Beispiel #1
0
def my_hyperbolic_triangle(a, b, c, **options):
    """
    Return a hyperbolic triangle in the complex hyperbolic plane with points
    (a, b, c). Type ``?hyperbolic_triangle`` to see all options.

    INPUT:

    - ``a, b, c`` - complex numbers in the upper half complex plane

    OPTIONS:
    
    - ``alpha`` - default: 1
       
    - ``fill`` - default: False

    - ``thickness`` - default: 1

    - ``rgbcolor`` - default: 'blue'

    - ``linestyle`` - default: 'solid'

    EXAMPLES:

    Show a hyperbolic triangle with coordinates 0, `1/2+i\sqrt{3}/2` and
    `-1/2+i\sqrt{3}/2`::
    
         sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2)

    A hyperbolic triangle with coordinates 0, 1 and 2+i::
    
         sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red')
    """
    from sage.plot.all import Graphics
    g = Graphics()
    g._set_extra_kwds(g._extract_kwds_for_show(options))
    model = options['model']
    npts = options.get('npts',10)
    sides = options.pop('sides',[1,2,3]) ## Which of the sides we will draw.
    verbose = options.get('verbose',0)
    options.pop('model',None); options.pop('method',None)
    if model=="D":
        #g.add_primitive(HyperbolicTriangleDisc(a, b, c, **options))
        #print "options=",options
        options['sides']=sides
        H = HyperbolicTriangleDisc(a, b, c, **options)
        g += H()
    else:
        options.pop('npts',None)
        if sides == [1,2,3]:
            if verbose>0:
                print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format(a,b,c,options)
            options.pop('verbose',0)
            g.add_primitive(HyperbolicTriangle(a, b, c, options))
        else:
            options['sides']=sides
            if verbose>0:
                print "adding MyHyperbolicTriangle({0}, {1}, {2},options={3})".format(a,b,c,options)
            g.add_primitive(MyHyperbolicTriangle(a, b, c, options))                           
    g.set_aspect_ratio(1)
    return g
Beispiel #2
0
def ellipse(center, r1, r2, angle=0, **options):
    """
    Return an ellipse centered at a point center = ``(x,y)`` with radii =
    ``r1,r2`` and angle ``angle``.  Type ``ellipse.options`` to see all
    options.

    INPUT:

    - ``center`` - 2-tuple of real numbers - coordinates of the center

    - ``r1``, ``r2`` - positive real numbers - the radii of the ellipse

    - ``angle`` - real number (default: 0) - the angle between the first axis
      and the horizontal

    OPTIONS:

    - ``alpha`` - default: 1 - transparency

    - ``fill`` - default: False - whether to fill the ellipse or not

    - ``thickness`` - default: 1 - thickness of the line

    - ``linestyle`` - default: ``'solid'`` - The style of the line, which is one
      of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``,
      ``':'``, ``'-'``, ``'-.'``,  respectively.

    - ``edgecolor`` - default: 'black' - color of the contour

    - ``facecolor`` - default: 'red' - color of the filling

    - ``rgbcolor`` - 2D or 3D plotting.  This option overrides
      ``edgecolor`` and ``facecolor`` for 2D plotting.

    EXAMPLES:

    An ellipse centered at (0,0) with major and minor axes of lengths 2 and 1.
    Note that the default color is blue::

        sage: ellipse((0,0),2,1)

    More complicated examples with tilted axes and drawing options::

        sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed")
        sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="--")

    ::

        sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red')

    We see that ``rgbcolor`` overrides these other options, as this plot
    is green::

        sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red',rgbcolor='green')

    The default aspect ratio for ellipses is 1.0::

        sage: ellipse((0,0),2,1).aspect_ratio()
        1.0

    One cannot yet plot ellipses in 3D::

        sage: ellipse((0,0,0),2,1)
        Traceback (most recent call last):
        ...
        NotImplementedError: plotting ellipse in 3D is not implemented
    """
    from sage.plot.all import Graphics
    g = Graphics()

    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
    # Otherwise matplotlib complains.
    scale = options.get('scale', None)
    if isinstance(scale, (list, tuple)):
        scale = scale[0]
    if scale == 'semilogy' or scale == 'semilogx':
        options['aspect_ratio'] = 'automatic'

    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    g.add_primitive(Ellipse(center[0], center[1], r1, r2, angle, options))
    if options['legend_label']:
        g.legend(True)
    if len(center) == 2:
        return g
    elif len(center) == 3:
        raise NotImplementedError, "plotting ellipse in 3D is not implemented"
Beispiel #3
0
def arc(center, r1, r2=None, angle=0.0, sector=(0.0,2*pi), **options):
    r"""
    An arc (that is a portion of a circle or an ellipse)

    Type ``arc.options`` to see all options.

    INPUT:

    - ``center`` - 2-tuple of real numbers - position of the center.

    - ``r1``, ``r2`` - positive real numbers - radii of the ellipse. If only ``r1``
      is set, then the two radii are supposed to be equal and this function returns
      an arc of of circle.

    - ``angle`` - real number - angle between the horizontal and the axis that
      corresponds to ``r1``.

    - ``sector`` - 2-tuple (default: (0,2*pi))- angles sector in which the arc will
      be drawn.

    OPTIONS:

    - ``alpha`` - float (default: 1) - transparency

    - ``thickness`` - float (default: 1) - thickness of the arc

    - ``color``, ``rgbcolor`` - string or 2-tuple (default: 'blue') - the color
      of the arc

    - ``linestyle`` - string (default: ``'solid'``) - The style of the line,
      which is one of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``,
      or ``'--'``, ``':'``, ``'-'``, ``'-.'``, respectively.

    EXAMPLES:

    Plot an arc of circle centered at (0,0) with radius 1 in the sector
    `(\pi/4,3*\pi/4)`::

        sage: arc((0,0), 1, sector=(pi/4,3*pi/4))
        Graphics object consisting of 1 graphics primitive

    Plot an arc of an ellipse between the angles 0 and `\pi/2`::

        sage: arc((2,3), 2, 1, sector=(0,pi/2))
        Graphics object consisting of 1 graphics primitive

    Plot an arc of a rotated ellipse between the angles 0 and `\pi/2`::

        sage: arc((2,3), 2, 1, angle=pi/5, sector=(0,pi/2))
        Graphics object consisting of 1 graphics primitive

    Plot an arc of an ellipse in red with a dashed linestyle::

        sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="dashed", color="red")
        Graphics object consisting of 1 graphics primitive
        sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="--", color="red")
        Graphics object consisting of 1 graphics primitive

    The default aspect ratio for arcs is 1.0::

        sage: arc((0,0), 1, sector=(pi/4,3*pi/4)).aspect_ratio()
        1.0

    It is not possible to draw arcs in 3D::

        sage: A = arc((0,0,0), 1)
        Traceback (most recent call last):
        ...
        NotImplementedError
    """
    from sage.plot.all import Graphics

    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
    # Otherwise matplotlib complains.
    scale = options.get('scale', None)
    if isinstance(scale, (list, tuple)):
        scale = scale[0]
    if scale == 'semilogy' or scale == 'semilogx':
        options['aspect_ratio'] = 'automatic'

    if len(center)==2:
        if r2 is None: r2 = r1
        g = Graphics()
        g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
        if len(sector) != 2:
            raise ValueError("the sector must consist of two angles")
        g.add_primitive(Arc(
            center[0],center[1],
            r1,r2,
            angle,
            sector[0],sector[1],
            options))
        return g
    elif len(center)==3:
        raise NotImplementedError
Beispiel #4
0
def my_hyperbolic_triangle(a, b, c, **options):
    """
    Return a hyperbolic triangle in the complex hyperbolic plane with points
    (a, b, c). Type ``?hyperbolic_triangle`` to see all options.

    INPUT:

    - ``a, b, c`` - complex numbers in the upper half complex plane

    OPTIONS:
    
    - ``alpha`` - default: 1
       
    - ``fill`` - default: False

    - ``thickness`` - default: 1

    - ``rgbcolor`` - default: 'blue'

    - ``linestyle`` - default: 'solid'

    EXAMPLES:

    Show a hyperbolic triangle with coordinates 0, `1/2+i\sqrt{3}/2` and
    `-1/2+i\sqrt{3}/2`::
    
         sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2)

    A hyperbolic triangle with coordinates 0, 1 and 2+i::
    
         sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red')
    """
    from sage.plot.all import Graphics
    g = Graphics()
    g._set_extra_kwds(g._extract_kwds_for_show(options))
    model = options['model']
    npts = options.get('npts', 10)
    sides = options.pop('sides',
                        [1, 2, 3])  ## Which of the sides we will draw.
    verbose = options.get('verbose', 0)
    options.pop('model', None)
    options.pop('method', None)
    if model == "D":
        #g.add_primitive(HyperbolicTriangleDisc(a, b, c, **options))
        #print "options=",options
        options['sides'] = sides
        H = HyperbolicTriangleDisc(a, b, c, **options)
        g += H()
    else:
        options.pop('npts', None)
        if sides == [1, 2, 3]:
            if verbose > 0:
                print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format(
                    a, b, c, options)
            options.pop('verbose', 0)
            ## check if We need my class or the original class
            g.add_primitive(HyperbolicTriangle(a, b, c, options))
        else:
            options['sides'] = sides
            if verbose > 0:
                print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format(
                    a, b, c, options)
            g.add_primitive(HyperbolicTriangle(a, b, c, options))
    g.set_aspect_ratio(1)
    return g
Beispiel #5
0
def ellipse(center, r1, r2, angle=0, **options):
    """
    Return an ellipse centered at a point center = ``(x,y)`` with radii =
    ``r1,r2`` and angle ``angle``.  Type ``ellipse.options`` to see all
    options.

    INPUT:

    - ``center`` - 2-tuple of real numbers - coordinates of the center

    - ``r1``, ``r2`` - positive real numbers - the radii of the ellipse

    - ``angle`` - real number (default: 0) - the angle between the first axis
      and the horizontal

    OPTIONS:

    - ``alpha`` - default: 1 - transparency

    - ``fill`` - default: False - whether to fill the ellipse or not

    - ``thickness`` - default: 1 - thickness of the line

    - ``linestyle`` - default: ``'solid'`` - The style of the line, which is one
      of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``,
      ``':'``, ``'-'``, ``'-.'``,  respectively.

    - ``edgecolor`` - default: 'black' - color of the contour

    - ``facecolor`` - default: 'red' - color of the filling

    - ``rgbcolor`` - 2D or 3D plotting.  This option overrides
      ``edgecolor`` and ``facecolor`` for 2D plotting.

    - ``legend_label`` - the label for this item in the legend

    - ``legend_color`` - the color for the legend label

    EXAMPLES:

    An ellipse centered at (0,0) with major and minor axes of lengths 2 and 1.
    Note that the default color is blue::

        sage: ellipse((0,0),2,1)

    More complicated examples with tilted axes and drawing options::

        sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed")
        sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="--")

    ::

        sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red')

    We see that ``rgbcolor`` overrides these other options, as this plot
    is green::

        sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red',rgbcolor='green')

    The default aspect ratio for ellipses is 1.0::

        sage: ellipse((0,0),2,1).aspect_ratio()
        1.0

    One cannot yet plot ellipses in 3D::

        sage: ellipse((0,0,0),2,1)
        Traceback (most recent call last):
        ...
        NotImplementedError: plotting ellipse in 3D is not implemented

    We can also give ellipses a legend::

        sage: ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green')
    """
    from sage.plot.all import Graphics
    g = Graphics()

    # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'.
    # Otherwise matplotlib complains.
    scale = options.get('scale', None)
    if isinstance(scale, (list, tuple)):
        scale = scale[0]
    if scale == 'semilogy' or scale == 'semilogx':
        options['aspect_ratio'] = 'automatic'

    g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
    g.add_primitive(Ellipse(center[0],center[1],r1,r2,angle,options))
    if options['legend_label']:
        g.legend(True)
        g._legend_colors = [options['legend_color']]
    if len(center)==2:
        return g
    elif len(center)==3:
        raise NotImplementedError("plotting ellipse in 3D is not implemented")