
    wg,                     .   d Z ddlZddl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 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 ddlmZ ddlm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(  G d de&      Z) G d de)      Z* G d de)      Z+y)aD  Geometrical Points.

Contains
========
Point
Point2D
Point3D

When methods of Point require 1 or more points as arguments, they
can be passed as a sequence of coordinates or Points:

>>> from sympy import Point
>>> Point(1, 1).is_collinear((2, 2), (3, 4))
False
>>> Point(1, 1).is_collinear(Point(2, 2), Point(3, 4))
False

    N)SsympifyExpr)Add)Tuple)Float)global_parameters)	nsimplifysimplify)GeometryError)sqrt)im)cossin)Matrix)	Transpose)uniqis_sequence)
filldedent	func_nameUndecidable   )GeometryEntity)prec_to_dpsc                   \   e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zed        Zed        Zed        Zed        Zd Zd Zd Zd(dZd Zd Zd Z ed        Z!d Z"ed        Z#ed        Z$d  Z%ed!        Z&ed"        Z'ed#        Z(d$ Z)d% Z*ed&        Z+y'))Pointa  A point in a n-dimensional Euclidean space.

    Parameters
    ==========

    coords : sequence of n-coordinate values. In the special
        case where n=2 or 3, a Point2D or Point3D will be created
        as appropriate.
    evaluate : if `True` (default), all floats are turn into
        exact types.
    dim : number of coordinates the point should have.  If coordinates
        are unspecified, they are padded with zeros.
    on_morph : indicates what should happen when the number of
        coordinates of a point need to be changed by adding or
        removing zeros.  Possible values are `'warn'`, `'error'`, or
        `ignore` (default).  No warning or error is given when `*args`
        is empty and `dim` is given. An error is always raised when
        trying to remove nonzero coordinates.


    Attributes
    ==========

    length
    origin: A `Point` representing the origin of the
        appropriately-dimensioned space.

    Raises
    ======

    TypeError : When instantiating with anything but a Point or sequence
    ValueError : when instantiating with a sequence with length < 2 or
        when trying to reduce dimensions if keyword `on_morph='error'` is
        set.

    See Also
    ========

    sympy.geometry.line.Segment : Connects two Points

    Examples
    ========

    >>> from sympy import Point
    >>> from sympy.abc import x
    >>> Point(1, 2, 3)
    Point3D(1, 2, 3)
    >>> Point([1, 2])
    Point2D(1, 2)
    >>> Point(0, x)
    Point2D(0, x)
    >>> Point(dim=4)
    Point(0, 0, 0, 0)

    Floats are automatically converted to Rational unless the
    evaluate flag is False:

    >>> Point(0.5, 0.25)
    Point2D(1/2, 1/4)
    >>> Point(0.5, 0.25, evaluate=False)
    Point2D(0.5, 0.25)

    Tc                    |j                  dt        j                        }|j                  dd      }t        |      dk(  r|d   n|}t	        |t
              r+d}t        |      |j                  dt        |            k(  r|S t        |      s,t        t        dj                  t        |                        t        |      dk(  r5|j                  dd       r#t        j                  f|j                  d      z  }t        | }|j                  dt        |            }t        |      d	k  rt        t        d
            t        |      |k7  rcdj                  |t        |      |      }|dk(  rnA|dk(  rt        |      |dk(  rt        j                   |d	       nt        t        d            t#        ||d        rt        d      t#        d |D              rt        d      t%        d |D              st        d      |d | t        j                  f|t        |      z
  z  z   }|rG|j'                  |j)                  t*              D ci c]  }|t-        t/        |d             c}      }t        |      d	k(  rd|d<   t1        |i |S t        |      dk(  rd|d<   t3        |i |S t5        j6                  | g| S c c}w )Nevaluateon_morphignorer   r   Fdimz<
                Expecting sequence of coordinates, not `{}`   z[
                Point requires 2 or more coordinates or
                keyword `dim` > 1.z2Dimension of {} needs to be changed from {} to {}.errorwarn)
stacklevelzf
                        on_morph value should be 'error',
                        'warn' or 'ignore'.z&Nonzero coordinates cannot be removed.c              3   f   K   | ])  }|j                   xr t        |      j                  d u  + yw)FN)	is_numberr   is_zero.0as     Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/geometry/point.py	<genexpr>z Point.__new__.<locals>.<genexpr>   s)     F!q{{5r!u}}55Fs   /1z(Imaginary coordinates are not permitted.c              3   <   K   | ]  }t        |t                y wN)
isinstancer   r)   s     r,   r-   z Point.__new__.<locals>.<genexpr>   s     71:a&7s   z,Coordinates must be valid SymPy expressions.T)rational_nocheck   )getr	   r   lenr0   r   r   	TypeErrorr   formatr   r   Zeror   
ValueErrorwarningsr$   anyallxreplaceatomsr   r   r
   Point2DPoint3Dr   __new__)	clsargskwargsr   r   coordsr!   messagefs	            r,   rA   zPoint.__new__m   s   ::j*;*D*DE::j(3  INa fe$ H6{fjjF<<6"J (?(.y/@(AC D D
 v;!

5$ 7ffYvzz%00FjjF,v;?Z )& ' ( ( v;#()/FS)I 8#W$ ))V#g!4  -/ "0 1 1 vcd|EFFFvFFGHH777JKK 	3V+< == __ ,,u-&/ 8Ia$788&/ 0F
 v;!!%F:F-f--[A!%F:F-f-- %%c3F33&/s   Kc                 ^    t        dgt        |       z        }t         j                  ||       S )z7Returns the distance between this point and the origin.r   )r   r5   distance)selforigins     r,   __abs__zPoint.__abs__   s'    s3t9}%~~fd++    c                    	 t         j                  | t        |d            \  }}t        ||      D cg c]  \  }}t        ||z          }}}t        |d      S # t        $ r t        dj	                  |            w xY wc c}}w )a8  Add other to self by incrementing self's coordinates by
        those of other.

        Notes
        =====

        >>> from sympy import Point

        When sequences of coordinates are passed to Point methods, they
        are converted to a Point internally. This __add__ method does
        not do that so if floating point values are used, a floating
        point result (in terms of SymPy Floats) will be returned.

        >>> Point(1, 2) + (.1, .2)
        Point2D(1.1, 2.2)

        If this is not desired, the `translate` method can be used or
        another Point can be added:

        >>> Point(1, 2).translate(.1, .2)
        Point2D(11/10, 11/5)
        >>> Point(1, 2) + Point(.1, .2)
        Point2D(11/10, 11/5)

        See Also
        ========

        sympy.geometry.point.Point.translate

        Fr   z+Don't know how to add {} and a Point object)r   _normalize_dimensionr6   r   r7   zipr   )rJ   othersor+   brE   s          r,   __add__zPoint.__add__   s    >	]--dE%%4PQDAq /2!Qi8da(1q5/88Ve,,	  	] M T TUZ [\\	] 9s   $A B$Bc                     || j                   v S r/   rC   rJ   items     r,   __contains__zPoint.__contains__   s    tyy  rM   c                     t        |      }| j                  D cg c]  }t        ||z         }}t        |d      S c c}w )z'Divide point's coordinates by a factor.FrO   r   rC   r   r   )rJ   divisorxrE   s       r,   __truediv__zPoint.__truediv__   s>    '"/3yy9!(1W9%99Ve,, :   >c                     t        |t              r+t        | j                        t        |j                        k7  ry| j                  |j                  k(  S )NF)r0   r   r5   rC   rJ   rR   s     r,   __eq__zPoint.__eq__   s9    %'3tyy>S_+LyyEJJ&&rM   c                      | j                   |   S r/   rX   )rJ   keys     r,   __getitem__zPoint.__getitem__   s    yy~rM   c                 ,    t        | j                        S r/   )hashrC   rJ   s    r,   __hash__zPoint.__hash__   s    DIIrM   c                 6    | j                   j                         S r/   )rC   __iter__rj   s    r,   rm   zPoint.__iter__   s    yy!!##rM   c                 ,    t        | j                        S r/   )r5   rC   rj   s    r,   __len__zPoint.__len__   s    499~rM   c                     t        |      }| j                  D cg c]  }t        ||z         }}t        |d      S c c}w )al  Multiply point's coordinates by a factor.

        Notes
        =====

        >>> from sympy import Point

        When multiplying a Point by a floating point number,
        the coordinates of the Point will be changed to Floats:

        >>> Point(1, 2)*0.1
        Point2D(0.1, 0.2)

        If this is not desired, the `scale` method can be used or
        else only multiply or divide by integers:

        >>> Point(1, 2).scale(1.1, 1.1)
        Point2D(11/10, 11/5)
        >>> Point(1, 2)*11/10
        Point2D(11/10, 11/5)

        See Also
        ========

        sympy.geometry.point.Point.scale
        FrO   r]   )rJ   factorr_   rE   s       r,   __mul__zPoint.__mul__   s?    6 .2ii8(1V8$88Ve,, 9ra   c                 $    | j                  |      S )z)Multiply a factor by point's coordinates.)rr   )rJ   rq   s     r,   __rmul__zPoint.__rmul__  s    ||F##rM   c                 Z    | j                   D cg c]  }|  }}t        |d      S c c}w )zNegate the point.FrO   )rC   r   )rJ   r_   rE   s      r,   __neg__zPoint.__neg__  s-    "ii(1"((Ve,, )s   
(c                 4    | |D cg c]  }|  c}z   S c c}w )zPSubtract two points, or subtract a factor from this point's
        coordinates. )rJ   rR   r_   s      r,   __sub__zPoint.__sub__#  s     5)ar))))s   
c                    t        | dd      |j                  d      t        d |D              t        fd|D              rt	        |      S |d<   |j                  dd      |d<   |D cg c]  }t        |fi | c}S c c}w )z~Ensure that points have the same dimension.
        By default `on_morph='warn'` is passed to the
        `Point` constructor._ambient_dimensionNr!   c              3   4   K   | ]  }|j                     y wr/   ambient_dimensionr*   is     r,   r-   z-Point._normalize_dimension.<locals>.<genexpr>3  s     :aa)):s   c              3   <   K   | ]  }|j                   k(    y wr/   r}   )r*   r   r!   s     r,   r-   z-Point._normalize_dimension.<locals>.<genexpr>4  s     :aq""c):s   r   r$   )getattrr4   maxr<   listr   )rB   pointsrD   r   r!   s       @r,   rP   zPoint._normalize_dimension(  s     c/6jj$;:6::C:6::<u#ZZ
F;z,23qa"6"333s   2Bc                  0   t        |       dk(  ryt        j                  | D cg c]  }t        |       c} }|d   }|dd D cg c]  }||z
  	 }}t        |D cg c]  }|j                   c}      }|j                  d       S c c}w c c}w c c}w )ag  The affine rank of a set of points is the dimension
        of the smallest affine space containing all the points.
        For example, if the points lie on a line (and are not all
        the same) their affine rank is 1.  If the points lie on a plane
        but not a line, their affine rank is 2.  By convention, the empty
        set has affine rank -1.r   r   Nc                 l    | j                   rt        | j                  d            dk  S | j                  S )Nr"   g-q=)r'   absnr(   )r_   s    r,   <lambda>z#Point.affine_rank.<locals>.<lambda>M  s-    #$;;CAK% 45II rM   )
iszerofunc)r5   r   rP   r   rC   rank)rC   r   r   rK   ms        r,   affine_rankzPoint.affine_rank:  s     t9> ++-E1eAh-EF&,QRj1!f*11F+qAFF+,vv $>v ? 	? .F1+s   B	BBc                 .    t        | dt        |             S )z$Number of components this point has.r{   )r   r5   rj   s    r,   r~   zPoint.ambient_dimensionP  s     t13t9==rM   c                     t        |      dk  ry | j                  |D cg c]  }t        |       c} }|d   j                  dk(  ryt	        t        |            }t        j                  | dk  S c c}w )a  Return True if there exists a plane in which all the points
        lie.  A trivial True value is returned if `len(points) < 3` or
        all Points are 2-dimensional.

        Parameters
        ==========

        A set of points

        Raises
        ======

        ValueError : if less than 3 unique points are given

        Returns
        =======

        boolean

        Examples
        ========

        >>> from sympy import Point3D
        >>> p1 = Point3D(1, 2, 2)
        >>> p2 = Point3D(2, 7, 2)
        >>> p3 = Point3D(0, 0, 2)
        >>> p4 = Point3D(1, 1, 2)
        >>> Point3D.are_coplanar(p1, p2, p3, p4)
        True
        >>> p5 = Point3D(0, 1, 3)
        >>> Point3D.are_coplanar(p1, p2, p3, p5)
        False

        r   Tr   r"   )r5   rP   r   r~   r   r   r   )rB   r   r   s      r,   are_coplanarzPoint.are_coplanarU  st    H v;!)))f+EE!H+EF!9&&!+d6l#  &)Q.. ,Fs   A2c           	         t        |t              s	 t        || j                        }t        |t              rDt        j                  | t        |            \  }}t        t        d t        ||      D               S t        |dd      }|t	        dt        |      z         ||       S # t        $ r t	        dt        |      z        w xY w)az  The Euclidean distance between self and another GeometricEntity.

        Returns
        =======

        distance : number or symbolic expression.

        Raises
        ======

        TypeError : if other is not recognized as a GeometricEntity or is a
                    GeometricEntity for which distance is not defined.

        See Also
        ========

        sympy.geometry.line.Segment.length
        sympy.geometry.point.Point.taxicab_distance

        Examples
        ========

        >>> from sympy import Point, Line
        >>> p1, p2 = Point(1, 1), Point(4, 5)
        >>> l = Line((3, 1), (2, 2))
        >>> p1.distance(p2)
        5
        >>> p1.distance(l)
        sqrt(2)

        The computed distance may be symbolic, too:

        >>> from sympy.abc import x, y
        >>> p3 = Point(x, y)
        >>> p3.distance((0, 0))
        sqrt(x**2 + y**2)

        r!   z'not recognized as a GeometricEntity: %sc              3   2   K   | ]  \  }}||z
  d z    ywr"   Nrx   r*   r+   rU   s      r,   r-   z!Point.distance.<locals>.<genexpr>  s     ?TQq1uqj?s   rI   Nz,distance between Point and %s is not defined)r0   r   r   r~   r6   typerP   r   r   rQ   r   )rJ   rR   rS   prI   s        r,   rI   zPoint.distance  s    N %0Ye)?)?@ eU#--dE%LADAq?SAY?@AA5*d3JTRW[XYY~  Y IDQVK WXXYs   B+ +!Cc                 `    t        |      st        |      }t        d t        | |      D         S )z.Return dot product of self with another Point.c              3   ,   K   | ]  \  }}||z    y wr/   rx   r   s      r,   r-   zPoint.dot.<locals>.<genexpr>  s     2TQQqS2s   )r   r   r   rQ   )rJ   r   s     r,   dotz	Point.dot  s)    1~aA2Sq\233rM   c                     t        |t              rt        |       t        |      k7  ryt        d t	        | |      D              S )z8Returns whether the coordinates of self and other agree.Fc              3   D   K   | ]  \  }}|j                  |        y wr/   )equalsr   s      r,   r-   zPoint.equals.<locals>.<genexpr>  s     <41a188A;<s    )r0   r   r5   r<   rQ   rc   s     r,   r   zPoint.equals  s8     %'3t9E
+B<3tU+;<<<rM   c                     t        |      }| j                  D cg c]  } |j                  dd|i| }}t        |ddiS c c}w )aF  Evaluate the coordinates of the point.

        This method will, where possible, create and return a new Point
        where the coordinates are evaluated as floating point numbers to
        the precision indicated (default=15).

        Parameters
        ==========

        prec : int

        Returns
        =======

        point : Point

        Examples
        ========

        >>> from sympy import Point, Rational
        >>> p1 = Point(Rational(1, 2), Rational(3, 2))
        >>> p1
        Point2D(1/2, 3/2)
        >>> p1.evalf()
        Point2D(0.5, 1.5)

        r   r   Frx   )r   rC   evalfr   )rJ   precoptionsdpsr_   rE   s         r,   _eval_evalfzPoint._eval_evalf  sN    8 $59YY?'!''+C+7+??f-u-- @s   Ac                     t        |t              st        |      }t        |t              r0| |k(  r| gS t        j                  | |      \  }}|| k(  r||k(  r| gS g S |j	                  |       S )a|  The intersection between this point and another GeometryEntity.

        Parameters
        ==========

        other : GeometryEntity or sequence of coordinates

        Returns
        =======

        intersection : list of Points

        Notes
        =====

        The return value will either be an empty list if there is no
        intersection, otherwise it will contain this point.

        Examples
        ========

        >>> from sympy import Point
        >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 0)
        >>> p1.intersection(p2)
        []
        >>> p1.intersection(p3)
        [Point2D(0, 0)]

        )r0   r   r   rP   intersection)rJ   rR   p1p2s       r,   r   zPoint.intersection  so    < %0%LEeU#u}v//e<FBTzbBhvI!!$''rM   c                     | f|z   }t        j                  |D cg c]  }t        |       c} }t        t        |            }t        j                  | dk  S c c}w )a  Returns `True` if there exists a line
        that contains `self` and `points`.  Returns `False` otherwise.
        A trivially True value is returned if no points are given.

        Parameters
        ==========

        args : sequence of Points

        Returns
        =======

        is_collinear : boolean

        See Also
        ========

        sympy.geometry.line.Line

        Examples
        ========

        >>> from sympy import Point
        >>> from sympy.abc import x
        >>> p1, p2 = Point(0, 0), Point(1, 1)
        >>> p3, p4, p5 = Point(2, 2), Point(x, x), Point(1, 2)
        >>> Point.is_collinear(p1, p2, p3, p4)
        True
        >>> Point.is_collinear(p1, p2, p3, p5)
        False

        r   )r   rP   r   r   r   )rJ   rC   r   r   s       r,   is_collinearzPoint.is_collinear  sY    B 4++-G1eAh-GHd6l#  &)Q.. .Hs   Ac           	         | f|z   }t        j                  |D cg c]  }t        |       c} }t        t        |            }t        j                  | dk  sy|d   }|D cg c]  }||z
  	 }}t        |D cg c]   }t        |      |j                  |      gz   " c}      }|j                         \  }}t        |      |vryyc c}w c c}w c c}w )a  Do `self` and the given sequence of points lie in a circle?

        Returns True if the set of points are concyclic and
        False otherwise. A trivial value of True is returned
        if there are fewer than 2 other points.

        Parameters
        ==========

        args : sequence of Points

        Returns
        =======

        is_concyclic : boolean


        Examples
        ========

        >>> from sympy import Point

        Define 4 points that are on the unit circle:

        >>> p1, p2, p3, p4 = Point(1, 0), (0, 1), (-1, 0), (0, -1)

        >>> p1.is_concyclic() == p1.is_concyclic(p2, p3, p4) == True
        True

        Define a point not on that circle:

        >>> p = Point(1, 1)

        >>> p.is_concyclic(p1, p2, p3)
        False

        r"   Fr   T)	r   rP   r   r   r   r   r   rrefr5   )	rJ   rC   r   r   rK   r   matr   pivotss	            r,   is_concycliczPoint.is_concyclic3  s    L 4++-G1eAh-GHd6l#  &)Q.&,-!f*-- F;qd1gq
*;<xxzfv;f$ .H
 . <s   C#C:%Cc                 &    | j                   }|y| S )zrTrue if any coordinate is nonzero, False if every coordinate is zero,
        and None if it cannot be determined.N)r(   )rJ   r(   s     r,   
is_nonzerozPoint.is_nonzerok  s     ,,?{rM   c                 v   t         j                  | t        |            \  }}|j                  dk(  rU|j                  |j                  c\  }}\  }}||z  ||z  z
  j	                  d      }|t        t        d|d|            t        |j                  |j                  g      }	|	j                         dk  S )z{Returns whether each coordinate of `self` is a scalar
        multiple of the corresponding coordinate in point p.
        r"   r   zCannot determine if z- is a scalar multiple of
                    )	r   rP   r~   rC   r   r   r   r   r   )
rJ   r   rS   rT   x1y1x2y2rvr   s
             r,   is_scalar_multiplezPoint.is_scalar_multiplet  s     ))$a91!#!"HRhr2R%"R%-''*Bz!*##$ % % AFFAFF#$vvx!|rM   c                     | j                   D cg c]  }|j                   }}t        |      ryt        d |D              ryyc c}w )zsTrue if every coordinate is zero, False if any coordinate is not zero,
        and None if it cannot be determined.Fc              3   $   K   | ]  }|d u  
 y wr/   rx   )r*   r_   s     r,   r-   z Point.is_zero.<locals>.<genexpr>  s     *QqDy*s   NT)rC   r   r;   )rJ   r_   nonzeros      r,   r(   zPoint.is_zero  sB     *.3A1<<33w<*'** 4s   Ac                 "    t         j                  S )z
        Treating a Point as a Line, this returns 0 for the length of a Point.

        Examples
        ========

        >>> from sympy import Point
        >>> p = Point(0, 1)
        >>> p.length
        0
        )r   r8   rj   s    r,   lengthzPoint.length  s     vvrM   c           
          t         j                  | t        |            \  }}t        t        ||      D cg c]$  \  }}t        ||z   t        j
                  z        & c}}      S c c}}w )a  The midpoint between self and point p.

        Parameters
        ==========

        p : Point

        Returns
        =======

        midpoint : Point

        See Also
        ========

        sympy.geometry.line.Segment.midpoint

        Examples
        ========

        >>> from sympy import Point
        >>> p1, p2 = Point(1, 1), Point(13, 5)
        >>> p1.midpoint(p2)
        Point2D(7, 3)

        )r   rP   rQ   r   r   Half)rJ   r   rS   r+   rU   s        r,   midpointzPoint.midpoint  sR    6 ))$a913q!9E41ahAqvv~.EFFEs   )A(
c                 6    t        dgt        |       z  d      S )zOA point of all zeros of the same ambient dimension
        as the current pointr   FrO   )r   r5   rj   s    r,   rK   zPoint.origin  s     aST]U33rM   c                     | j                   }| d   j                  rt        dg|dz
  dgz  z         S | d   j                  rt        ddg|dz
  dgz  z         S t        | d    | d   g|dz
  dgz  z         S )au  Returns a non-zero point that is orthogonal to the
        line containing `self` and the origin.

        Examples
        ========

        >>> from sympy import Line, Point
        >>> a = Point(1, 2, 3)
        >>> a.orthogonal_direction
        Point3D(-2, 1, 0)
        >>> b = _
        >>> Line(b, b.origin).is_perpendicular(Line(a, a.origin))
        True
        r   r   r"   )r~   r(   r   )rJ   r!   s     r,   orthogonal_directionzPoint.orthogonal_direction  s      $$7??!a!},--7??!A#'A3.// tAwhQ(C!GaS=899rM   c                     t         j                  t        |       t        |            \  } }|j                  rt        d      || j	                  |      |j	                  |      z  z  S )a  Project the point `a` onto the line between the origin
        and point `b` along the normal direction.

        Parameters
        ==========

        a : Point
        b : Point

        Returns
        =======

        p : Point

        See Also
        ========

        sympy.geometry.line.LinearEntity.projection

        Examples
        ========

        >>> from sympy import Line, Point
        >>> a = Point(1, 2)
        >>> b = Point(2, 5)
        >>> z = a.origin
        >>> p = Point.project(a, b)
        >>> Line(p, a).is_perpendicular(Line(p, b))
        True
        >>> Point.is_collinear(z, p, b)
        True
        "Cannot project to the zero vector.)r   rP   r(   r9   r   )r+   rU   s     r,   projectzPoint.project  sV    D ))%(E!H=199ABB!%%(QUU1X%&&rM   c                 x    t         j                  | t        |            \  }}t        d t        ||      D         S )a2  The Taxicab Distance from self to point p.

        Returns the sum of the horizontal and vertical distances to point p.

        Parameters
        ==========

        p : Point

        Returns
        =======

        taxicab_distance : The sum of the horizontal
        and vertical distances to point p.

        See Also
        ========

        sympy.geometry.point.Point.distance

        Examples
        ========

        >>> from sympy import Point
        >>> p1, p2 = Point(1, 1), Point(4, 5)
        >>> p1.taxicab_distance(p2)
        7

        c              3   >   K   | ]  \  }}t        ||z
          y wr/   r   r   s      r,   r-   z)Point.taxicab_distance.<locals>.<genexpr>%  s     6DAqSQZ6s   )r   rP   r   rQ   rJ   r   rS   s      r,   taxicab_distancezPoint.taxicab_distance  s5    < ))$a916C1I677rM   c                     t         j                  | t        |            \  }}| j                  r|j                  rt        d      t	        d t        ||      D         S )a=  The Canberra Distance from self to point p.

        Returns the weighted sum of horizontal and vertical distances to
        point p.

        Parameters
        ==========

        p : Point

        Returns
        =======

        canberra_distance : The weighted sum of horizontal and vertical
        distances to point p. The weight used is the sum of absolute values
        of the coordinates.

        Examples
        ========

        >>> from sympy import Point
        >>> p1, p2 = Point(1, 1), Point(3, 3)
        >>> p1.canberra_distance(p2)
        1
        >>> p1, p2 = Point(0, 0), Point(3, 3)
        >>> p1.canberra_distance(p2)
        2

        Raises
        ======

        ValueError when both vectors are zero.

        See Also
        ========

        sympy.geometry.point.Point.distance

        r   c              3   n   K   | ]-  \  }}t        ||z
        t        |      t        |      z   z   / y wr/   r   r   s      r,   r-   z*Point.canberra_distance.<locals>.<genexpr>S  s-     J1c!a%j#a&3q6/2Js   35)r   rP   r(   r9   r   rQ   r   s      r,   canberra_distancezPoint.canberra_distance'  sO    R ))$a91<<AIIABBJAq	JKKrM   c                     | t        |       z  S )zdReturn the Point that is in the same direction as `self`
        and a distance of 1 from the originr   rj   s    r,   unitz
Point.unitU  s     c$irM   N)   ),__name__
__module____qualname____doc__is_PointrA   rL   rV   r[   r`   rd   rg   rk   rm   ro   rr   rt   rv   ry   classmethodrP   staticmethodr   propertyr~   r   rI   r   r   r   r   r   r   r   r   r(   r   r   rK   r   r   r   r   r   rx   rM   r,   r   r   *   sv   >@ HF4P,
%-N!-'
$->$-
*
 4 4" ? ?* > > +/ +/Z2h4=.@'(R$/L6p  &    G< 4 4
 : :2 $' $'L8B,L\    rM   r   c                       e Zd ZdZdZdddZd Zed        Zdd	Z	dd
Z
d ZddZed        Zed        Zed        Zy)r?   a  A point in a 2-dimensional Euclidean space.

    Parameters
    ==========

    coords
        A sequence of 2 coordinate values.

    Attributes
    ==========

    x
    y
    length

    Raises
    ======

    TypeError
        When trying to add or subtract points with different dimensions.
        When trying to create a point with more than two dimensions.
        When `intersection` is called with object other than a Point.

    See Also
    ========

    sympy.geometry.line.Segment : Connects two Points

    Examples
    ========

    >>> from sympy import Point2D
    >>> from sympy.abc import x
    >>> Point2D(1, 2)
    Point2D(1, 2)
    >>> Point2D([1, 2])
    Point2D(1, 2)
    >>> Point2D(0, x)
    Point2D(0, x)

    Floats are automatically converted to Rational unless the
    evaluate flag is False:

    >>> Point2D(0.5, 0.25)
    Point2D(1/2, 1/4)
    >>> Point2D(0.5, 0.25, evaluate=False)
    Point2D(0.5, 0.25)

    r"   Fr2   c                R    |sd|d<   t        |i |}t        j                  | g| S )Nr"   r!   r   r   rA   rB   r2   rC   rD   s       r,   rA   zPoint2D.__new__  3    F5M$)&)D%%c1D11rM   c                     || k(  S r/   rx   rY   s     r,   r[   zPoint2D.__contains__      t|rM   c                 ^    | j                   | j                  | j                   | j                  fS )zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding
        rectangle for the geometric figure.

        )r_   yrj   s    r,   boundszPoint2D.bounds  s#     //rM   Nc                     t        |      }t        |      }| }|t        |d      }||z  }|j                  \  }}t        ||z  ||z  z
  ||z  ||z  z         }|||z  }|S )a[  Rotate ``angle`` radians counterclockwise about Point ``pt``.

        See Also
        ========

        translate, scale

        Examples
        ========

        >>> from sympy import Point2D, pi
        >>> t = Point2D(1, 0)
        >>> t.rotate(pi/2)
        Point2D(0, 1)
        >>> t.rotate(pi/2, (2, 0))
        Point2D(2, -1)

        r"   r   )r   r   r   rC   )rJ   angleptcrS   r   r_   r   s           r,   rotatezPoint2D.rotate  sy    & JJ>rq!B"HBww11Q319acAaCi(>"HB	rM   c                     |rNt        |d      }  | j                  | j                   j                  ||      j                  |j                   S t        | j                  |z  | j
                  |z        S )a  Scale the coordinates of the Point by multiplying by
        ``x`` and ``y`` after subtracting ``pt`` -- default is (0, 0) --
        and then adding ``pt`` back again (i.e. ``pt`` is the point of
        reference for the scaling).

        See Also
        ========

        rotate, translate

        Examples
        ========

        >>> from sympy import Point2D
        >>> t = Point2D(1, 1)
        >>> t.scale(2)
        Point2D(2, 1)
        >>> t.scale(2, 2)
        Point2D(2, 2)

        r"   r   )r   	translaterC   scaler_   r   )rJ   r_   r   r   s       r,   r   zPoint2D.scale  se    , rq!BD>4>>RC::.44Q:DDbggNNTVVAXtvvax((rM   c           	          |j                   r|j                  dk(  st        d      | j                  \  }}t	        t        dd||dg      |z  j                         d   dd  S )a  Return the point after applying the transformation described
        by the 3x3 Matrix, ``matrix``.

        See Also
        ========
        sympy.geometry.point.Point2D.rotate
        sympy.geometry.point.Point2D.scale
        sympy.geometry.point.Point2D.translate
        )r3   r3   zmatrix must be a 3x3 matrixr   r3   r   Nr"   )	is_Matrixshaper9   rC   r   r   tolist)rJ   matrixr_   r   s       r,   	transformzPoint2D.transform  se       V\\V%;:;;yy1vaQ1I.v5==?B2AFGGrM   c                 N    t        | j                  |z   | j                  |z         S )a  Shift the Point by adding x and y to the coordinates of the Point.

        See Also
        ========

        sympy.geometry.point.Point2D.rotate, scale

        Examples
        ========

        >>> from sympy import Point2D
        >>> t = Point2D(0, 1)
        >>> t.translate(2)
        Point2D(2, 1)
        >>> t.translate(2, 2)
        Point2D(2, 3)
        >>> t + Point2D(2, 2)
        Point2D(2, 3)

        )r   r_   r   )rJ   r_   r   s      r,   r   zPoint2D.translate  s!    * TVVaZ!,,rM   c                     | j                   S )z
        Returns the two coordinates of the Point.

        Examples
        ========

        >>> from sympy import Point2D
        >>> p = Point2D(0, 1)
        >>> p.coordinates
        (0, 1)
        rX   rj   s    r,   coordinateszPoint2D.coordinates       yyrM   c                      | j                   d   S )z
        Returns the X coordinate of the Point.

        Examples
        ========

        >>> from sympy import Point2D
        >>> p = Point2D(0, 1)
        >>> p.x
        0
        r   rX   rj   s    r,   r_   z	Point2D.x       yy|rM   c                      | j                   d   S )z
        Returns the Y coordinate of the Point.

        Examples
        ========

        >>> from sympy import Point2D
        >>> p = Point2D(0, 1)
        >>> p.y
        1
        r   rX   rj   s    r,   r   z	Point2D.y"  r   rM   r/   )r   r   N)r   r   )r   r   r   r   r{   rA   r[   r   r   r   r   r   r   r   r_   r   rx   rM   r,   r?   r?   \  s    0d %* 2 0 0@)6H-.      rM   r?   c                       e Zd ZdZdZdddZd Zed        Zd Z	d	 Z
d
 ZddZd ZddZed        Zed        Zed        Zed        Zy)r@   a>  A point in a 3-dimensional Euclidean space.

    Parameters
    ==========

    coords
        A sequence of 3 coordinate values.

    Attributes
    ==========

    x
    y
    z
    length

    Raises
    ======

    TypeError
        When trying to add or subtract points with different dimensions.
        When `intersection` is called with object other than a Point.

    Examples
    ========

    >>> from sympy import Point3D
    >>> from sympy.abc import x
    >>> Point3D(1, 2, 3)
    Point3D(1, 2, 3)
    >>> Point3D([1, 2, 3])
    Point3D(1, 2, 3)
    >>> Point3D(0, x, 3)
    Point3D(0, x, 3)

    Floats are automatically converted to Rational unless the
    evaluate flag is False:

    >>> Point3D(0.5, 0.25, 2)
    Point3D(1/2, 1/4, 2)
    >>> Point3D(0.5, 0.25, 3, evaluate=False)
    Point3D(0.5, 0.25, 3)

    r3   Fr   c                R    |sd|d<   t        |i |}t        j                  | g| S )Nr3   r!   r   r   s       r,   rA   zPoint3D.__new__a  r   rM   c                     || k(  S r/   rx   rY   s     r,   r[   zPoint3D.__contains__g  r   rM   c                  &    t        j                  |  S )a  Is a sequence of points collinear?

        Test whether or not a set of points are collinear. Returns True if
        the set of points are collinear, or False otherwise.

        Parameters
        ==========

        points : sequence of Point

        Returns
        =======

        are_collinear : boolean

        See Also
        ========

        sympy.geometry.line.Line3D

        Examples
        ========

        >>> from sympy import Point3D
        >>> from sympy.abc import x
        >>> p1, p2 = Point3D(0, 0, 0), Point3D(1, 1, 1)
        >>> p3, p4, p5 = Point3D(2, 2, 2), Point3D(x, x, x), Point3D(1, 2, 6)
        >>> Point3D.are_collinear(p1, p2, p3, p4)
        True
        >>> Point3D.are_collinear(p1, p2, p3, p5)
        False
        )r   r   )r   s    r,   are_collinearzPoint3D.are_collinearj  s    D !!6**rM   c                     | j                  |      }t        t        d |D               }|j                  | j                  z
  |z  |j                  | j                  z
  |z  |j
                  | j
                  z
  |z  gS )ap  
        Gives the direction cosine between 2 points

        Parameters
        ==========

        p : Point3D

        Returns
        =======

        list

        Examples
        ========

        >>> from sympy import Point3D
        >>> p1 = Point3D(1, 2, 3)
        >>> p1.direction_cosine(Point3D(2, 3, 5))
        [sqrt(6)/6, sqrt(6)/6, sqrt(6)/3]
        c              3   &   K   | ]	  }|d z    ywr   rx   r   s     r,   r-   z+Point3D.direction_cosine.<locals>.<genexpr>  s     'q!t's   )direction_ratior   r   r_   r   z)rJ   pointr+   rU   s       r,   direction_cosinezPoint3D.direction_cosine  sq    ,   ''Q'()466!Q&$&&(8A'=466!Q&( 	(rM   c                     |j                   | j                   z
  |j                  | j                  z
  |j                  | j                  z
  gS )aV  
        Gives the direction ratio between 2 points

        Parameters
        ==========

        p : Point3D

        Returns
        =======

        list

        Examples
        ========

        >>> from sympy import Point3D
        >>> p1 = Point3D(1, 2, 3)
        >>> p1.direction_ratio(Point3D(2, 3, 5))
        [1, 1, 2]
        )r_   r   r  )rJ   r  s     r,   r  zPoint3D.direction_ratio  s8    , 466!EGGdff$4uww7GIIrM   c                     t        |t              st        |d      }t        |t              r
| |k(  r| gS g S |j	                  |       S )a  The intersection between this point and another GeometryEntity.

        Parameters
        ==========

        other : GeometryEntity or sequence of coordinates

        Returns
        =======

        intersection : list of Points

        Notes
        =====

        The return value will either be an empty list if there is no
        intersection, otherwise it will contain this point.

        Examples
        ========

        >>> from sympy import Point3D
        >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 0, 0)
        >>> p1.intersection(p2)
        []
        >>> p1.intersection(p3)
        [Point3D(0, 0, 0)]

        r3   r   )r0   r   r   r@   r   rc   s     r,   r   zPoint3D.intersection  sH    < %0%Q'EeW%u}vI!!$''rM   Nc                    |rMt        |      }  | j                  | j                   j                  |||      j                  |j                   S t        | j                  |z  | j
                  |z  | j                  |z        S )a  Scale the coordinates of the Point by multiplying by
        ``x`` and ``y`` after subtracting ``pt`` -- default is (0, 0) --
        and then adding ``pt`` back again (i.e. ``pt`` is the point of
        reference for the scaling).

        See Also
        ========

        translate

        Examples
        ========

        >>> from sympy import Point3D
        >>> t = Point3D(1, 1, 1)
        >>> t.scale(2)
        Point3D(2, 1, 1)
        >>> t.scale(2, 2)
        Point3D(2, 2, 1)

        )r@   r   rC   r   r_   r   r  )rJ   r_   r   r  r   s        r,   r   zPoint3D.scale  sn    , BG>4>>RC::.44Q1=GGQQtvvax466!844rM   c           
          |j                   r|j                  dk(  st        d      | j                  \  }}}t	        |      }t        t        dd|||dg      |z  j                         d   dd  S )zReturn the point after applying the transformation described
        by the 4x4 Matrix, ``matrix``.

        See Also
        ========
        sympy.geometry.point.Point3D.scale
        sympy.geometry.point.Point3D.translate
        )   r
  zmatrix must be a 4x4 matrixr   r
  r   Nr3   )r   r   r9   rC   r   r@   r   r   )rJ   r   r_   r   r  r   s         r,   r   zPoint3D.transform  ss       V\\V%;:;;))1af1q!Ql3A5==?B2AFGGrM   c                 j    t        | j                  |z   | j                  |z   | j                  |z         S )a  Shift the Point by adding x and y to the coordinates of the Point.

        See Also
        ========

        scale

        Examples
        ========

        >>> from sympy import Point3D
        >>> t = Point3D(0, 1, 1)
        >>> t.translate(2)
        Point3D(2, 1, 1)
        >>> t.translate(2, 2)
        Point3D(2, 3, 1)
        >>> t + Point3D(2, 2, 2)
        Point3D(2, 3, 3)

        )r@   r_   r   r  )rJ   r_   r   r  s       r,   r   zPoint3D.translate  s+    * tvvz466A:tvvz::rM   c                     | j                   S )z
        Returns the three coordinates of the Point.

        Examples
        ========

        >>> from sympy import Point3D
        >>> p = Point3D(0, 1, 2)
        >>> p.coordinates
        (0, 1, 2)
        rX   rj   s    r,   r   zPoint3D.coordinates(  r   rM   c                      | j                   d   S )z
        Returns the X coordinate of the Point.

        Examples
        ========

        >>> from sympy import Point3D
        >>> p = Point3D(0, 1, 3)
        >>> p.x
        0
        r   rX   rj   s    r,   r_   z	Point3D.x7  r   rM   c                      | j                   d   S )z
        Returns the Y coordinate of the Point.

        Examples
        ========

        >>> from sympy import Point3D
        >>> p = Point3D(0, 1, 2)
        >>> p.y
        1
        r   rX   rj   s    r,   r   z	Point3D.yF  r   rM   c                      | j                   d   S )z
        Returns the Z coordinate of the Point.

        Examples
        ========

        >>> from sympy import Point3D
        >>> p = Point3D(0, 1, 1)
        >>> p.z
        1
        r"   rX   rj   s    r,   r  z	Point3D.zU  r   rM   )r   r   r   N)r   r   r   )r   r   r   r   r{   rA   r[   r   r   r  r  r   r   r   r   r   r   r_   r   r  rx   rM   r,   r@   r@   1  s    +Z %* 2 !+ !+F(6J0$(L56H;.        rM   r@   ),r   r:   
sympy.corer   r   r   sympy.core.addr   sympy.core.containersr   sympy.core.numbersr   sympy.core.parametersr	   sympy.simplifyr
   r   sympy.geometry.exceptionsr   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.complexesr   (sympy.functions.elementary.trigonometricr   r   sympy.matricesr   sympy.matrices.expressionsr   sympy.utilities.iterablesr   r   sympy.utilities.miscr   r   r   entityr   mpmath.libmp.libmpfr   r   r?   r@   rx   rM   r,   <module>r      sq   &  ' '  ' $ 3 . 3 9 3 = ! 0 7 C C " +o N o dSe Sjqe qrM   