B
    [(                 @   s   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ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mZmZ dd
lmZ G dd deZdS )z4Parabolic geometrical entity.

Contains
* Parabola

    )divisionprint_function)S)ordered)_symbol)symbolssimplifysolve)GeometryEntityGeometrySet)PointPoint2D)LineLine2DRay2D	Segment2DLinearEntity3D)Ellipsec               @   s   e Zd ZdZdddZedd Zedd Zed	d
 Zedd Z	dddZ
edd Zedd Zdd Zedd Zedd ZdS )Parabolaa  A parabolic GeometryEntity.

    A parabola is declared with a point, that is called 'focus', and
    a line, that is called 'directrix'.
    Only vertical or horizontal parabolas are currently supported.

    Parameters
    ==========

    focus : Point
        Default value is Point(0, 0)
    directrix : Line

    Attributes
    ==========

    focus
    directrix
    axis of symmetry
    focal length
    p parameter
    vertex
    eccentricity

    Raises
    ======
    ValueError
        When `focus` is not a two dimensional point.
        When `focus` is a point of directrix.
    NotImplementedError
        When `directrix` is neither horizontal nor vertical.

    Examples
    ========

    >>> from sympy import Parabola, Point, Line
    >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7,8)))
    >>> p1.focus
    Point2D(0, 0)
    >>> p1.directrix
    Line2D(Point2D(5, 8), Point2D(7, 8))

    Nc             K   sf   |rt |dd}n
t dd}t|}|jdkrB|jtjkrBtd||rTtdtj	| ||f|S )N   )Zdimr   z3The directrix must be a horizontal or vertical linez*The focus must not be a point of directrix)
r   r   sloper   ZInfinityNotImplementedErrorcontains
ValueErrorr
   __new__)clsfocus	directrixkwargs r   6lib/python3.7/site-packages/sympy/geometry/parabola.pyr   @   s    

zParabola.__new__c             C   s   t dS )aX  Returns the ambient dimension of parabola.

        Returns
        =======

        ambient_dimension : integer

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> f1 = Point(0, 0)
        >>> p1 = Parabola(f1, Line(Point(5, 8), Point(7, 8)))
        >>> p1.ambient_dimension
        2

        r   )r   )selfr   r   r    ambient_dimensionQ   s    zParabola.ambient_dimensionc             C   s   | j | jS )a  The axis of symmetry of the parabola.

        Returns
        =======

        axis_of_symmetry : Line

        See Also
        ========

        sympy.geometry.line.Line

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.axis_of_symmetry
        Line2D(Point2D(0, 0), Point2D(0, 1))

        )r   Zperpendicular_liner   )r!   r   r   r    axis_of_symmetryf   s    zParabola.axis_of_symmetryc             C   s
   | j d S )a  The directrix of the parabola.

        Returns
        =======

        directrix : Line

        See Also
        ========

        sympy.geometry.line.Line

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> l1 = Line(Point(5, 8), Point(7, 8))
        >>> p1 = Parabola(Point(0, 0), l1)
        >>> p1.directrix
        Line2D(Point2D(5, 8), Point2D(7, 8))

           )args)r!   r   r   r    r      s    zParabola.directrixc             C   s   t dS )a  The eccentricity of the parabola.

        Returns
        =======

        eccentricity : number

        A parabola may also be characterized as a conic section with an
        eccentricity of 1. As a consequence of this, all parabolas are
        similar, meaning that while they can be different sizes,
        they are all the same shape.

        See Also
        ========

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


        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.eccentricity
        1

        Notes
        -----
        The eccentricity for every Parabola is 1 by definition.

        r$   )r   )r!   r   r   r    eccentricity   s    !zParabola.eccentricityxyc             C   sz   t |dd}t |dd}| jjdkrLd| j || jj  }|| jj d }n&d| j || jj  }|| jj d }|| S )az  The equation of the parabola.

        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 Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.equation()
        -x**2 - 16*y + 64
        >>> p1.equation('f')
        -f**2 - 16*y + 64
        >>> p1.equation(y='z')
        -x**2 - 16*z + 64

        T)realr      r   )r   r#   r   p_parametervertexr'   r(   )r!   r'   r(   Zt1Zt2r   r   r    equation   s    zParabola.equationc             C   s   | j | j}|d }|S )aY  The focal length of the parabola.

        Returns
        =======

        focal_lenght : number or symbolic expression

        Notes
        =====

        The distance between the vertex and the focus
        (or the vertex and directrix), measured along the axis
        of symmetry, is the "focal length".

        See Also
        ========

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

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.focal_length
        4

        r   )r   distancer   )r!   r.   focal_lengthr   r   r    r/      s    zParabola.focal_lengthc             C   s
   | j d S )a  The focus of the parabola.

        Returns
        =======

        focus : Point

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> f1 = Point(0, 0)
        >>> p1 = Parabola(f1, Line(Point(5, 8), Point(7, 8)))
        >>> p1.focus
        Point2D(0, 0)

        r   )r%   )r!   r   r   r    r     s    zParabola.focusc                sD  t ddd\}}|  }t trZ | kr0 gS ttdd t|  g||gD S nt trt|	| j
d f| j
d fgdkr gS g S nt ttfrt|t jd  jd  g||g}tt fdd|D S t ttfr"ttd	d t|  g||gD S t tr8td
ntddS )a  The intersection of the parabola and another geometrical entity `o`.

        Parameters
        ==========

        o : GeometryEntity, LinearEntity

        Returns
        =======

        intersection : list of GeometryEntity objects

        Examples
        ========

        >>> from sympy import Parabola, Point, Ellipse, Line, Segment
        >>> p1 = Point(0,0)
        >>> l1 = Line(Point(1, -2), Point(-1,-2))
        >>> parabola1 = Parabola(p1, l1)
        >>> parabola1.intersection(Ellipse(Point(0, 0), 2, 5))
        [Point2D(-2, 0), Point2D(2, 0)]
        >>> parabola1.intersection(Line(Point(-7, 3), Point(12, 3)))
        [Point2D(-4, 3), Point2D(4, 3)]
        >>> parabola1.intersection(Segment((-12, -65), (14, -68)))
        []

        zx yT)r)   c             S   s   g | ]}t |qS r   )r   ).0ir   r   r    
<listcomp>B  s    z)Parabola.intersection.<locals>.<listcomp>r   r$   c                s   g | ]}| krt |qS r   )r   )r0   r1   )or   r    r2   J  s    c             S   s   g | ]}t |qS r   )r   )r0   r1   r   r   r    r2   L  s    z5Entity must be two dimensional, not three dimensionalzWrong type of argument were putN)r   r-   
isinstancer   listr   r	   r   r   ZsubsZ_argsr   r   r   Zpointsr   r   	TypeError)r!   r3   r'   r(   Zparabola_eqresultr   )r3   r    intersection   s$    
*
*((
zParabola.intersectionc             C   sn   | j jdkr<| jjd  }|| jjd k r2| j}qj| j }n.| jjd  }|| jjd krd| j }n| j}|S )a	  P is a parameter of parabola.

        Returns
        =======

        p : number or symbolic expression

        Notes
        =====

        The absolute value of p is the focal length. The sign on p tells
        which way the parabola faces. Vertical parabolas that open up
        and horizontal that open right, give a positive value for p.
        Vertical parabolas that open down and horizontal that open left,
        give a negative value for p.


        See Also
        ========

        http://www.sparknotes.com/math/precalc/conicsections/section2.rhtml

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.p_parameter
        -4

        r   r   r$   )r#   r   r   Zcoefficientsr   r%   r/   )r!   r'   pr(   r   r   r    r+   R  s    !

zParabola.p_parameterc             C   sP   | j }| jjdkr0t|jd | j |jd }nt|jd |jd | j }|S )ap  The vertex of the parabola.

        Returns
        =======

        vertex : Point

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Parabola, Point, Line
        >>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
        >>> p1.vertex
        Point2D(0, 4)

        r   r$   )r   r#   r   r   r%   r+   )r!   r   r,   r   r   r    r,     s
    zParabola.vertex)NN)r'   r(   )__name__
__module____qualname____doc__r   propertyr"   r#   r   r&   r-   r/   r   r8   r+   r,   r   r   r   r    r      s   +
#
'#20r   N)r=   Z
__future__r   r   Z
sympy.corer   Zsympy.core.compatibilityr   Zsympy.core.symbolr   Zsympyr   r   r	   Zsympy.geometry.entityr
   r   Zsympy.geometry.pointr   r   Zsympy.geometry.liner   r   r   r   r   Zsympy.geometry.ellipser   r   r   r   r   r    <module>   s   