B
    [                 @   s|  d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=Z=G dd de3Z>G dd de>Z?ddl@mAZA dS )z?Elliptical geometrical entities.

Contains
* Ellipse
* Circle

    )divisionprint_function)Spisympify)
fuzzy_bool)Rationaloo)rangeordered)Dummy_uniquely_named_symbol_symbol)simplifytrigsimp)sqrt)cossin)
elliptic_e)GeometryError)Ray2D	Segment2DLine2DLinearEntity3D)DomainErrorPolyPolynomialError)_not_a_coeff_nsort)solve)
filldedent	func_name   )GeometryEntityGeometrySet)PointPoint2DPoint3D)LineLinearEntity)idiffNc                   s~  e Zd ZdZdd Zdd Z fddZdNd	d
ZdOddZe	dd Z
e	dd ZdPddZe	dd Ze	dd Ze	dd Ze	dd Ze	dd Zd d! ZdQd$d%ZdRd&d'Ze	d(d) Ze	d*d+ Ze	d,d- Zd.d/ Zd0d1 Ze	d2d3 Ze	d4d5 ZdSd6d7Ze	d8d9 Ze	d:d; ZdTd<d=ZdUd>d?Z d@dA Z!dV fdCdD	Z"dWdFdGZ#dHdI Z$e	dJdK Z%dXdLdMZ&  Z'S )YEllipsea"  An elliptical GeometryEntity.

    Parameters
    ==========

    center : Point, optional
        Default value is Point(0, 0)
    hradius : number or SymPy expression, optional
    vradius : number or SymPy expression, optional
    eccentricity : number or SymPy expression, optional
        Two of `hradius`, `vradius` and `eccentricity` must be supplied to
        create an Ellipse. The third is derived from the two supplied.

    Attributes
    ==========

    center
    hradius
    vradius
    area
    circumference
    eccentricity
    periapsis
    apoapsis
    focus_distance
    foci

    Raises
    ======

    GeometryError
        When `hradius`, `vradius` and `eccentricity` are incorrectly supplied
        as parameters.
    TypeError
        When `center` is not a Point.

    See Also
    ========

    Circle

    Notes
    -----
    Constructed from a center and two radii, the first being the horizontal
    radius (along the x-axis) and the second being the vertical radius (along
    the y-axis).

    When symbolic value for hradius and vradius are used, any calculation that
    refers to the foci or the major or minor axis will assume that the ellipse
    has its major radius on the x-axis. If this is not true then a manual
    rotation is necessary.

    Examples
    ========

    >>> from sympy import Ellipse, Point, Rational
    >>> e1 = Ellipse(Point(0, 0), 5, 1)
    >>> e1.hradius, e1.vradius
    (5, 1)
    >>> e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5))
    >>> e2
    Ellipse(Point2D(3, 1), 3, 9/5)

    c             C   sh   t |trRtddd}tddd}| ||||j||ji}tt|t	j
kS t |trd| |kS dS )NxT)realyF)
isinstancer%   r   equationsubsr,   r.   r   r   r   ZZeror+   )selfor,   r.   Zres r4   5lib/python3.7/site-packages/sympy/geometry/ellipse.py__contains__e   s    

zEllipse.__contains__c             C   s.   t |to,| j|jko,| j|jko,| j|jkS )z5Is the other GeometryEntity the same as this ellipse?)r/   r+   centerhradiusvradius)r2   r3   r4   r4   r5   __eq__p   s    zEllipse.__eq__c                s   t t|  S )N)superr+   __hash__)r2   )	__class__r4   r5   r<   v   s    zEllipse.__hash__Nc             K   s   t |}t |}t |}|d kr,tdd}nt|dd}t|dkrRtd| tttdd |||fdkrztd|d k	r|d kr|td|d   }n|d kr|td|d   }||krt||f|S t	j
| |||f|S )	Nr      )dimz3The center of "{0}" must be a two dimensional pointc             S   s   | d k	S )Nr4   )r,   r4   r4   r5   <lambda>   s    z!Ellipse.__new__.<locals>.<lambda>zTExactly two arguments of "hradius", "vradius", and "eccentricity" must not be None."r"   )r   r%   len
ValueErrorformatlistfilterr   Circler#   __new__)clsr7   r8   r9   eccentricitykwargsr4   r4   r5   rG   y   s$     zEllipse.__new__      ?#66cc99c             C   sH   ddl m} || j}|| j|| j }}dd| ||j|j||S )a%  Returns SVG ellipse element for the Ellipse.

        Parameters
        ==========

        scale_factor : float
            Multiplication factor for the SVG stroke-width.  Default is 1.
        fill_color : str, optional
            Hex string for fill color. Default is "#66cc99".
        r   )Nzk<ellipse fill="{1}" stroke="#555555" stroke-width="{0}" opacity="0.6" cx="{2}" cy="{3}" rx="{4}" ry="{5}"/>g       @)Zsympy.core.evalfrM   r7   r8   r9   rC   r,   r.   )r2   Zscale_factorZ
fill_colorrM   chvr4   r4   r5   _svg   s
    
zEllipse._svgc             C   s   dS )Nr>   r4   )r2   r4   r4   r5   ambient_dimension   s    zEllipse.ambient_dimensionc             C   s   | j d| j  S )a  The apoapsis of the ellipse.

        The greatest distance between the focus and the contour.

        Returns
        =======

        apoapsis : number

        See Also
        ========

        periapsis : Returns shortest distance between foci and contour

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.apoapsis
        2*sqrt(2) + 3

        r"   )majorrI   )r2   r4   r4   r5   apoapsis   s    zEllipse.apoapsistc             C   sb   t |dd}|jdd | jD kr4ttd|j t| jj| jt	|  | jj
| jt|  S )aX  A parameterized point on the ellipse.

        Parameters
        ==========

        parameter : str, optional
            Default value is 't'.

        Returns
        =======

        arbitrary_point : Point

        Raises
        ======

        ValueError
            When `parameter` already appears in the functions.

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.arbitrary_point()
        Point2D(3*cos(t), 2*sin(t))

        T)r-   c             s   s   | ]}|j V  qd S )N)name).0fr4   r4   r5   	<genexpr>   s    z*Ellipse.arbitrary_point.<locals>.<genexpr>zFSymbol %s already appears in object and cannot be used as a parameter.)r   rV   free_symbolsrB   r    r%   r7   r,   r8   r   r.   r9   r   )r2   	parameterrU   r4   r4   r5   arbitrary_point   s    "zEllipse.arbitrary_pointc             C   s   t tj| j | j S )a  The area of the ellipse.

        Returns
        =======

        area : number

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.area
        3*pi

        )r   r   Pir8   r9   )r2   r4   r4   r5   area   s    zEllipse.areac             C   s:   | j | j }}| jj| | jj| | jj| | jj| fS )zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding
        rectangle for the geometric figure.

        )r8   r9   r7   r,   r.   )r2   rO   rP   r4   r4   r5   bounds  s    zEllipse.boundsc             C   s
   | j d S )ab  The center of the ellipse.

        Returns
        =======

        center : number

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.center
        Point2D(0, 0)

        r   )args)r2   r4   r4   r5   r7     s    zEllipse.centerc             C   sH   | j dkrd| j S | j dkr,dt | j S d| j t| j d  S dS )zThe circumference of the ellipse.

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.circumference
        12*elliptic_e(8/9)

        r"      r   r>   N)rI   rS   r   r8   r   )r2   r4   r4   r5   circumference/  s
    


zEllipse.circumferencec             C   s   | j | j S )a5  The eccentricity of the ellipse.

        Returns
        =======

        eccentricity : number

        Examples
        ========

        >>> from sympy import Point, Ellipse, sqrt
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, sqrt(2))
        >>> e1.eccentricity
        sqrt(7)/3

        )focus_distancerS   )r2   r4   r4   r5   rI   F  s    zEllipse.eccentricityc                sn   t  dd  | krdS t| jdkrR fdd| jD \}}d| j ||  }n| j| j  }t|jS )a  
        Return True if p is enclosed by (is inside of) self.

        Notes
        -----
        Being on the border of self is considered False.

        Parameters
        ==========

        p : Point

        Returns
        =======

        encloses_point : True, False or None

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Ellipse, S
        >>> from sympy.abc import t
        >>> e = Ellipse((0, 0), 3, 2)
        >>> e.encloses_point((0, 0))
        True
        >>> e.encloses_point(e.arbitrary_point(t).subs(t, S.Half))
        False
        >>> e.encloses_point((4, 0))
        False

        r>   )r?   Fc                s   g | ]}|  qS r4   )distance)rW   rX   )pr4   r5   
<listcomp>  s    z*Ellipse.encloses_point.<locals>.<listcomp>)	r%   rA   focirS   radiusr7   rd   r   is_positive)r2   re   Zh1Zh2testr4   )re   r5   encloses_point[  s    %zEllipse.encloses_pointr,   r.   c             C   sP   t |dd}t |dd}|| jj | j d }|| jj | j d }|| d S )aX  The equation of the ellipse.

        Parameters
        ==========

        x : str, optional
            Label for the x-axis. Default value is 'x'.
        y : str, optional
            Label for the y-axis. Default value is 'y'.

        Returns
        =======

        equation : sympy expression

        See Also
        ========

        arbitrary_point : Returns parameterized point on ellipse

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> e1 = Ellipse(Point(1, 0), 3, 2)
        >>> e1.equation()
        y**2/4 + (x/3 - 1/3)**2 - 1

        T)r-   r>   r"   )r   r7   r,   r8   r.   r9   )r2   r,   r.   t1t2r4   r4   r5   r0     s
    zEllipse.equationc             C   s   t | jdkrtdt|dd}t|dd}| j|| jj  tdd }| j|| jj	  tdd }|| | jd | jd  tdd  S )a  The equation of evolute of the ellipse.

        Parameters
        ==========

        x : str, optional
            Label for the x-axis. Default value is 'x'.
        y : str, optional
            Label for the y-axis. Default value is 'y'.

        Returns
        =======

        equation : sympy expression

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> e1 = Ellipse(Point(1, 0), 3, 2)
        >>> e1.evolute()
        2**(2/3)*y**(2/3) + (3*x - 3)**(2/3) - 5**(2/3)
           z.Evolute of arbitrary Ellipse is not supported.T)r-   r>   )
rA   r`   NotImplementedErrorr   r8   r7   r,   r   r9   r.   )r2   r,   r.   rl   rm   r4   r4   r5   evolute  s    zEllipse.evolutec             C   s   | j }| j| j }}||kr$||fS t| jd | jd  }|| jkrd|td|  |td| fS || jkr|t| d |t|d fS dS )ah  The foci of the ellipse.

        Notes
        -----
        The foci can only be calculated if the major/minor axes are known.

        Raises
        ======

        ValueError
            When the major and minor axis cannot be determined.

        See Also
        ========

        sympy.geometry.point.Point
        focus_distance : Returns the distance between focus and center

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.foci
        (Point2D(-2*sqrt(2), 0), Point2D(2*sqrt(2), 0))

        r>   r   N)r7   r8   r9   r   rS   minorr%   )r2   rN   ZhrZvrfdr4   r4   r5   rg     s    

zEllipse.focic             C   s   t | j| jd S )a  The focal distance of the ellipse.

        The distance between the center and one focus.

        Returns
        =======

        focus_distance : number

        See Also
        ========

        foci

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.focus_distance
        2*sqrt(2)

        r   )r%   rd   r7   rg   )r2   r4   r4   r5   rc     s    zEllipse.focus_distancec             C   s
   | j d S )a^  The horizontal radius of the ellipse.

        Returns
        =======

        hradius : number

        See Also
        ========

        vradius, major, minor

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.hradius
        3

        r"   )r`   )r2   r4   r4   r5   r8     s    zEllipse.hradiusc          	      s*  t ddd}t ddd}t tr6 | kr0 gS g S nt ttfr| ||}t|t jd  jd ||g||g}t	t
 fdd|D S t tr | S t ttfr  | kr| S | ||}t	t
d	d t| ||g||gD S n&t trtd
ntdt  dS )aI  The intersection of this ellipse and another geometrical entity
        `o`.

        Parameters
        ==========

        o : GeometryEntity

        Returns
        =======

        intersection : list of GeometryEntity objects

        Notes
        -----
        Currently supports intersections with Point, Line, Segment, Ray,
        Circle and Ellipse types.

        See Also
        ========

        sympy.geometry.entity.GeometryEntity

        Examples
        ========

        >>> from sympy import Ellipse, Point, Line, sqrt
        >>> e = Ellipse(Point(0, 0), 5, 7)
        >>> e.intersection(Point(0, 0))
        []
        >>> e.intersection(Point(5, 0))
        [Point2D(5, 0)]
        >>> e.intersection(Line(Point(0,0), Point(0, 1)))
        [Point2D(0, -7), Point2D(0, 7)]
        >>> e.intersection(Line(Point(5,0), Point(5, 1)))
        [Point2D(5, 0)]
        >>> e.intersection(Line(Point(6,0), Point(6, 1)))
        []
        >>> e = Ellipse(Point(-1, 0), 4, 3)
        >>> e.intersection(Ellipse(Point(1, 0), 4, 3))
        [Point2D(0, -3*sqrt(15)/4), Point2D(0, 3*sqrt(15)/4)]
        >>> e.intersection(Ellipse(Point(5, 0), 4, 3))
        [Point2D(2, -3*sqrt(7)/4), Point2D(2, 3*sqrt(7)/4)]
        >>> e.intersection(Ellipse(Point(100500, 0), 4, 3))
        []
        >>> e.intersection(Ellipse(Point(0, 0), 3, 4))
        [Point2D(3, 0), Point2D(-363/175, -48*sqrt(111)/175), Point2D(-363/175, 48*sqrt(111)/175)]
        >>> e.intersection(Ellipse(Point(-1, 0), 3, 4))
        [Point2D(-17/5, -12/5), Point2D(-17/5, 12/5), Point2D(7/5, -12/5), Point2D(7/5, 12/5)]
        r,   T)r-   r.   r   r"   c                s   g | ]}| krt |qS r4   )r%   )rW   i)r3   r4   r5   rf   w  s    z(Ellipse.intersection.<locals>.<listcomp>c             S   s   g | ]}t |qS r4   )r%   )rW   rs   r4   r4   r5   rf     s    z5Entity must be two dimensional, not three dimensionalzIntersection not handled for %sN)r   r/   r%   r   r   r0   r   r(   pointsrD   r   Polygonintersectionr+   r   r   	TypeErrorr!   )r2   r3   r,   r.   Zellipse_equationresultr4   )r3   r5   rv   7  s(    4
,

.
zEllipse.intersectionc                sz  t trdS t trT t  tr0dS  rLtfdd D S dS n"t trptdkS t tr t dkr d jko	j S dS nt t
tfrLd}t trֈjng}xj|D ]b}| t dkr@t fdd|jD s:tfdd|jD r:d}qndS q|S qW |S t ttfrftd	ntd
t dS )a  Is `o` tangent to the ellipse?

        Parameters
        ==========

        o : GeometryEntity
            An Ellipse, LinearEntity or Polygon

        Raises
        ======

        NotImplementedError
            When the wrong type of argument is supplied.

        Returns
        =======

        is_tangent: boolean
            True if o is tangent to the ellipse, False otherwise.

        See Also
        ========

        tangent_lines

        Examples
        ========

        >>> from sympy import Point, Ellipse, Line
        >>> p0, p1, p2 = Point(0, 0), Point(3, 0), Point(3, 3)
        >>> e1 = Ellipse(p0, 3, 2)
        >>> l1 = Line(p1, p2)
        >>> e1.is_tangent(l1)
        True

        FTc             3   s,   | ]$} |d    |d  V  qdS )r   N)tangent_linesZequals)rW   rs   )r3   r2   r4   r5   rY     s    z%Ellipse.is_tangent.<locals>.<genexpr>r"   r   c             3   s   | ]} d  |kV  qdS )r   Nr4   )rW   rs   )	intersectr4   r5   rY     s    c             3   s   | ]}  | V  qd S )N)rk   )rW   rs   )r2   r4   r5   rY     s    z5Entity must be two dimensional, not three dimensionalzIs_tangent not handled for %sN)r/   r&   r+   rv   allr   rA   r   sourcerk   r   ru   Zsidesanyrt   r   r'   rw   r!   )r2   r3   Zall_tangentsZsegmentsZsegmentr4   )rz   r3   r2   r5   
is_tangent  s@    %









zEllipse.is_tangentc             C   sT   | j dd }t|dkr"|d S |\}}|| dk }|dkrB|S |dkrN|S | jS )a  Longer axis of the ellipse (if it can be determined) else hradius.

        Returns
        =======

        major : number or expression

        See Also
        ========

        hradius, vradius, minor

        Examples
        ========

        >>> from sympy import Point, Ellipse, Symbol
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.major
        3

        >>> a = Symbol('a')
        >>> b = Symbol('b')
        >>> Ellipse(p1, a, b).major
        a
        >>> Ellipse(p1, b, a).major
        b

        >>> m = Symbol('m')
        >>> M = m + 1
        >>> Ellipse(p1, m, M).major
        m + 1

        r"   rn   r   TF)r`   rA   r8   )r2   ababr3   r4   r4   r5   rS     s    $zEllipse.majorc             C   sT   | j dd }t|dkr"|d S |\}}|| dk }|dkrB|S |dkrN|S | jS )a  Shorter axis of the ellipse (if it can be determined) else vradius.

        Returns
        =======

        minor : number or expression

        See Also
        ========

        hradius, vradius, major

        Examples
        ========

        >>> from sympy import Point, Ellipse, Symbol
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.minor
        1

        >>> a = Symbol('a')
        >>> b = Symbol('b')
        >>> Ellipse(p1, a, b).minor
        b
        >>> Ellipse(p1, b, a).minor
        a

        >>> m = Symbol('m')
        >>> M = m + 1
        >>> Ellipse(p1, m, M).minor
        m

        r"   rn   r   TF)r`   rA   r9   )r2   r   r   r   r3   r4   r4   r5   rq     s    $zEllipse.minorc          
      s  t |dd}g }|j| jjkr2|t| jtd |j| jjkrT|t| jdd |r\|S tdddtddd |  t	 }d	| t|fj
}| }t|d } | d  }t|jd
krByt| }	W n2 tttfk
r(   tt|ddd }	Y nX  fdd|	D }
ntdfdd|
D }dk	rfdd|
D }
fdd|D }dd t|
|D S )aG  Normal lines between `p` and the ellipse.

        Parameters
        ==========

        p : Point

        Returns
        =======

        normal_lines : list with 1, 2 or 4 Lines

        Examples
        ========

        >>> from sympy import Line, Point, Ellipse
        >>> e = Ellipse((0, 0), 2, 3)
        >>> c = e.center
        >>> e.normal_lines(c + Point(1, 0))
        [Line2D(Point2D(0, 0), Point2D(1, 0))]
        >>> e.normal_lines(c)
        [Line2D(Point2D(0, 0), Point2D(0, 1)), Line2D(Point2D(0, 0), Point2D(1, 0))]

        Off-axis points require the solution of a quartic equation. This
        often leads to very large expressions that may be of little practical
        use. An approximate solution of `prec` digits can be obtained by
        passing in the desired value:

        >>> e.normal_lines((3, 3), prec=2)
        [Line2D(Point2D(-0.81, -2.7), Point2D(0.19, -1.2)),
        Line2D(Point2D(1.5, -2.0), Point2D(2.5, -2.7))]

        Whereas the above solution has an operation count of 12, the exact
        solution has an operation count of 2020.
        r>   )r?   )sloper   r,   T)r-   r.   r"   )Z	separatedc          	      s(   g | ] }t |t |d  qS )r   )r%   r   r1   )rW   rs   )eqr,   r.   r4   r5   rf   w  s    z(Ellipse.normal_lines.<locals>.<listcomp>z7intersections for the general ellipse are not supportedc                s"   g | ]}  tf|jqS r4   )r1   zipr`   )rW   pt)normr,   r.   r4   r5   rf   {  s    Nc                s   g | ]}|  qS r4   )n)rW   r   )precr4   r5   rf   }  s    c                s"   g | ]}t |r|n| qS r4   )r   r   )rW   rs   )r   r4   r5   rf   ~  s    c             S   s   g | ]\}}t ||d qS ))r   )r(   )rW   r   sr4   r4   r5   rf     s    )r%   r,   r7   appendr(   r	   r.   r   r0   r*   r   r   r1   Zas_numer_denomexpandrA   rZ   r   Z
real_rootsr   r   ro   r   r   )r2   re   r   rvdydxr   seqZyisZxeqZxsolrt   Zslopesr4   )r   r   r   r,   r.   r5   normal_lines0  s:    $
zEllipse.normal_linesc             C   s   | j d| j  S )a  The periapsis of the ellipse.

        The shortest distance between the focus and the contour.

        Returns
        =======

        periapsis : number

        See Also
        ========

        apoapsis : Returns greatest distance between focus and contour

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.periapsis
        -2*sqrt(2) + 3

        r"   )rS   rI   )r2   r4   r4   r5   	periapsis  s    zEllipse.periapsisc             C   s   | j d| jd   S )a=  
        Calculates the semi-latus rectum of the Ellipse.

        Semi-latus rectum is defined as one half of the the chord through a
        focus parallel to the conic section directrix of a conic section.

        Returns
        =======

        semilatus_rectum : number

        See Also
        ========

        apoapsis : Returns greatest distance between focus and contour

        periapsis : The shortest distance between the focus and the contour

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.semilatus_rectum
        1/3

        References
        ==========

        [1] http://mathworld.wolfram.com/SemilatusRectum.html
        [2] https://en.wikipedia.org/wiki/Ellipse#Semi-latus_rectum

        r"   r>   )rS   rI   )r2   r4   r4   r5   semilatus_rectum  s    $zEllipse.semilatus_rectumc             C   s   t |dd}|tj tjgS )a  The plot interval for the default geometric plot of the Ellipse.

        Parameters
        ==========

        parameter : str, optional
            Default value is 't'.

        Returns
        =======

        plot_interval : list
            [parameter, lower_bound, upper_bound]

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.plot_interval()
        [t, -pi, pi]

        T)r-   )r   r   r]   )r2   r[   rU   r4   r4   r5   plot_interval  s    zEllipse.plot_intervalc             C   s   ddl m}m}m} tddd}| |j\}}|dk	rDt|}nt}|| }	d|	 d }
t	d|
d  }t
||||
||||S )	aY  A random point on the ellipse.

        Returns
        =======

        point : Point

        Examples
        ========

        >>> from sympy import Point, Ellipse, Segment
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.random_point() # gives some random point
        Point2D(...)
        >>> p1 = e1.random_point(seed=0); p1.n(2)
        Point2D(2.1, 1.4)

        Notes
        =====

        When creating a random point, one may simply replace the
        parameter with a random number. When doing so, however, the
        random number should be made a Rational or else the point
        may not test as being in the ellipse:

        >>> from sympy.abc import t
        >>> from sympy import Rational
        >>> arb = e1.arbitrary_point(t); arb
        Point2D(3*cos(t), 2*sin(t))
        >>> arb.subs(t, .1) in e1
        False
        >>> arb.subs(t, Rational(.1)) in e1
        True
        >>> arb.subs(t, Rational('.1')) in e1
        True

        See Also
        ========
        sympy.geometry.point.Point
        arbitrary_point : Returns parameterized point on ellipse
        r   )r   r   r   rU   T)r-   Nr>   r"   )Zsympyr   r   r   r   r\   r`   randomZRandomr   r%   r1   )r2   Zseedr   r   r   rU   r,   r.   rngrrN   r   r4   r4   r5   random_point  s    *zEllipse.random_pointc                s    j dtfkr2j}| }|j jS  fdddD \}}||}t|| }|j	t
||f|jdd}ttddt|t|t|f  d	S )
a  Override GeometryEntity.reflect since the radius
        is not a GeometryEntity.

        Examples
        ========

        >>> from sympy import Circle, Line
        >>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
        Circle(Point2D(1, 0), -1)
        >>> from sympy import Ellipse, Line, Point
        >>> Ellipse(Point(3, 4), 1, 3).reflect(Line(Point(0, -4), Point(5, 0)))
        Traceback (most recent call last):
        ...
        NotImplementedError:
        General Ellipse is not supported but the equation of the reflected
        Ellipse is given by the zeros of: f(x, y) = (9*x/41 + 40*y/41 +
        37/41)**2 + (40*x/123 - 3*y/41 - 364/123)**2 - 1

        Notes
        =====

        Until the general ellipse (with no axis parallel to the x-axis) is
        supported a NotImplemented error is raised and the equation whose
        zeros define the rotated ellipse is given.

        r   c                s   g | ]}t | fd dqS )T)r-   )r   )rW   rV   )liner2   r4   r5   rf   ;  s   z#Ellipse.reflect.<locals>.<listcomp>ZxyT)ZsimultaneouszeGeneral Ellipse is not supported but the equation of the reflected Ellipse is given by the zeros of: zf(%s, %s) = %sN)r   r	   r7   reflectfuncr8   r9   r0   r%   r1   r   r`   ro   r    str)r2   r   rN   r,   r.   exprre   rx   r4   )r   r2   r5   r     s    
zEllipse.reflectr   c                sz   | j | jkr$| | j||| j S |tj jrBtt	| ||S d| tj jrn| | j||| j| j S t
ddS )a  Rotate ``angle`` radians counterclockwise about Point ``pt``.

        Note: since the general ellipse is not supported, only rotations that
        are integer multiples of pi/2 are allowed.

        Examples
        ========

        >>> from sympy import Ellipse, pi
        >>> Ellipse((1, 0), 2, 1).rotate(pi/2)
        Ellipse(Point2D(0, 1), 1, 2)
        >>> Ellipse((1, 0), 2, 1).rotate(pi)
        Ellipse(Point2D(-1, 0), 2, 1)
        r>   z;Only rotations of pi/2 are currently supported for Ellipse.N)r8   r9   r   r7   rotater   r]   
is_integerr;   r+   ro   )r2   Zangler   )r=   r4   r5   r   F  s    zEllipse.rotater"   c             C   s`   | j }|r4t|dd}| j| j ||j|j S | j}| j}| j||||| || dS )at  Override GeometryEntity.scale since it is the major and minor
        axes which must be scaled and they are not GeometryEntities.

        Examples
        ========

        >>> from sympy import Ellipse
        >>> Ellipse((0, 0), 2, 1).scale(2, 4)
        Circle(Point2D(0, 0), 4)
        >>> Ellipse((0, 0), 2, 1).scale(2)
        Ellipse(Point2D(0, 0), 4, 1)
        r>   )r?   )r8   r9   )r7   r%   	translater`   scaler8   r9   r   )r2   r,   r.   r   rN   rO   rP   r4   r4   r5   r   _  s    zEllipse.scalec             C   s  t |dd}| |rg S || krx| j| }| jd |j }| jd  |j }t t|j| t|j| }t||gS t	| j
dkr| j
\}}| j}d| t || t || }	n| jt | j| }	|	jr|	jrg S tdtd }
}| |
|}t|||
}t|t |
|j}t|| |g|
|g}t	|dkr|d d |jksh|d d |jkshtt||t dd t||t dd gS t||d t||d gS dS )a`  Tangent lines between `p` and the ellipse.

        If `p` is on the ellipse, returns the tangent line through point `p`.
        Otherwise, returns the tangent line(s) from `p` to the ellipse, or
        None if no tangent line is possible (e.g., `p` inside ellipse).

        Parameters
        ==========

        p : Point

        Returns
        =======

        tangent_lines : list with 1 or 2 Lines

        Raises
        ======

        NotImplementedError
            Can only find tangent lines for a point, `p`, on the ellipse.

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.line.Line

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.tangent_lines(Point(3, 0))
        [Line2D(Point2D(3, 0), Point2D(3, -12))]

        r>   )r?   r,   r.   r"   r   N)r%   rk   r7   r9   r,   r8   r.   r   r(   rA   rg   rd   rh   Z	is_numberri   r   r0   r*   r   r   AssertionError)r2   re   ZdeltaZriserunZp2f1f2Zmajrj   r,   r.   r   r   r   Ztangent_pointsr4   r4   r5   ry   u  s8    %


&(zEllipse.tangent_linesc             C   s
   | j d S )a\  The vertical radius of the ellipse.

        Returns
        =======

        vradius : number

        See Also
        ========

        hradius, major, minor

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.vradius
        1

        r>   )r`   )r2   r4   r4   r5   r9     s    zEllipse.vradiusc             C   s   t j| j | jd  d }t j| jd  | j d }d}|dkrJ|||fS || j|d | jj d   }|| j|d | jj d   }|| j|d | jj  |d | jj   }|||fS )a  Returns the second moment and product moment area of an ellipse.

        Parameters
        ==========

        point : Point, two-tuple of sympifiable objects, or None(default=None)
            point is the point about which second moment of area is to be found.
            If "point=None" it will be calculated about the axis passing through the
            centroid of the ellipse.

        Returns
        =======

        I_xx, I_yy, I_xy : number or sympy expression
            I_xx, I_yy are second moment of area of an ellise.
            I_xy is product moment of area of an ellipse.

        Examples
        ========

        >>> from sympy import Point, Ellipse
        >>> p1 = Point(0, 0)
        >>> e1 = Ellipse(p1, 3, 1)
        >>> e1.second_moment_of_area()
        (3*pi/4, 27*pi/4, 0)

        References
        ==========

        https://en.wikipedia.org/wiki/List_of_second_moments_of_area

        rn   ra   r   Nr"   r>   )r   r]   r8   r9   r^   r7   r.   r,   )r2   pointZI_xxZI_yyZI_xyr4   r4   r5   second_moment_of_area  s    "
*zEllipse.second_moment_of_area)NNNN)rK   rL   )rU   )r,   r.   )r,   r.   )N)rU   )N)r   N)r"   r"   N)N)(__name__
__module____qualname____doc__r6   r:   r<   rG   rQ   propertyrR   rT   r\   r^   r_   r7   rb   rI   rk   r0   rp   rg   rc   r8   rv   r~   rS   rq   r   r   r   r   r   r   r   r   ry   r9   r   __classcell__r4   r4   )r=   r5   r+   #   sF   @


)
5
$
 -PK//
R'

9,
Or+   c               @   s`   e Zd ZdZdd Zedd Zddd	Zd
d Zedd Z	dd Z
dddZedd ZdS )rF   a%  A circle in space.

    Constructed simply from a center and a radius, or from three
    non-collinear points.

    Parameters
    ==========

    center : Point
    radius : number or sympy expression
    points : sequence of three Points

    Attributes
    ==========

    radius (synonymous with hradius, vradius, major and minor)
    circumference
    equation

    Raises
    ======

    GeometryError
        When trying to construct circle from three collinear points.
        When trying to construct circle from incorrect parameters.

    See Also
    ========

    Ellipse, sympy.geometry.point.Point

    Examples
    ========

    >>> from sympy.geometry import Point, Circle
    >>> # a circle constructed from a center and radius
    >>> c1 = Circle(Point(0, 0), 5)
    >>> c1.hradius, c1.vradius, c1.radius
    (5, 5, 5)

    >>> # a circle constructed from three points
    >>> c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
    >>> c2.hradius, c2.vradius, c2.radius, c2.center
    (sqrt(2)/2, sqrt(2)/2, sqrt(2)/2, Point2D(1/2, 1/2))

    c             O   s   d\}}t |dkrVdd |D }tj| r4tdddlm} || }|j}|j}n(t |dkr~t|d	 dd
}t|d }|d ks|d kst	j
| ||f|S tdd S )N)NNrn   c             S   s   g | ]}t |d dqS )r>   )r?   )r%   )rW   r   r4   r4   r5   rf   C  s    z"Circle.__new__.<locals>.<listcomp>z5Cannot construct a circle from three collinear pointsr"   )Triangler>   r   )r?   z)Circle.__new__ received unknown arguments)rA   r%   Zis_collinearr   polygonr   ZcircumcenterZcircumradiusr   r#   rG   )rH   r`   rJ   rN   r   r   rU   r4   r4   r5   rG   @  s     
zCircle.__new__c             C   s   dt j | j S )a"  The circumference of the circle.

        Returns
        =======

        circumference : number or SymPy expression

        Examples
        ========

        >>> from sympy import Point, Circle
        >>> c1 = Circle(Point(3, 4), 6)
        >>> c1.circumference
        12*pi

        r>   )r   r]   rh   )r2   r4   r4   r5   rb   U  s    zCircle.circumferencer,   r.   c             C   sJ   t |dd}t |dd}|| jj d }|| jj d }|| | jd  S )a  The equation of the circle.

        Parameters
        ==========

        x : str or Symbol, optional
            Default value is 'x'.
        y : str or Symbol, optional
            Default value is 'y'.

        Returns
        =======

        equation : SymPy expression

        Examples
        ========

        >>> from sympy import Point, Circle
        >>> c1 = Circle(Point(0, 0), 5)
        >>> c1.equation()
        x**2 + y**2 - 25

        T)r-   r>   )r   r7   r,   r.   rS   )r2   r,   r.   rl   rm   r4   r4   r5   r0   i  s
    zCircle.equationc             C   s   t | |S )a  The intersection of this circle with another geometrical entity.

        Parameters
        ==========

        o : GeometryEntity

        Returns
        =======

        intersection : list of GeometryEntities

        Examples
        ========

        >>> from sympy import Point, Circle, Line, Ray
        >>> p1, p2, p3 = Point(0, 0), Point(5, 5), Point(6, 0)
        >>> p4 = Point(5, 0)
        >>> c1 = Circle(p1, 5)
        >>> c1.intersection(p2)
        []
        >>> c1.intersection(p4)
        [Point2D(5, 0)]
        >>> c1.intersection(Ray(p1, p2))
        [Point2D(5*sqrt(2)/2, 5*sqrt(2)/2)]
        >>> c1.intersection(Line(p2, p3))
        []

        )r+   rv   )r2   r3   r4   r4   r5   rv     s    zCircle.intersectionc             C   s
   | j d S )at  The radius of the circle.

        Returns
        =======

        radius : number or sympy expression

        See Also
        ========

        Ellipse.major, Ellipse.minor, Ellipse.hradius, Ellipse.vradius

        Examples
        ========

        >>> from sympy import Point, Circle
        >>> c1 = Circle(Point(3, 4), 6)
        >>> c1.radius
        6

        r"   )r`   )r2   r4   r4   r5   rh     s    zCircle.radiusc             C   s    | j }||}| || j S )a  Override GeometryEntity.reflect since the radius
        is not a GeometryEntity.

        Examples
        ========

        >>> from sympy import Circle, Line
        >>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
        Circle(Point2D(1, 0), -1)
        )r7   r   r   rh   )r2   r   rN   r4   r4   r5   r     s    
zCircle.reflectr"   Nc             C   s   | j }|r4t|dd}| j| j ||j|j S |||}dd ||fD \}}||krp| ||| j S | j }}t||| || dS )a;  Override GeometryEntity.scale since the radius
        is not a GeometryEntity.

        Examples
        ========

        >>> from sympy import Circle
        >>> Circle((0, 0), 1).scale(2, 2)
        Circle(Point2D(0, 0), 2)
        >>> Circle((0, 0), 1).scale(2, 4)
        Ellipse(Point2D(0, 0), 2, 4)
        r>   )r?   c             S   s   g | ]}t |qS r4   )abs)rW   rs   r4   r4   r5   rf     s    z Circle.scale.<locals>.<listcomp>)r8   r9   )r7   r%   r   r`   r   r   rh   r+   )r2   r,   r.   r   rN   rO   rP   r4   r4   r5   r     s    
zCircle.scalec             C   s
   t | jS )a  
        This Ellipse property is an alias for the Circle's radius.

        Whereas hradius, major and minor can use Ellipse's conventions,
        the vradius does not exist for a circle. It is always a positive
        value in order that the Circle, like Polygons, will have an
        area that can be positive or negative as determined by the sign
        of the hradius.

        Examples
        ========

        >>> from sympy import Point, Circle
        >>> c1 = Circle(Point(3, 4), 6)
        >>> c1.vradius
        6
        )r   rh   )r2   r4   r4   r5   r9     s    zCircle.vradius)r,   r.   )r"   r"   N)r   r   r   r   rG   r   rb   r0   rv   rh   r   r   r9   r4   r4   r4   r5   rF     s   .
 
rF   )ru   )Br   Z
__future__r   r   Z
sympy.corer   r   r   Zsympy.core.logicr   Zsympy.core.numbersr   r	   Zsympy.core.compatibilityr
   r   Zsympy.core.symbolr   r   r   Zsympy.simplifyr   r   Z(sympy.functions.elementary.miscellaneousr   Z(sympy.functions.elementary.trigonometricr   r   Z*sympy.functions.special.elliptic_integralsr   Zsympy.geometry.exceptionsr   Zsympy.geometry.liner   r   r   r   Zsympy.polysr   r   r   Zsympy.polys.polyutilsr   r   Zsympy.solversr   Zsympy.utilities.miscr    r!   Zentityr#   r$   r   r%   r&   r'   r   r(   r)   utilr*   r   r+   rF   r   ru   r4   r4   r4   r5   <module>   sD            v o