o
    ohk@                    @   s  d dl mZmZ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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 dd
lmZmZ ddlm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+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7Z7dd e8dD \Z9Z:Z;G dd deZ<G dd de<Z=G dd de<Z>dd  Z?d!d" Z@d#d$ ZAd%d& ZBd'd( ZCd)d* ZDdS )+    )ExprSoopisympify)N)default_sort_keyordered)_symbolDummySymbol)sign)	Piecewise)cossintan   )Circle)GeometryEntityGeometrySet)GeometryError)LineSegmentRayPoint)And)Matrixsimplify)solve)has_dupshas_varietyuniqrotate_leftleast_rotation)as_int	func_name)prec_to_dpsNc                 C   s   g | ]}t d ddqS )polygon_dummyTreal)r   .0i r/   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/geometry/polygon.py
<listcomp>       r1      c                   @   s$  e Zd ZdZdZddddZedd Zed	d
 Z	edd Z
edd Zedd Zedd Zedd Zd?ddZd?ddZdd Zd?ddZedd Zed d! Zd"d# Zd$d% Zd@d'd(Zd)d* Zd@d+d,Zd-d. Zd/d0 Zd1d2 Zd3d4 ZdAd7d8Zd9d: Zd;d< Z d?d=d>Z!dS )BPolygona	  A two-dimensional polygon.

    A simple polygon in space. Can be constructed from a sequence of points
    or from a center, radius, number of sides and rotation angle.

    Parameters
    ==========

    vertices
        A sequence of points.

    n : int, optional
        If $> 0$, an n-sided RegularPolygon is created.
        Default value is $0$.

    Attributes
    ==========

    area
    angles
    perimeter
    vertices
    centroid
    sides

    Raises
    ======

    GeometryError
        If all parameters are not Points.

    See Also
    ========

    sympy.geometry.point.Point, sympy.geometry.line.Segment, Triangle

    Notes
    =====

    Polygons are treated as closed paths rather than 2D areas so
    some calculations can be be negative or positive (e.g., area)
    based on the orientation of the points.

    Any consecutive identical points are reduced to a single point
    and any points collinear and between two points will be removed
    unless they are needed to define an explicit intersection (see examples).

    A Triangle, Segment or Point will be returned when there are 3 or
    fewer points provided.

    Examples
    ========

    >>> from sympy import Polygon, pi
    >>> p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
    >>> Polygon(p1, p2, p3, p4)
    Polygon(Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1))
    >>> Polygon(p1, p2)
    Segment2D(Point2D(0, 0), Point2D(1, 0))
    >>> Polygon(p1, p2, p5)
    Segment2D(Point2D(0, 0), Point2D(3, 0))

    The area of a polygon is calculated as positive when vertices are
    traversed in a ccw direction. When the sides of a polygon cross the
    area will have positive and negative contributions. The following
    defines a Z shape where the bottom right connects back to the top
    left.

    >>> Polygon((0, 2), (2, 2), (0, 0), (2, 0)).area
    0

    When the keyword `n` is used to define the number of sides of the
    Polygon then a RegularPolygon is created and the other arguments are
    interpreted as center, radius and rotation. The unrotated RegularPolygon
    will always have a vertex at Point(r, 0) where `r` is the radius of the
    circle that circumscribes the RegularPolygon. Its method `spin` can be
    used to increment that angle.

    >>> p = Polygon((0,0), 1, n=3)
    >>> p
    RegularPolygon(Point2D(0, 0), 1, 3, 0)
    >>> p.vertices[0]
    Point2D(1, 0)
    >>> p.args[0]
    Point2D(0, 0)
    >>> p.spin(pi/2)
    >>> p.vertices[0]
    Point2D(0, 1)

    r/   r   )nc                   s  |r%t |}t|dkr|| nt|dkr|d| t|i  S  fdd|D }g }|D ]}|r=||d kr=q2|| q2t|dkrU|d |d krU|  d}|t|d k rt|dkr|| ||d  ||d  }}	}
t||	|
r||d  ||
kr|| n|d7 }|t|d k rt|dkset |}t|dkrtj	| g|R i  S t|dkrt
|i  S t|dkrt|i  S t|i  S )	N   r3   c                        g | ]}t |fd di qS dimr6   r   r-   akwargsr/   r0   r1           z#Polygon.__new__.<locals>.<listcomp>r   r   )listlenappendinsertRegularPolygonpopr   is_collinearr   __new__Triangler   )clsr5   argsr=   verticesnoduppr.   r;   bcr/   r<   r0   rH   z   sB   $
	zPolygon.__new__c                 C   s\   d}| j }tt|D ]}||d  j \}}|| j \}}||| ||  7 }qt|d S )a  
        The area of the polygon.

        Notes
        =====

        The area calculation can be positive or negative based on the
        orientation of the points. If any side of the polygon crosses
        any other side, there will be areas having opposite signs.

        See Also
        ========

        sympy.geometry.ellipse.Ellipse.area

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.area
        3

        In the Z shaped polygon (with the lower right connecting back
        to the upper left) the areas cancel out:

        >>> Z = Polygon((0, 1), (1, 1), (0, 0), (1, 0))
        >>> Z.area
        0

        In the M shaped polygon, areas do not cancel because no side
        crosses any other (though there is a point of contact).

        >>> M = Polygon((0, 0), (0, 1), (2, 0), (3, 1), (3, 0))
        >>> M.area
        -3/2

        r   r   r6   )rK   rangerB   r   )selfarearK   r.   x1y1x2y2r/   r/   r0   rS      s   )zPolygon.areac                 C   sF   ||  }||  }t |j|j |j|j  }|j}|du r!td|S )a7  Return True/False for cw/ccw orientation.

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> a, b, c = [Point(i) for i in [(0, 0), (1, 1), (1, 0)]]
        >>> Polygon._is_clockwise(a, b, c)
        True
        >>> Polygon._is_clockwise(a, c, b)
        False
        NzCan't determine orientation)r   xyis_nonpositive
ValueError)r;   rO   rP   bacat_arearesr/   r/   r0   _is_clockwise   s   zPolygon._is_clockwisec                 C   s   | j }t|}i }t|D ]4}||d  ||d  || }}}t||t||}| |||r=dtj | ||< q|||< qt|	 tj d |d  d j
}	|	rjdtj }
|D ]
}|
||  ||< q]|S |	du rrtd|S )a  The internal angle at each vertex.

        Returns
        =======

        angles : dict
            A dictionary where each key is a vertex and each value is the
            internal angle at that vertex. The vertices are represented as
            Points.

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.line.LinearEntity.angle_between

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.angles[p1]
        pi/2
        >>> poly.angles[p2]
        acos(-4*sqrt(17)/17)

        r6   r   Nz(could not determine Polygon orientation.)rL   rB   rQ   r   angle_betweenr`   r   Pisumvaluesis_positiver[   )rR   rK   r5   retr.   r;   rO   rP   
reflex_angwrongtwo_pir/   r/   r0   angles   s$   $
$
zPolygon.anglesc                 C   s   | j d jS )Nr   )rL   ambient_dimensionrR   r/   r/   r0   rk         zPolygon.ambient_dimensionc                 C   s>   d}| j }tt|D ]}|||d  || 7 }qt|S )a  The perimeter of the polygon.

        Returns
        =======

        perimeter : number or Basic instance

        See Also
        ========

        sympy.geometry.line.Segment.length

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.perimeter
        sqrt(17) + 7
        r   r   )rL   rQ   rB   distancer   )rR   rN   rK   r.   r/   r/   r0   	perimeter$  s
   zPolygon.perimeterc                 C   s
   t | jS )aQ  The vertices of the polygon.

        Returns
        =======

        vertices : list of Points

        Notes
        =====

        When iterating over the vertices, it is more efficient to index self
        rather than to request the vertices and index them. Only use the
        vertices when you want to process all of them at once. This is even
        more important with RegularPolygons that calculate each vertex.

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.vertices
        [Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1)]
        >>> poly.vertices[0]
        Point2D(0, 0)

        )rA   rK   rl   r/   r/   r0   rL   A  s   
"zPolygon.verticesc                 C   s   dd| j   }d\}}| j}tt|D ]*}||d  j\}}|| j\}}	||	 ||  }
||
||  7 }||
||	  7 }qtt|| t|| S )a  The centroid of the polygon.

        Returns
        =======

        centroid : Point

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.util.centroid

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.centroid
        Point2D(31/18, 11/18)

        r      r   r   )rS   rK   rQ   rB   r   r   )rR   AcxcyrK   r.   rT   rU   rV   rW   vr/   r/   r0   centroide  s   zPolygon.centroidNc                 C   s  d\}}}| j }tt|D ]R}||d  j\}}|| j\}	}
||
 |	|  }||d ||
  |
d  | 7 }||d ||	  |	d  | 7 }|||
 d| |  d|	 |
  |	|  | 7 }q| j}| jd }| jd }|d ||d   }|d ||d   }|d |||   }|du r|||fS |||d | d   }|||d | d   }|||d | |d |    }|||fS )a  Returns the second moment and product moment of area of a two dimensional polygon.

        Parameters
        ==========

        point : Point, two-tuple of sympifyable 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 polygon.

        Returns
        =======

        I_xx, I_yy, I_xy : number or SymPy expression
                           I_xx, I_yy are second moment of area of a two dimensional polygon.
                           I_xy is product moment of area of a two dimensional polygon.

        Examples
        ========

        >>> from sympy import Polygon, symbols
        >>> a, b = symbols('a, b')
        >>> p1, p2, p3, p4, p5 = [(0, 0), (a, 0), (a, b), (0, b), (a/3, b/3)]
        >>> rectangle = Polygon(p1, p2, p3, p4)
        >>> rectangle.second_moment_of_area()
        (a*b**3/12, a**3*b/12, 0)
        >>> rectangle.second_moment_of_area(p5)
        (a*b**3/9, a**3*b/9, a**2*b**2/36)

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Second_moment_of_area

        )r   r   r   r   r6   r         N)rL   rQ   rB   rK   rS   rv   )rR   pointI_xxI_yyI_xyrK   r.   rT   rU   rV   rW   ru   rr   c_xc_yI_xx_cI_yy_cI_xy_cr/   r/   r0   second_moment_of_area  s*   
%  2


 
zPolygon.second_moment_of_areac                 C   s   |r| j \}}n| j }|\}}t|dd}t|tjd}| |}| |}|d j|d jkr4|d n|d }|d j|d jkrF|d n|d }	|j j| |j }
|	j j| |	j }|
|fS )a  
        Returns the first moment of area of a two-dimensional polygon with
        respect to a certain point of interest.

        First moment of area is a measure of the distribution of the area
        of a polygon in relation to an axis. The first moment of area of
        the entire polygon about its own centroid is always zero. Therefore,
        here it is calculated for an area, above or below a certain point
        of interest, that makes up a smaller portion of the polygon. This
        area is bounded by the point of interest and the extreme end
        (top or bottom) of the polygon. The first moment for this area is
        is then determined about the centroidal axis of the initial polygon.

        References
        ==========

        .. [1] https://skyciv.com/docs/tutorials/section-tutorials/calculating-the-statical-or-first-moment-of-area-of-beam-sections/?cc=BMD
        .. [2] https://mechanicalc.com/reference/cross-sections

        Parameters
        ==========

        point: Point, two-tuple of sympifyable objects, or None (default=None)
            point is the point above or below which the area of interest lies
            If ``point=None`` then the centroid acts as the point of interest.

        Returns
        =======

        Q_x, Q_y: number or SymPy expressions
            Q_x is the first moment of area about the x-axis
            Q_y is the first moment of area about the y-axis
            A negative sign indicates that the section modulus is
            determined for a section below (or left of) the centroidal axis

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> a, b = 50, 10
        >>> p1, p2, p3, p4 = [(0, b), (0, 0), (a, 0), (a, b)]
        >>> p = Polygon(p1, p2, p3, p4)
        >>> p.first_moment_of_area()
        (625, 3125)
        >>> p.first_moment_of_area(point=Point(30, 7))
        (525, 3000)
        r   sloper   )rv   r   r   Infinitycut_sectionrS   rY   rX   )rR   ry   xcych_linev_lineh_polyv_polypoly_1poly_2Q_xQ_yr/   r/   r0   first_moment_of_area  s   0

$$zPolygon.first_moment_of_areac                 C   s   |   }|d |d  S )a  Returns the polar modulus of a two-dimensional polygon

        It is a constituent of the second moment of area, linked through
        the perpendicular axis theorem. While the planar second moment of
        area describes an object's resistance to deflection (bending) when
        subjected to a force applied to a plane parallel to the central
        axis, the polar second moment of area describes an object's
        resistance to deflection when subjected to a moment applied in a
        plane perpendicular to the object's central axis (i.e. parallel to
        the cross-section)

        Examples
        ========

        >>> from sympy import Polygon, symbols
        >>> a, b = symbols('a, b')
        >>> rectangle = Polygon((0, 0), (a, 0), (a, b), (0, b))
        >>> rectangle.polar_second_moment_of_area()
        a**3*b/12 + a*b**3/12

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Polar_moment_of_inertia

        r   r   )r   )rR   second_momentr/   r/   r0   polar_second_moment_of_area  s   z#Polygon.polar_second_moment_of_areac                 C   s   | j \}}|du r#| j\}}}}t|| || }t|| || }	n
|j| }|j| }	|  }
|
d | }|
d |	 }||fS )a  Returns a tuple with the section modulus of a two-dimensional
        polygon.

        Section modulus is a geometric property of a polygon defined as the
        ratio of second moment of area to the distance of the extreme end of
        the polygon from the centroidal axis.

        Parameters
        ==========

        point : Point, two-tuple of sympifyable objects, or None(default=None)
            point is the point at which section modulus is to be found.
            If "point=None" it will be calculated for the point farthest from the
            centroidal axis of the polygon.

        Returns
        =======

        S_x, S_y: numbers or SymPy expressions
                  S_x is the section modulus with respect to the x-axis
                  S_y is the section modulus with respect to the y-axis
                  A negative sign indicates that the section modulus is
                  determined for a point below the centroidal axis

        Examples
        ========

        >>> from sympy import symbols, Polygon, Point
        >>> a, b = symbols('a, b', positive=True)
        >>> rectangle = Polygon((0, 0), (a, 0), (a, b), (0, b))
        >>> rectangle.section_modulus()
        (a*b**2/6, a**2*b/6)
        >>> rectangle.section_modulus(Point(a/4, b/4))
        (-a*b**2/3, -a**2*b/3)

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Section_modulus

        Nr   r   )rv   boundsmaxrY   rX   r   )rR   ry   x_cy_cx_miny_minx_maxy_maxrY   rX   r   S_xS_yr/   r/   r0   section_modulus,  s   
*

zPolygon.section_modulusc                 C   s@   g }| j }tt| dD ]}|t|| ||d   q|S )a  The directed line segments that form the sides of the polygon.

        Returns
        =======

        sides : list of sides
            Each side is a directed Segment.

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.line.Segment

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.sides
        [Segment2D(Point2D(0, 0), Point2D(1, 0)),
        Segment2D(Point2D(1, 0), Point2D(5, 1)),
        Segment2D(Point2D(5, 1), Point2D(0, 1)), Segment2D(Point2D(0, 1), Point2D(0, 0))]

        r   r   )rL   rQ   rB   rC   r   )rR   r_   rK   r.   r/   r/   r0   sidesh  s
   zPolygon.sidesc                 C   s>   | j }dd |D }dd |D }t|t|t|t|fS )zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding
        rectangle for the geometric figure.

        c                 S      g | ]}|j qS r/   rX   r-   rN   r/   r/   r0   r1         z"Polygon.bounds.<locals>.<listcomp>c                 S   r   r/   rY   r   r/   r/   r0   r1     r   )rL   minr   )rR   vertsxsysr/   r/   r0   r     s   zPolygon.boundsc           
      C   s   | j }| |d |d |d }tdt|D ]}|| ||d  ||d  || A r/ dS q| j}t|D ]4\}}|j}t|t|d krIdnd|d D ]}|| }|j|vrj|j|vrj|	|}	|	rj  dS qOq7dS )a_  Is the polygon convex?

        A polygon is convex if all its interior angles are less than 180
        degrees and there are no intersections between sides.

        Returns
        =======

        is_convex : boolean
            True if this polygon is convex, False otherwise.

        See Also
        ========

        sympy.geometry.util.convex_hull

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly = Polygon(p1, p2, p3, p4)
        >>> poly.is_convex()
        True

        r?   r   r   r6   FT)
rL   r`   rQ   rB   r   	enumeraterK   p1p2intersection)
rR   rK   cwr.   r   siptsjsjhitr/   r/   r0   	is_convex  s$   &&
zPolygon.is_convexc                    s  t  dd  | jv st fdd| jD rdS g }| jD ]}||   |d jr/ dS qt| }|j}tt	t
| d}| r{d}|D ]/}|| }	||d  }
|	j |
j|	j  |	j |
j|	j   j}|du rq|}qI||urx dS qId	S d}|d
 j\}}|dd D ]?}|| j\}}d
t||krd
t||krd
t||kr||kr| ||  ||  | }||ksd
|kr| }||}}q|S )a4  
        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, sympy.geometry.ellipse.Ellipse.encloses_point

        Examples
        ========

        >>> from sympy import Polygon, Point
        >>> p = Polygon((0, 0), (4, 0), (4, 4))
        >>> p.encloses_point(Point(2, 1))
        True
        >>> p.encloses_point(Point(2, 2))
        False
        >>> p.encloses_point(Point(5, 5))
        False

        References
        ==========

        .. [1] https://paulbourke.net/geometry/polygonmesh/#insidepoly

        r6   r9   c                 3       | ]} |v V  qd S Nr/   r-   srN   r/   r0   	<genexpr>      z)Polygon.encloses_point.<locals>.<genexpr>Fr?   Nr   Tr   )r   rL   anyr   rC   free_symbolsr4   rK   rA   rQ   rB   r   rY   rX   is_negativer   r   )rR   rN   litru   polyrK   indicesorientationr.   r;   rO   testhit_oddp1xp1yp2xp2yxintersr/   r   r0   encloses_point  sJ   *"

*zPolygon.encloses_pointtc           
      C   s   t |dd}|jdd | jD v rtd|j g }| j}d}| jD ](}|j| }|| }||||| | }	|	|	t
||k||k f |}q"t| S )a+  A parameterized point on the polygon.

        The parameter, varying from 0 to 1, assigns points to the position on
        the perimeter that is that fraction of the total perimeter. So the
        point evaluated at t=1/2 would return the point from the first vertex
        that is 1/2 way around the polygon.

        Parameters
        ==========

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

        Returns
        =======

        arbitrary_point : Point

        Raises
        ======

        ValueError
            When `parameter` already appears in the Polygon's definition.

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Polygon, Symbol
        >>> t = Symbol('t', real=True)
        >>> tri = Polygon((0, 0), (1, 0), (1, 1))
        >>> p = tri.arbitrary_point('t')
        >>> perimeter = tri.perimeter
        >>> s1, s2 = [s.length for s in tri.sides[:2]]
        >>> p.subs(t, (s1 + s2/2)/perimeter)
        Point2D(1, 1/2)

        Tr*   c                 s       | ]}|j V  qd S r   )name)r-   fr/   r/   r0   r   F      z*Polygon.arbitrary_point.<locals>.<genexpr>zFSymbol %s already appears in object and cannot be used as a parameter.r   )r
   r   r   r[   ro   r   lengtharbitrary_pointsubsrC   r   r   )
rR   	parameterr   r   ro   perim_fraction_startr   side_perim_fractionperim_fraction_endptr/   r/   r0   r     s"   +


zPolygon.arbitrary_pointc           	      C   s   t |tst|| jd}t |tstd|jrtdd}| t}|j	D ](\}}t
|| tdd}|s6q&|d t }t|t|dkrL||i  S d}q&|rYtdt|  td	t|  )
Nr   zother must be a pointznon-numeric coordinatesFT)dictr   zGiven point may not be on %szGiven point is not on %s)
isinstancer   r   rk   r[   r   NotImplementedErrorr   TrK   r    r   r   r'   )	rR   otherr   unknownrN   r   condsolvaluer/   r/   r0   parameter_valueU  s&   


zPolygon.parameter_valuec                 C   s   t |dd}|ddgS )a  The plot interval for the default geometric plot of the polygon.

        Parameters
        ==========

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

        Returns
        =======

        plot_interval : list (plot interval)
            [parameter, lower_bound, upper_bound]

        Examples
        ========

        >>> from sympy import Polygon
        >>> p = Polygon((0, 0), (1, 0), (1, 1))
        >>> p.plot_interval()
        [t, 0, 1]

        Tr*   r   r   )r   )rR   r   r   r/   r/   r0   plot_intervalj  s   
zPolygon.plot_intervalc           	         s   g }t |tr
|jn|g}| jD ]}|D ]
}||| qqtt|}dd |D }dd |D  |rY rYtt fdd|D }|rQ|D ]}|| qItt | S tt|S )a  The intersection of polygon and geometry entity.

        The intersection may be empty and can contain individual Points and
        complete Line Segments.

        Parameters
        ==========

        other: GeometryEntity

        Returns
        =======

        intersection : list
            The list of Segments and Points

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.line.Segment

        Examples
        ========

        >>> from sympy import Point, Polygon, Line
        >>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
        >>> poly1 = Polygon(p1, p2, p3, p4)
        >>> p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
        >>> poly2 = Polygon(p5, p6, p7)
        >>> poly1.intersection(poly2)
        [Point2D(1/3, 1), Point2D(2/3, 0), Point2D(9/5, 1/5), Point2D(7/3, 1)]
        >>> poly1.intersection(Line(p1, p2))
        [Segment2D(Point2D(0, 0), Point2D(1, 0))]
        >>> poly1.intersection(p1)
        [Point2D(0, 0)]
        c                 S      g | ]	}t |tr|qS r/   )r   r   r-   entityr/   r/   r0   r1         z(Polygon.intersection.<locals>.<listcomp>c                 S   r   r/   )r   r   r   r/   r/   r0   r1     r   c                    s"   g | ]} D ]}||v r|qqS r/   r/   )r-   ry   segmentsegmentsr/   r0   r1     s   " )	r   r4   r   extendr   rA   r#   remover	   )	rR   ointersection_resultksideside1pointspoints_in_segmentsr.   r/   r   r0   r     s    %
zPolygon.intersectionc                 C   sr  |  |}|stdt| j}||d  |tt}|t}|t}g }g }d}	d}
|D ]e}|rB|	t|jt|ji| n|	t|j| }|dkrq|	sit
||
}| |}||d  ||d  || d}	n#|	r|
rt
||
}| |}||d  ||d  || d}	|}
q1d\}}|rtt| trt| }|rtt| trt| }||fS )aL  
        Returns a tuple of two polygon segments that lie above and below
        the intersecting line respectively.

        Parameters
        ==========

        line: Line object of geometry module
            line which cuts the Polygon. The part of the Polygon that lies
            above and below this line is returned.

        Returns
        =======

        upper_polygon, lower_polygon: Polygon objects or None
            upper_polygon is the polygon that lies above the given line.
            lower_polygon is the polygon that lies below the given line.
            upper_polygon and lower polygon are ``None`` when no polygon
            exists above the line or below the line.

        Raises
        ======

        ValueError: When the line does not intersect the polygon

        Examples
        ========

        >>> from sympy import Polygon, Line
        >>> a, b = 20, 10
        >>> p1, p2, p3, p4 = [(0, b), (0, 0), (a, 0), (a, b)]
        >>> rectangle = Polygon(p1, p2, p3, p4)
        >>> t = rectangle.cut_section(Line((0, 5), slope=0))
        >>> t
        (Polygon(Point2D(0, 10), Point2D(0, 5), Point2D(20, 5), Point2D(20, 10)),
        Polygon(Point2D(0, 5), Point2D(0, 0), Point2D(20, 0), Point2D(20, 5)))
        >>> upper_segment, lower_segment = t
        >>> upper_segment.area
        100
        >>> upper_segment.centroid
        Point2D(10, 15/2)
        >>> lower_segment.centroid
        Point2D(10, 5/2)

        References
        ==========

        .. [1] https://github.com/sympy/sympy/wiki/A-method-to-return-a-cut-section-of-any-polygon-geometry

        z(This line does not intersect the polygonr   TNF)NN)r   r[   rA   rL   rC   equationrX   rY   coeffr   r   r   r4   )rR   lineintersection_pointsr   eqr;   rO   upper_verticeslower_verticesprev
prev_pointry   compareedge	new_pointupper_polygonlower_polygonr/   r/   r0   r     sL   
3








zPolygon.cut_sectionc                 C   sp   t |tr#t}| jD ]}||}|dkrtj  S ||k r |}q
|S t |tr5|  r5| r5| 	|S t
 )a  
        Returns the shortest distance between self and o.

        If o is a point, then self does not need to be convex.
        If o is another polygon self and o must be convex.

        Examples
        ========

        >>> from sympy import Point, Polygon, RegularPolygon
        >>> p1, p2 = map(Point, [(0, 0), (7, 5)])
        >>> poly = Polygon(*RegularPolygon(p1, 1, 3).vertices)
        >>> poly.distance(p2)
        sqrt(61)
        r   )r   r   r   r   rn   r   Zeror4   r   _do_poly_distancer   )rR   r   distr   currentr/   r/   r0   rn   (  s   




zPolygon.distancec                  C   s  | }	 |j }|j }tj}tj}|jD ]}t||}||k r |}q|jD ]}t||}||k r2|}q$t||}	|	|| krFtjddd 	 tdt }
tdt}|jD ]}|j	|
j	ksi|j	|
j	krk|j
|
j
krk|}
qU|jD ]}|j	|j	k s|j	|j	kr|j
|j
k r|}qot|
|}	 i }i }|jD ].}|j|v r||j |j n|jg||j< |j|v r||j |j q|jg||j< q|jD ].}|j|v r||j |j n|jg||j< |j|v r||j |j q|jg||j< q|
}|}tttjtjttjtj}	 ||
 d }||
 d }|t|
|}|t|
|}||k r-|}n||k r5|}nt|
|t|
|krE|}n|}|| d }|| d }|t||}|t||}||krk|}n||krs|}nt||t||kr|}n|}	 	 |t||}t|t|| }||k du rt||}t||}||}| | k r|}|| d |kr|}|| d }n|}|| d }n||kdu rt||}t||}||}| | k r|}|| d |kr|}|| d }nf|}|| d }n]t||}t||}t||}||}||}t||}| | k r:|}|| d |krL|}|| d }n|}|| d }|| d |krf|}|| d }n|}|| d }||
kr{||kr{	 |S q)a  
        Calculates the least distance between the exteriors of two
        convex polygons e1 and e2. Does not check for the convexity
        of the polygons as this is checked by Polygon.distance.

        Notes
        =====

            - Prints a warning if the two polygons possibly intersect as the return
              value will not be valid in such a case. For a more through test of
              intersection use intersection().

        See Also
        ========

        sympy.geometry.point.Point.distance

        Examples
        ========

        >>> from sympy import Point, Polygon
        >>> square = Polygon(Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0))
        >>> triangle = Polygon(Point(1, 2), Point(2, 2), Point(2, 1))
        >>> square._do_poly_distance(triangle)
        sqrt(2)/2

        Description of method used
        ==========================

        Method:
        [1] https://web.archive.org/web/20150509035744/http://cgm.cs.mcgill.ca/~orm/mind2p.html
        Uses rotating calipers:
        [2] https://en.wikipedia.org/wiki/Rotating_calipers
        and antipodal points:
        [3] https://en.wikipedia.org/wiki/Antipodal_point
        z1Polygons may intersect producing erroneous outputr3   )
stacklevelr   r   T)rv   r   r  rL   r   rn   warningswarnr   rY   rX   r   r   rC   r   r   Onera   r   r   evalfr   ) rR   e2e1	e1_center	e2_centere1_max_radiuse2_max_radiusvertexrcenter_diste1_ymaxe2_yminmin_diste1_connectionse2_connectionsr   
e1_current
e2_currentsupport_linepoint1point2angle1angle2e1_nexte2_nexte1_anglee2_angle
e1_segmentmin_dist_current
e2_segmentmin1min2r/   r/   r0   r  E  s   %



$
$





















zPolygon._do_poly_distance      ?#66cc99c                 C   sJ   t t| j}dd |D }d|d d|dd }dd	| ||S )
a"  Returns SVG path element for the Polygon.

        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".
        c                 S   s   g | ]
}d  |j|jqS )z{},{})formatrX   rY   r   r/   r/   r0   r1     s    z Polygon._svg.<locals>.<listcomp>zM {} L {} zr   z L r   Nza<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="0.6" d="{1}" />g       @)mapr   rL   r+  join)rR   scale_factor
fill_colorr   coordspathr/   r/   r0   _svg  s   zPolygon._svgc                    st   i   fdd}|| j }t|t|}|tt| j }t|t|}||k r+|}n|} fdd|D }t|S )Nc                    s@   i  t tt| D ]\}}| |< ||< q
 fdd| D S )Nc                       g | ]} | qS r/   r/   r   keer/   r0   r1   (      z?Polygon._hashable_content.<locals>.ref_list.<locals>.<listcomp>)r   r	   set)
point_listr.   rN   Dr4  r0   ref_list#  s
   
z+Polygon._hashable_content.<locals>.ref_listc                    r3  r/   r/   )r-   orderr9  r/   r0   r1   2  r6  z-Polygon._hashable_content.<locals>.<listcomp>)rK   r$   r%   rA   reversedtuple)rR   r;  S1r_norS2r_revr  canonical_argsr/   r9  r0   _hashable_content   s   
zPolygon._hashable_contentc                    sj   t  tr	|  kS t  trt fdd| jD S t  tr3 | jv r&dS | jD ]	} |v r2 dS q)dS )a  
        Return True if o is contained within the boundary lines of self.altitudes

        Parameters
        ==========

        other : GeometryEntity

        Returns
        =======

        contained in : bool
            The points (and sides, if applicable) are contained in self.

        See Also
        ========

        sympy.geometry.entity.GeometryEntity.encloses

        Examples
        ========

        >>> from sympy import Line, Segment, Point
        >>> p = Point(0, 0)
        >>> q = Point(1, 1)
        >>> s = Segment(p, q*2)
        >>> l = Line(p, q)
        >>> p in q
        False
        >>> p in s
        True
        >>> q*3 in s
        False
        >>> s in l
        True

        c                 3   r   r   r/   r   r   r/   r0   r   _  r   z'Polygon.__contains__.<locals>.<genexpr>TF)r   r4   r   r   r   r   rL   )rR   r   r   r/   rE  r0   __contains__5  s   
'



zPolygon.__contains__c                 C   s   i }t | j}||d  tj|dd  }|rt t|}| j D ]E\}}||}t	
|| ||d  \}}	t||	|d |}
|
j}t|
j|
j||d  }
|duret|
j|
j|}
|
||< q$|S )a  Returns angle bisectors of a polygon. If prec is given
        then approximate the point defining the ray to that precision.

        The distance between the points defining the bisector ray is 1.

        Examples
        ========

        >>> from sympy import Polygon, Point
        >>> p = Polygon(Point(0, 0), Point(2, 0), Point(1, 1), Point(0, 3))
        >>> p.bisectors(2)
        {Point2D(0, 0): Ray2D(Point2D(0, 0), Point2D(0.71, 0.71)),
         Point2D(0, 3): Ray2D(Point2D(0, 3), Point2D(0.23, 2.0)),
         Point2D(1, 1): Ray2D(Point2D(1, 1), Point2D(0.19, 0.42)),
         Point2D(2, 0): Ray2D(Point2D(2, 0), Point2D(1.1, 0.38))}
        r   Nr3   r   r6   rq   )rA   rK   rC   r4   r`   r=  rj   itemsindexr   _normalize_dimensionr   rotate	directionr   rn   r   r5   )rN   precrO   r   r   ru   r;   r.   r   r   raydirr/   r/   r0   	bisectorsi  s    


zPolygon.bisectorsr   )r   )r)  r*  )"__name__
__module____qualname____doc__	__slots__rH   propertyrS   staticmethodr`   rj   rk   ro   rL   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   rn   r  r2  rD  rF  rO  r/   r/   r/   r0   r4      sP    [+
0

3


#

#
?E
<
 
.
W;
9j 
I4r4   c                       s@  e Zd ZdZdZd=ddZd>ddZed	d
 Zdd Z	dd Z
edd Zedd Zedd ZeZedd Zedd Zedd Zedd Zedd Zed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d-d. Zd?d0d1Zd@d3d4Zd5d6 Zed7d8 Zd9d: Z  fd;d<Z!  Z"S )ArE   a  
    A regular polygon.

    Such a polygon has all internal angles equal and all sides the same length.

    Parameters
    ==========

    center : Point
    radius : number or Basic instance
        The distance from the center to a vertex
    n : int
        The number of sides

    Attributes
    ==========

    vertices
    center
    radius
    rotation
    apothem
    interior_angle
    exterior_angle
    circumcircle
    incircle
    angles

    Raises
    ======

    GeometryError
        If the `center` is not a Point, or the `radius` is not a number or Basic
        instance, or the number of sides, `n`, is less than three.

    Notes
    =====

    A RegularPolygon can be instantiated with Polygon with the kwarg n.

    Regular polygons are instantiated with a center, radius, number of sides
    and a rotation angle. Whereas the arguments of a Polygon are vertices, the
    vertices of the RegularPolygon must be obtained with the vertices method.

    See Also
    ========

    sympy.geometry.point.Point, Polygon

    Examples
    ========

    >>> from sympy import RegularPolygon, Point
    >>> r = RegularPolygon(Point(0, 0), 5, 3)
    >>> r
    RegularPolygon(Point2D(0, 0), 5, 3, 0)
    >>> r.vertices[0]
    Point2D(5, 0)

    )_n_center_radius_rotr   c                 K   s   t t|||f\}}}t|fddi|}t|ts td| |jr1t| |dk r1td| tj	| |||fi |}||_
||_||_|jrU|dtj |  |_|S ||_|S )Nr9   r6   z r must be an Expr object, not %sr3   zn must be a >= 3, not %s)r,  r   r   r   r   r   	is_Numberr&   r   rH   rW  rX  rY  	is_numberr   rb   rZ  )rR   rP   r  r5   rotr=   objr/   r/   r0   rH     s    
zRegularPolygon.__new__   c                    sF   | j \}}}}t|  fdd|||fD \}}}| ||||S )Nc                    s    g | ]}|j dd  iqS )r5   r/   )r
  r,   dpsoptionsr/   r0   r1     r>   z.RegularPolygon._eval_evalf.<locals>.<listcomp>)rK   r(   func)rR   rL  rb  rP   r  r5   r;   r/   r`  r0   _eval_evalf  s    zRegularPolygon._eval_evalfc                 C   s   | j | j| j| jfS )a-  
        Returns the center point, the radius,
        the number of sides, and the orientation angle.

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> r = RegularPolygon(Point(0, 0), 5, 3)
        >>> r.args
        (Point2D(0, 0), 5, 3, 0)
        )rX  rY  rW  rZ  rl   r/   r/   r0   rK     s   zRegularPolygon.argsc                 C      dt | j S NzRegularPolygon(%s, %s, %s, %s)r>  rK   rl   r/   r/   r0   __str__     zRegularPolygon.__str__c                 C   re  rf  rg  rl   r/   r/   r0   __repr__  ri  zRegularPolygon.__repr__c                 C   s4   | j \}}}}t|| | jd  dtt|   S )zReturns the area.

        Examples
        ========

        >>> from sympy import RegularPolygon
        >>> square = RegularPolygon((0, 0), 1, 4)
        >>> square.area
        2
        >>> _ == square.length**2
        True
        r6      )rK   r   r   r   r   )rR   rP   r  r5   r]  r/   r/   r0   rS     s   &zRegularPolygon.areac                 C   s   | j d tt| j  S )a  Returns the length of the sides.

        The half-length of the side and the apothem form two legs
        of a right triangle whose hypotenuse is the radius of the
        regular polygon.

        Examples
        ========

        >>> from sympy import RegularPolygon
        >>> from sympy import sqrt
        >>> s = square_in_unit_circle = RegularPolygon((0, 0), 1, 4)
        >>> s.length
        sqrt(2)
        >>> sqrt((_/2)**2 + s.apothem**2) == s.radius
        True

        r6   )radiusr   r   rW  rl   r/   r/   r0   r   
  s   zRegularPolygon.lengthc                 C      | j S )a  The center of the RegularPolygon

        This is also the center of the circumscribing circle.

        Returns
        =======

        center : Point

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.ellipse.Ellipse.center

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 5, 4)
        >>> rp.center
        Point2D(0, 0)
        )rX  rl   r/   r/   r0   center      zRegularPolygon.centerc                 C   rm  )z
        Alias for center.

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 5, 4)
        >>> rp.circumcenter
        Point2D(0, 0)
        )rn  rl   r/   r/   r0   circumcenter<  s   zRegularPolygon.circumcenterc                 C   rm  )a  Radius of the RegularPolygon

        This is also the radius of the circumscribing circle.

        Returns
        =======

        radius : number or instance of Basic

        See Also
        ========

        sympy.geometry.line.Segment.length, sympy.geometry.ellipse.Circle.radius

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy import RegularPolygon, Point
        >>> radius = Symbol('r')
        >>> rp = RegularPolygon(Point(0, 0), radius, 4)
        >>> rp.radius
        r

        )rY  rl   r/   r/   r0   rl  K  s   zRegularPolygon.radiusc                 C   rm  )a  
        Alias for radius.

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy import RegularPolygon, Point
        >>> radius = Symbol('r')
        >>> rp = RegularPolygon(Point(0, 0), radius, 4)
        >>> rp.circumradius
        r
        )rl  rl   r/   r/   r0   circumradiush     zRegularPolygon.circumradiusc                 C   rm  )a3  CCW angle by which the RegularPolygon is rotated

        Returns
        =======

        rotation : number or instance of Basic

        Examples
        ========

        >>> from sympy import pi
        >>> from sympy.abc import a
        >>> from sympy import RegularPolygon, Point
        >>> RegularPolygon(Point(0, 0), 3, 4, pi/4).rotation
        pi/4

        Numerical rotation angles are made canonical:

        >>> RegularPolygon(Point(0, 0), 3, 4, a).rotation
        a
        >>> RegularPolygon(Point(0, 0), 3, 4, pi).rotation
        0

        rZ  rl   r/   r/   r0   rotationy  s   zRegularPolygon.rotationc                 C   s   | j ttj| j  S )a8  The inradius of the RegularPolygon.

        The apothem/inradius is the radius of the inscribed circle.

        Returns
        =======

        apothem : number or instance of Basic

        See Also
        ========

        sympy.geometry.line.Segment.length, sympy.geometry.ellipse.Circle.radius

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy import RegularPolygon, Point
        >>> radius = Symbol('r')
        >>> rp = RegularPolygon(Point(0, 0), radius, 4)
        >>> rp.apothem
        sqrt(2)*r/2

        )rl  r   r   rb   rW  rl   r/   r/   r0   apothem  s   zRegularPolygon.apothemc                 C   rm  )a&  
        Alias for apothem.

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy import RegularPolygon, Point
        >>> radius = Symbol('r')
        >>> rp = RegularPolygon(Point(0, 0), radius, 4)
        >>> rp.inradius
        sqrt(2)*r/2
        )ru  rl   r/   r/   r0   inradius  rr  zRegularPolygon.inradiusc                 C   s   | j d tj | j  S )a~  Measure of the interior angles.

        Returns
        =======

        interior_angle : number

        See Also
        ========

        sympy.geometry.line.LinearEntity.angle_between

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 4, 8)
        >>> rp.interior_angle
        3*pi/4

        r6   )rW  r   rb   rl   r/   r/   r0   interior_angle  s   zRegularPolygon.interior_anglec                 C   s   dt j | j S )a|  Measure of the exterior angles.

        Returns
        =======

        exterior_angle : number

        See Also
        ========

        sympy.geometry.line.LinearEntity.angle_between

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 4, 8)
        >>> rp.exterior_angle
        pi/4

        r6   )r   rb   rW  rl   r/   r/   r0   exterior_angle  s   zRegularPolygon.exterior_anglec                 C      t | j| jS )a  The circumcircle of the RegularPolygon.

        Returns
        =======

        circumcircle : Circle

        See Also
        ========

        circumcenter, sympy.geometry.ellipse.Circle

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 4, 8)
        >>> rp.circumcircle
        Circle(Point2D(0, 0), 4)

        )r   rn  rl  rl   r/   r/   r0   circumcircle     zRegularPolygon.circumcirclec                 C   ry  )a  The incircle of the RegularPolygon.

        Returns
        =======

        incircle : Circle

        See Also
        ========

        inradius, sympy.geometry.ellipse.Circle

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 4, 7)
        >>> rp.incircle
        Circle(Point2D(0, 0), 4*cos(pi/7))

        )r   rn  ru  rl   r/   r/   r0   incircle  r{  zRegularPolygon.incirclec                 C   s"   i }| j }| jD ]}|||< q|S )a  
        Returns a dictionary with keys, the vertices of the Polygon,
        and values, the interior angle at each vertex.

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> r = RegularPolygon(Point(0, 0), 5, 3)
        >>> r.angles
        {Point2D(-5/2, -5*sqrt(3)/2): pi/3,
         Point2D(-5/2, 5*sqrt(3)/2): pi/3,
         Point2D(5, 0): pi/3}
        )rw  rL   )rR   rf   angru   r/   r/   r0   rj   '  s
   

zRegularPolygon.anglesc                 C   s:   | j }t||j}|| jkrdS || jk rdS t| |S )aN  
        Return True if p is enclosed by (is inside of) self.

        Notes
        =====

        Being on the border of self is considered False.

        The general Polygon.encloses_point method is called only if
        a point is not within or beyond the incircle or circumcircle,
        respectively.

        Parameters
        ==========

        p : Point

        Returns
        =======

        encloses_point : True, False or None

        See Also
        ========

        sympy.geometry.ellipse.Ellipse.encloses_point

        Examples
        ========

        >>> from sympy import RegularPolygon, S, Point, Symbol
        >>> p = RegularPolygon((0, 0), 3, 4)
        >>> p.encloses_point(Point(0, 0))
        True
        >>> r, R = p.inradius, p.circumradius
        >>> p.encloses_point(Point((r + R)/2, 0))
        True
        >>> p.encloses_point(Point(R/2, R/2 + (R - r)/10))
        False
        >>> t = Symbol('t', real=True)
        >>> p.encloses_point(p.arbitrary_point().subs(t, S.Half))
        False
        >>> p.encloses_point(Point(5, 5))
        False

        FT)rn  r   r   rl  rv  r4   r   )rR   rN   rP   dr/   r/   r0   r   =  s   0

zRegularPolygon.encloses_pointc                 C   s   |  j |7  _ dS )a  Increment *in place* the virtual Polygon's rotation by ccw angle.

        See also: rotate method which moves the center.

        >>> from sympy import Polygon, Point, pi
        >>> r = Polygon(Point(0,0), 1, n=3)
        >>> r.vertices[0]
        Point2D(1, 0)
        >>> r.spin(pi/6)
        >>> r.vertices[0]
        Point2D(sqrt(3)/2, 1/2)

        See Also
        ========

        rotation
        rotate : Creates a copy of the RegularPolygon rotated about a Point

        Nrs  )rR   angler/   r/   r0   spinw  s   zRegularPolygon.spinNc                 C   s*   t | | j }| j|7  _t|||S )a  Override GeometryEntity.rotate to first rotate the RegularPolygon
        about its center.

        >>> from sympy import Point, RegularPolygon, pi
        >>> t = RegularPolygon(Point(1, 0), 1, 3)
        >>> t.vertices[0] # vertex on x-axis
        Point2D(2, 0)
        >>> t.rotate(pi/2).vertices[0] # vertex on y axis now
        Point2D(0, 2)

        See Also
        ========

        rotation
        spin : Rotates a RegularPolygon in place

        )typerK   rZ  r   rJ  )rR   r  r   r  r/   r/   r0   rJ    s   zRegularPolygon.rotater   c                 C   sn   |rt |dd}| j| j ||j|j S ||kr$t| j ||S | j\}}}}||9 }| ||||S )a  Override GeometryEntity.scale since it is the radius that must be
        scaled (if x == y) or else a new Polygon must be returned.

        >>> from sympy import RegularPolygon

        Symmetric scaling returns a RegularPolygon:

        >>> RegularPolygon((0, 0), 1, 4).scale(2, 2)
        RegularPolygon(Point2D(0, 0), 2, 4, 0)

        Asymmetric scaling returns a kite as a Polygon:

        >>> RegularPolygon((0, 0), 1, 4).scale(2, 1)
        Polygon(Point2D(2, 0), Point2D(0, 1), Point2D(-2, 0), Point2D(0, -1))

        r6   r   )r   	translaterK   scaler4   rL   rc  )rR   rX   rY   r   rP   r  r5   r]  r/   r/   r0   r    s   zRegularPolygon.scalec                 C   st   | j \}}}}| jd }|| }||}||}	|	| }
td|
}td|}||}||7 }| || ||S )a5  Override GeometryEntity.reflect since this is not made of only
        points.

        Examples
        ========

        >>> from sympy import RegularPolygon, Line

        >>> RegularPolygon((0, 0), 1, 4).reflect(Line((0, 1), slope=-2))
        RegularPolygon(Point2D(4/5, 2/5), -1, 4, atan(4/3))

        r   rq   )rK   rL   reflectr   closing_anglerc  )rR   r   rP   r  r5   r]  ru   r~  ccvvddl1l2r}  r/   r/   r0   r    s   





zRegularPolygon.reflectc                    sD   | j  t| j| jdtj | j  fddt| jD S )a  The vertices of the RegularPolygon.

        Returns
        =======

        vertices : list
            Each vertex is a Point.

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import RegularPolygon, Point
        >>> rp = RegularPolygon(Point(0, 0), 5, 4)
        >>> rp.vertices
        [Point2D(5, 0), Point2D(0, 5), Point2D(-5, 0), Point2D(0, -5)]

        r6   c              	      sB   g | ]}t  jt|     jt|    qS r/   )r   rX   r   rY   r   )r-   r   rP   r  r]  ru   r/   r0   r1     s    :z+RegularPolygon.vertices.<locals>.<listcomp>)rX  absrY  rZ  r   rb   rW  rQ   rl   r/   r  r0   rL     s   
zRegularPolygon.verticesc                 C   s0   t |tsdS t |tst|| S | j|jkS )NF)r   r4   rE   __eq__rK   )rR   r   r/   r/   r0   r    s
   

zRegularPolygon.__eq__c                    s
   t   S r   )super__hash__rl   	__class__r/   r0   r    s   
zRegularPolygon.__hash__)r   )r_  r   )r   r   N)#rP  rQ  rR  rS  rT  rH   rd  rU  rK   rh  rj  rS   r   rn  rv   rp  rl  rq  rt  ru  rv  rw  rx  rz  r|  rj   r   r  rJ  r  r  rL   r  r  __classcell__r/   r/   r  r0   rE     s^    =
















:


rE   c                   @   s   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dd Z
d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edd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zd.S )/rI   a  
    A polygon with three vertices and three sides.

    Parameters
    ==========

    points : sequence of Points
    keyword: asa, sas, or sss to specify sides/angles of the triangle

    Attributes
    ==========

    vertices
    altitudes
    orthocenter
    circumcenter
    circumradius
    circumcircle
    inradius
    incircle
    exradii
    medians
    medial
    nine_point_circle

    Raises
    ======

    GeometryError
        If the number of vertices is not equal to three, or one of the vertices
        is not a Point, or a valid keyword is not given.

    See Also
    ========

    sympy.geometry.point.Point, Polygon

    Examples
    ========

    >>> from sympy import Triangle, Point
    >>> Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
    Triangle(Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))

    Keywords sss, sas, or asa can be used to give the desired
    side lengths (in order) and interior angles (in degrees) that
    define the triangle:

    >>> Triangle(sss=(3, 4, 5))
    Triangle(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
    >>> Triangle(asa=(30, 1, 30))
    Triangle(Point2D(0, 0), Point2D(1, 0), Point2D(1/2, sqrt(3)/6))
    >>> Triangle(sas=(1, 45, 2))
    Triangle(Point2D(0, 0), Point2D(2, 0), Point2D(sqrt(2)/2, sqrt(2)/2))

    c                    s  t |dkr9d v rtdd  d D  S d v r$tdd  d D  S d v r3tdd  d D  S d	}t| fd
d|D }g }|D ]}|rQ||d krQqF|| qFt |dkri|d |d kri|  d}|t |d k rt |dkrt|| ||d  ||d  gtd\}}	}
t	
||	|
r|||< d ||d < ||d  |d7 }|t |d k rt |dksyttdd |}t |dkrtj| g|R i  S t |dkrt|i  S t	|i  S )Nr3   sssc                 S      g | ]}t |qS r/   r   r:   r/   r/   r0   r1   B  r6  z$Triangle.__new__.<locals>.<listcomp>asac                 S   r  r/   r   r:   r/   r/   r0   r1   D  r6  sasc                 S   r  r/   r   r:   r/   r/   r0   r1   F  r6  z;Triangle instantiates with three points or a valid keyword.c                    r7   r8   r   r:   r<   r/   r0   r1   J  r>   r?   r   r   r@   r6   )keyc                 S   s   | d uS r   r/   r   r/   r/   r0   <lambda>`  s    z"Triangle.__new__.<locals>.<lambda>)rB   _sss_asa_sasr   rC   rF   sortedr   r   rG   rA   filterr   rH   r   )rJ   rK   r=   msgrL   rM   rN   r.   r;   rO   rP   r/   r<   r0   rH   ?  sD   	zTriangle.__new__c                 C   rm  )a  The triangle's vertices

        Returns
        =======

        vertices : tuple
            Each element in the tuple is a Point

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
        >>> t.vertices
        (Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))

        )rK   rl   r/   r/   r0   rL   i  ro  zTriangle.verticesc                 C   s   t |tsdS dd | jD \}}}dd |jD }dd }||||g|R  pY||||g|R  pY||||g|R  pY||||g|R  pY||||g|R  pY||||g|R  S )a  Is another triangle similar to this one.

        Two triangles are similar if one can be uniformly scaled to the other.

        Parameters
        ==========

        other: Triangle

        Returns
        =======

        is_similar : boolean

        See Also
        ========

        sympy.geometry.entity.GeometryEntity.is_similar

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
        >>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -3))
        >>> t1.is_similar(t2)
        True

        >>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -4))
        >>> t1.is_similar(t2)
        False

        Fc                 S   r   r/   r   r-   r   r/   r/   r0   r1     r   z'Triangle.is_similar.<locals>.<listcomp>c                 S   r   r/   r  r  r/   r/   r0   r1     r   c           	      S   s<   t | | }t || }t || }t||kot||kS r   )r   bool)	u1u2u3v1v2v3r  r  e3r/   r/   r0   _are_similar  s   z)Triangle.is_similar.<locals>._are_similar)r   r4   r   )t1t2s1_1s1_2s1_3s2r  r/   r/   r0   
is_similar  s    
"zTriangle.is_similarc                 C      t dd | jD  S )ab  Are all the sides the same length?

        Returns
        =======

        is_equilateral : boolean

        See Also
        ========

        sympy.geometry.entity.GeometryEntity.is_similar, RegularPolygon
        is_isosceles, is_right, is_scalene

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
        >>> t1.is_equilateral()
        False

        >>> from sympy import sqrt
        >>> t2 = Triangle(Point(0, 0), Point(10, 0), Point(5, 5*sqrt(3)))
        >>> t2.is_equilateral()
        True

        c                 s   r   r   r  r   r/   r/   r0   r     r   z*Triangle.is_equilateral.<locals>.<genexpr>)r"   r   rl   r/   r/   r0   is_equilateral  s   zTriangle.is_equilateralc                 C   s   t dd | jD S )a  Are two or more of the sides the same length?

        Returns
        =======

        is_isosceles : boolean

        See Also
        ========

        is_equilateral, is_right, is_scalene

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(2, 4))
        >>> t1.is_isosceles()
        True

        c                 s   r   r   r  r   r/   r/   r0   r     r   z(Triangle.is_isosceles.<locals>.<genexpr>r!   r   rl   r/   r/   r0   is_isosceles  s   zTriangle.is_isoscelesc                 C   r  )a  Are all the sides of the triangle of different lengths?

        Returns
        =======

        is_scalene : boolean

        See Also
        ========

        is_equilateral, is_isosceles, is_right

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(1, 4))
        >>> t1.is_scalene()
        True

        c                 s   r   r   r  r   r/   r/   r0   r   	  r   z&Triangle.is_scalene.<locals>.<genexpr>r  rl   r/   r/   r0   
is_scalene  s   zTriangle.is_scalenec                 C   sB   | j }t|d |d p t|d |d p t|d |d S )a  Is the triangle right-angled.

        Returns
        =======

        is_right : boolean

        See Also
        ========

        sympy.geometry.line.LinearEntity.is_perpendicular
        is_equilateral, is_isosceles, is_scalene

        Examples
        ========

        >>> from sympy import Triangle, Point
        >>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
        >>> t1.is_right()
        True

        r   r   r6   )r   r   is_perpendicularrR   r   r/   r/   r0   is_right	  s   zTriangle.is_rightc              	   C   sR   | j }| j}|d |d |d |d |d |d |d |d |d iS )a  The altitudes of the triangle.

        An altitude of a triangle is a segment through a vertex,
        perpendicular to the opposite side, with length being the
        height of the vertex measured from the line containing the side.

        Returns
        =======

        altitudes : dict
            The dictionary consists of keys which are vertices and values
            which are Segments.

        See Also
        ========

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

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.altitudes[p1]
        Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))

        r   r   r6   )r   rL   perpendicular_segmentrR   r   ru   r/   r/   r0   	altitudes#	  s   zTriangle.altitudesc                 C   s2   | j }| j}t||d  t||d  d S )a  The orthocenter of the triangle.

        The orthocenter is the intersection of the altitudes of a triangle.
        It may lie inside, outside or on the triangle.

        Returns
        =======

        orthocenter : Point

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.orthocenter
        Point2D(0, 0)

        r   r   )r  rL   r   r   )rR   r;   ru   r/   r/   r0   orthocenterG	  s   &zTriangle.orthocenterc                 C   s$   dd | j D \}}}||d S )a  The circumcenter of the triangle

        The circumcenter is the center of the circumcircle.

        Returns
        =======

        circumcenter : Point

        See Also
        ========

        sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.circumcenter
        Point2D(1/2, 1/2)
        c                 S   s   g | ]}|  qS r/   )perpendicular_bisector)r-   rX   r/   r/   r0   r1   	  r6  z)Triangle.circumcenter.<locals>.<listcomp>r   )r   r   )rR   r;   rO   rP   r/   r/   r0   rp  f	  s   zTriangle.circumcenterc                 C   s   t | j| jd S )a  The radius of the circumcircle of the triangle.

        Returns
        =======

        circumradius : number of Basic instance

        See Also
        ========

        sympy.geometry.ellipse.Circle.radius

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy import Point, Triangle
        >>> a = Symbol('a')
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, a)
        >>> t = Triangle(p1, p2, p3)
        >>> t.circumradius
        sqrt(a**2/4 + 1/4)
        r   )r   rn   rp  rL   rl   r/   r/   r0   rq  	  s   zTriangle.circumradiusc                 C   ry  )a  The circle which passes through the three vertices of the triangle.

        Returns
        =======

        circumcircle : Circle

        See Also
        ========

        sympy.geometry.ellipse.Circle

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.circumcircle
        Circle(Point2D(1/2, 1/2), sqrt(2)/2)

        )r   rp  rq  rl   r/   r/   r0   rz  	  s   zTriangle.circumcirclec                 C   s   dd | j D }| j}| j}t|d t|d ||d d }t|d t|d ||d d }t|d t|d ||d d }|d ||d ||d |iS )a  The angle bisectors of the triangle.

        An angle bisector of a triangle is a straight line through a vertex
        which cuts the corresponding angle in half.

        Returns
        =======

        bisectors : dict
            Each key is a vertex (Point) and each value is the corresponding
            bisector (Segment).

        See Also
        ========

        sympy.geometry.point.Point, sympy.geometry.line.Segment

        Examples
        ========

        >>> from sympy import Point, Triangle, Segment
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> from sympy import sqrt
        >>> t.bisectors()[p2] == Segment(Point(1, 0), Point(0, sqrt(2) - 1))
        True

        c                 S   r  r/   )r   )r-   lr/   r/   r0   r1   	  r6  z&Triangle.bisectors.<locals>.<listcomp>r   r   r6   )r   rL   incenterr   r   r   )rR   r   ru   rP   r  r  l3r/   r/   r0   rO  	  s    &&&zTriangle.bisectorsc                    st   | j  t fdddD }t|}| j}t|tdd |D | }t|tdd |D | }t||S )a  The center of the incircle.

        The incircle is the circle which lies inside the triangle and touches
        all three sides.

        Returns
        =======

        incenter : Point

        See Also
        ========

        incircle, sympy.geometry.point.Point

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.incenter
        Point2D(1 - sqrt(2)/2, 1 - sqrt(2)/2)

        c                    s   g | ]} | j qS r/   r  r,   r   r/   r0   r1   	  s    z%Triangle.incenter.<locals>.<listcomp>)r   r6   r   c                 S   r   r/   r   r-   vir/   r/   r0   r1   	  r   c                 S   r   r/   r   r  r/   r/   r0   r1   	  r   )r   r   rc   rL   r   dotr   )rR   r  rN   ru   rX   rY   r/   r  r0   r  	  s     
zTriangle.incenterc                 C   s   t d| j | j S )a  The radius of the incircle.

        Returns
        =======

        inradius : number of Basic instance

        See Also
        ========

        incircle, sympy.geometry.ellipse.Circle.radius

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(4, 0), Point(0, 3)
        >>> t = Triangle(p1, p2, p3)
        >>> t.inradius
        1

        r6   )r   rS   ro   rl   r/   r/   r0   rv  
  s   zTriangle.inradiusc                 C   ry  )a!  The incircle of the triangle.

        The incircle is the circle which lies inside the triangle and touches
        all three sides.

        Returns
        =======

        incircle : Circle

        See Also
        ========

        sympy.geometry.ellipse.Circle

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(2, 0), Point(0, 2)
        >>> t = Triangle(p1, p2, p3)
        >>> t.incircle
        Circle(Point2D(2 - sqrt(2), 2 - sqrt(2)), 2 - sqrt(2))

        )r   r  rv  rl   r/   r/   r0   r|  
  s   zTriangle.incirclec              	   C   s   | j }|d j}|d j}|d j}|| | d }| j}| j d t|||  | j d t|||  | j d t|||  i}|S )ao  The radius of excircles of a triangle.

        An excircle of the triangle is a circle lying outside the triangle,
        tangent to one of its sides and tangent to the extensions of the
        other two.

        Returns
        =======

        exradii : dict

        See Also
        ========

        sympy.geometry.polygon.Triangle.inradius

        Examples
        ========

        The exradius touches the side of the triangle to which it is keyed, e.g.
        the exradius touching side 2 is:

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(6, 0), Point(0, 2)
        >>> t = Triangle(p1, p2, p3)
        >>> t.exradii[t.sides[2]]
        -2 + sqrt(10)

        References
        ==========

        .. [1] https://mathworld.wolfram.com/Exradius.html
        .. [2] https://mathworld.wolfram.com/Excircles.html

        r   r   r6   )r   r   rS   r   )rR   r   r;   rO   rP   r   rS   exradiir/   r/   r0   r  9
  s   &


zTriangle.exradiic           
   
   C   s  | j }| j}|d j}|d j}|d j}|d j|d j|d jg}|d j|d j|d jg}t| |d  ||d   ||d  | | |   t||d  ||d   ||d  || |   t||d  ||d   ||d  || |   t| |d  ||d   ||d  | | |   t||d  ||d   ||d  || |   t||d  ||d   ||d  || |   d}|d t|d |d |d t|d |d |d t|d	 |d
 i}	|	S )as  Excenters of the triangle.

        An excenter is the center of a circle that is tangent to a side of the
        triangle and the extensions of the other two sides.

        Returns
        =======

        excenters : dict


        Examples
        ========

        The excenters are keyed to the side of the triangle to which their corresponding
        excircle is tangent: The center is keyed, e.g. the excenter of a circle touching
        side 0 is:

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(6, 0), Point(0, 2)
        >>> t = Triangle(p1, p2, p3)
        >>> t.excenters[t.sides[0]]
        Point2D(12*sqrt(10), 2/3 + sqrt(10)/3)

        See Also
        ========

        sympy.geometry.polygon.Triangle.exradii

        References
        ==========

        .. [1] https://mathworld.wolfram.com/Excircles.html

        r   r   r6   )rT   rV   x3rU   rW   y3rT   rU   rV   rW   r  r  )r   rL   r   rX   rY   r   r   )
rR   r   ru   r;   rO   rP   rX   rY   
exc_coords	excentersr/   r/   r0   r  k
  s&   &


622622
zTriangle.excentersc              	   C   sX   | j }| j}|d t|d |d j|d t|d |d j|d t|d |d jiS )a  The medians of the triangle.

        A median of a triangle is a straight line through a vertex and the
        midpoint of the opposite side, and divides the triangle into two
        equal areas.

        Returns
        =======

        medians : dict
            Each key is a vertex (Point) and each value is the median (Segment)
            at that point.

        See Also
        ========

        sympy.geometry.point.Point.midpoint, sympy.geometry.line.Segment.midpoint

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.medians[p1]
        Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))

        r   r   r6   )r   rL   r   midpointr  r/   r/   r0   medians
  s   zTriangle.mediansc                 C   s$   | j }t|d j|d j|d jS )a  The medial triangle of the triangle.

        The triangle which is formed from the midpoints of the three sides.

        Returns
        =======

        medial : Triangle

        See Also
        ========

        sympy.geometry.line.Segment.midpoint

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.medial
        Triangle(Point2D(1/2, 0), Point2D(1/2, 1/2), Point2D(0, 1/2))

        r   r   r6   )r   rI   r  r  r/   r/   r0   medial
  s   zTriangle.medialc                 C   s   t | jj S )a  The nine-point circle of the triangle.

        Nine-point circle is the circumcircle of the medial triangle, which
        passes through the feet of altitudes and the middle points of segments
        connecting the vertices and the orthocenter.

        Returns
        =======

        nine_point_circle : Circle

        See also
        ========

        sympy.geometry.line.Segment.midpoint
        sympy.geometry.polygon.Triangle.medial
        sympy.geometry.polygon.Triangle.orthocenter

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.nine_point_circle
        Circle(Point2D(1/4, 1/4), sqrt(2)/4)

        )r   r  rL   rl   r/   r/   r0   nine_point_circle
  s   zTriangle.nine_point_circlec                 C   s   |   r| jS t| j| jS )a  The Euler line of the triangle.

        The line which passes through circumcenter, centroid and orthocenter.

        Returns
        =======

        eulerline : Line (or Point for equilateral triangles in which case all
                    centers coincide)

        Examples
        ========

        >>> from sympy import Point, Triangle
        >>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
        >>> t = Triangle(p1, p2, p3)
        >>> t.eulerline
        Line2D(Point2D(0, 0), Point2D(1/2, 1/2))

        )r  r  r   rp  rl   r/   r/   r0   	eulerline  s   zTriangle.eulerlineN)rP  rQ  rR  rS  rH   rU  rL   r  r  r  r  r  r  r  rp  rq  rz  rO  r  rv  r|  r  r  r  r  r  r  r/   r/   r/   r0   rI     sN    9*
6
#



(
"


1
>
#

rI   c                 C   s   | t  d S )zAReturn the radian value for the given degrees (pi = 180 degrees).   r   )r~  r/   r/   r0   rad%  rm   r  c                 C   s   | t  d S )zAReturn the degree value for the given radians (pi = 180 degrees).r  r  )r  r/   r/   r0   deg*  rm   r  c                 C   s   t t| }|S r   )r   r  )r~  rvr/   r/   r0   _slope/  s   r  c                 C   s>   t dt| dt |dftd| dd }td|df|S )z8Return triangle having side with length l on the x-axis.rq   r   r   r  )r   r  r   rI   )d1r  d2xyr/   r/   r0   r  4  s   r  c                 C   sL   t d|}t | df|}dd ||D }|sdS |d }td| df|S )z7Return triangle having side of length l1 on the x-axis.rq   r   c                 S   s   g | ]}|j jr|qS r/   )rY   is_nonnegativer:   r/   r/   r0   r1   ?  r2   z_sss.<locals>.<listcomp>N)r   r   rI   )r  r  r  c1c2interr   r/   r/   r0   r  ;  s   
r  c                 C   sB   t dd}t |d}t tt||  tt||  }t|||S )z9Return triangle having side with length l2 on the x-axis.r   )r   r   r  r   rI   )r  r~  r  r   r   p3r/   r/   r0   r  F  s   

"r  )E
sympy.corer   r   r   r   r   sympy.core.evalfr   sympy.core.sortingr   r	   sympy.core.symbolr
   r   r   $sympy.functions.elementary.complexesr   $sympy.functions.elementary.piecewiser   (sympy.functions.elementary.trigonometricr   r   r   ellipser   r   r   r   
exceptionsr   r   r   r   r   ry   r   sympy.logicr   sympy.matricesr   sympy.simplify.simplifyr   sympy.solvers.solversr    sympy.utilities.iterablesr!   r"   r#   r$   r%   sympy.utilities.miscr&   r'   mpmath.libmp.libmpfr(   r  rQ   rX   rY   r   r4   rE   rI   r  r  r  r  r  r  r/   r/   r/   r0   <module>   sd              z    }      &