U
    ZÊ¹jÓ)  ã                   @   s¬   d Z ddl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 ddlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ G dd„ de
ƒZdS )z4Parabolic geometrical entity.

Contains
* Parabola

é    )ÚS)Úordered)Ú_symbolÚsymbols)ÚGeometryEntityÚGeometrySet)ÚPointÚPoint2D)ÚLineÚLine2DÚRay2DÚ	Segment2DÚLinearEntity3D)ÚEllipse)Úsign)Úsimplify)Úsolvec                   @   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   sH   |rt |dd�}n
t ddƒ}t|ƒ}| |¡r6tdƒ‚tj| ||f|ŽS )Né   )Údimr   z*The focus must not be a point of directrix)r   r
   ÚcontainsÚ
ValueErrorr   Ú__new__)ÚclsÚfocusÚ	directrixÚkwargs© r   úV/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/geometry/parabola.pyr   A   s    

zParabola.__new__c                 C   s   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_dimensionO   s    zParabola.ambient_dimensionc                 C   s   | j  | j¡S )aò  Return the axis of symmetry of the parabola: a line
        perpendicular to the directrix passing through the focus.

        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_symmetryd   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))

        é   ©Úargsr   r   r   r   r   ~   s    zParabola.directrixc                 C   s   t j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   ZOner   r   r   r   Úeccentricity˜   s    !zParabola.eccentricityÚxÚyc           
      C   sâ   t |dd�}t |dd�}| jj}|tjkrRd| j || jj  }|| jj d }nˆ|dkr‚d| j || jj  }|| jj d }nX| j	\}}| jj
dd… \}}	|| d || d  }| j ||¡d |d |	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©Úrealé   r   r   N)r   r   Úsloper   ÚInfinityÚp_parameterÚvertexr'   r(   r   ÚcoefficientsÚequation)
r    r'   r(   ÚmÚt1Út2ÚaÚbÚcÚdr   r   r   r1   »   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    r9   Ú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                    s^  t ddd�\}}|  ¡ }tˆ tƒrbˆ | kr0ˆ gS ttdd„ t|ˆ  ¡ g||gdd�d D ƒƒƒS nøtˆ tƒr¢t| 	|ˆ j
d f|ˆ j
d fg¡ƒdkrœˆ gS g S n¸tˆ ttfƒ� rüt|tˆ jd ˆ jd ƒ ¡ g||gdd�d }tt‡ fd	d„|D ƒƒƒS tˆ ttfƒ�r<ttd
d„ t|ˆ  ¡ g||gdd�d D ƒƒƒS tˆ tƒ�rRt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 yTr)   c                 S   s   g | ]}t |ƒ‘qS r   )r   ©Ú.0Úir   r   r   Ú
<listcomp>F  s     z)Parabola.intersection.<locals>.<listcomp>)Úsetr#   r   c                    s   g | ]}|ˆ krt |ƒ‘qS r   ©r	   r;   ©Úor   r   r>   Q  s      c                 S   s   g | ]}t |ƒ‘qS r   r@   r;   r   r   r   r>   S  s     z5Entity must be two dimensional, not three dimensionalzWrong type of argument were putN)r   r1   Ú
isinstancer   Úlistr   r   r	   r   ÚsubsÚ_argsr   r   r   Zpointsr   r   Ú	TypeError)r    rB   r'   r(   Zparabola_eqÚresultr   rA   r   Úintersection$  sJ    

  ÿÿ
*ÿ þþ
  ÿÿ
zParabola.intersectionc                 C   sˆ   | j j}|tjkr4| j jd }t| jjd | ƒ}nJ|dkr^| j jd }t| jjd | ƒ}n | j  | j¡}t| jj	|j	 ƒ}|| 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
        ========

        https://www.sparknotes.com/math/precalc/conicsections/section2/

        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   r-   r0   r   r   r%   Z
projectionr'   r:   )r    r2   r'   Úpr(   r8   r   r   r   r.   Z  s    !
zParabola.p_parameterc                 C   sp   | j }| jj}|tjkr6t|jd | j |jd ƒ}n6|dkr\t|jd |jd | j ƒ}n| j 	| ¡d }|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"   rI   )r    r   r2   r/   r   r   r   r/   ‡  s    
zParabola.vertex)NN)r'   r(   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr!   r"   r   r&   r1   r:   r   rI   r.   r/   r   r   r   r   r      s(   ,




"
,
"
6
,r   N)rN   Z
sympy.corer   Zsympy.core.sortingr   Zsympy.core.symbolr   r   Zsympy.geometry.entityr   r   Zsympy.geometry.pointr   r	   Zsympy.geometry.liner
   r   r   r   r   Zsympy.geometry.ellipser   Zsympy.functionsr   Zsympy.simplifyr   Zsympy.solvers.solversr   r   r   r   r   r   Ú<module>   s   