
    \hk@                       S SK JrJrJrJrJr  S SKJr  S SKJ	r	J
r
  S SKJrJrJr  S SKJr  S SKJr  S SKJrJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJrJ r J!r!  SSK"J#r#  S SK$J%r%  S SK&J'r'  S SK(J)r)  S SK*J+r+  S SK,J-r-J.r.J/r/J0r0J1r1  S SK2J3r3J4r4  S SK5J6r6  S SK7r7\8" S5       V s/ s H
  n \" SSS9PM     sn u  r9r:r; " S S\5      r< " S S\<5      r= " S S\<5      r>S  r?S! r@S" rAS# rBS$ rCS% rDgs  sn f )&    )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_dpsN   polygon_dummyTrealc                   <   \ rS rSrSrSrSS.S jr\S 5       r\	S 5       r
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       rS"S jrS"S jrS rS"S jr\S 5       r\S 5       rS rS rS#S jrS rS#S jrS rS rS rS rS$S jrS r S  r!S"S! jr"Sr#g)%Polygon   a  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   )nc                   U(       aX  [        U5      n[        U5      S:X  a  UR                  U5        O![        U5      S:X  a  UR                  SU5        [	        U0 UD6$ U Vs/ s H  n[        U4SS0UD6PM     nn/ nU H%  nU(       a
  XvS   :X  a  M  UR                  U5        M'     [        U5      S:  a  US   US   :X  a  UR                  5         SnU[        U5      S-
  :  a  [        U5      S:  a  Xh   XhS-      XhS-      pn[
        R                  " XIU
5      (       a+  UR                  US-   5        XJ:X  a  UR                  U5        OUS-  nU[        U5      S-
  :  a  [        U5      S:  a  M  [        U5      n[        U5      S:  a  [        R                  " U /UQ70 UD6$ [        U5      S:X  a  [        U0 UD6$ [        U5      S:X  a  [        U0 UD6$ [        U0 UD6$ s  snf )N   r(   dimr   r   )listlenappendinsertRegularPolygonr   popis_collinearr   __new__Triangler   )clsr0   argskwargsaverticesnoduppibcs              N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/geometry/polygon.pyr=   Polygon.__new__z   s   :D4yA~ATaAq!!426227;<t!E!--f-t< ABiLLO  u:>eBi583IIK #e*q. SZ!^h!eeEl!A!!!**		!a% 6IIaLQ #e*q. SZ!^ ;x=1!))#CCFCC]aX000]aH///(-f--? =s   $G,c                     SnU R                   n[        [        U5      5       H2  nX#S-
     R                   u  pEX#   R                   u  pgXU-  Xe-  -
  -  nM4     [        U5      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   r2   )r@   ranger7   r   )selfarear@   rF   x1y1x2y2s           rI   rN   Polygon.area   si    R yys4y!Aa%[%%FBW\\FBrEBEM!D " ~!!    c                     X-
  nX -
  n[        UR                  UR                  -  UR                  UR                  -  -
  5      nUR                  nUc  [	        S5      eU$ )zReturn 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
zCan't determine orientation)r   xyis_nonpositive
ValueError)rB   rG   rH   bacat_arearess          rI   _is_clockwisePolygon._is_clockwise   sZ     UU"$$rtt)bdd244i/0##;:;;
rT   c                 &   U R                   n[        U5      n0 n[        U5       Hl  nXS-
     XS-
     X   pvn[        Xe5      R	                  [        Xg5      5      nU R                  XVU5      (       a  S[        R                  -  U-
  X6'   Mh  XU'   Mn     [        UR                  5       5      [        R                  -  S-
  US-
  -  S-
  R                  n	U	(       a'  S[        R                  -  n
U H  nXU   -
  X6'   M     U$ U	c  [        S5      eU$ )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)

r2   r   z(could not determine Polygon orientation.)rC   r7   rL   r   angle_betweenr^   r   Pisumvaluesis_positiverY   )rM   r@   r0   retrF   rB   rG   rH   
reflex_angwrongtwo_pis              rI   anglesPolygon.angles   s   < }}IqAq5k4A;!AQ00Q;J!!!**144*,#A  cjjl#ADD(*QU3a7DDqttVFa&  
 ]GHH
rT   c                 4    U R                   S   R                  $ )Nr   )rC   ambient_dimensionrM   s    rI   rm   Polygon.ambient_dimension   s    }}Q111rT   c                     SnU R                   n[        [        U5      5       H  nXUS-
     R                  X#   5      -  nM      [	        U5      $ )aJ  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   )rC   rL   r7   distancer   )rM   rE   r@   rF   s       rI   	perimeterPolygon.perimeter$  sL    . }}s4y!Aa!e%%dg..A "{rT   c                 ,    [        U R                  5      $ )a  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)

)r6   r@   rn   s    rI   rC   Polygon.verticesA  s    D DIIrT   c                 <   SSU R                   -  -  nSu  p#U R                  n[        [        U5      5       HA  nXES-
     R                  u  pgXE   R                  u  pXi-  X-  -
  n
X*Xh-   -  -  nX:Xy-   -  -  nMC     [	        [        X-  5      [        X-  5      5      $ )aT  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   )rN   r@   rL   r7   r   r   )rM   Acxcyr@   rF   rO   rP   rQ   rR   vs              rI   centroidPolygon.centroide  s    0 q{Oyys4y!Aa%[%%FBW\\FBARW+BRW+B " Xad^Xad^44rT   Nc                 n   Su  p#nU R                   n[        [        U5      5       Hz  nXVS-
     R                  u  pxXV   R                  u  pXz-  X-  -
  nX(S-  X-  -   U
S-  -   U-  -  nX7S-  Xy-  -   U	S-  -   U-  -  nXGU
-  SU-  U-  -   SU	-  U
-  -   X-  -   U-  -  nM|     U R                  nU R
                  S   nU R
                  S   nUS-  XS-  -  -
  nUS-  XS-  -  -
  nUS-  XU-  -  -
  nUc  UUU4$ XUS   U-
  S-  -  -   nUXS   U-
  S-  -  -   nUXS   U-
  US   U-
  -  -  -   nX#U4$ )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   r2   r         )rC   rL   r7   r@   rN   r}   )rM   pointI_xxI_yyI_xyr@   rF   rO   rP   rQ   rR   r|   ry   c_xc_yI_xx_cI_yy_cI_xy_cs                     rI   second_moment_of_areaPolygon.second_moment_of_area  s   J #D}}s4y!AA#Y^^FBW\\FBAURU]RU*A--DURU]RU*A--DUQrT"W_qtBw.699D " IImmAmmAr'aaj)r'aaj)r'aSk*=66))U1Xc\A-..1Xc\A-..1Xc\E!HSL9::4rT   c                    U(       a  U R                   u  p#OU R                   nUu  p#[        USS9n[        U[        R                  S9nU R	                  U5      nU R	                  U5      nUS   R
                  US   R
                  ::  a  US   OUS   nUS   R
                  US   R
                  ::  a  US   OUS   n	UR                   R                  U-
  UR
                  -  n
U	R                   R                  U-
  U	R
                  -  nX4$ )ac  
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   )r}   r   r   Infinitycut_sectionrN   rW   rV   )rM   r   xcych_linev_lineh_polyv_polypoly_1poly_2Q_xQ_ys               rI   first_moment_of_areaPolygon.first_moment_of_area  s    ` ]]FBMMEFBe1%e1::.!!&)!!&)$Qinnq	>F1I$Qinnq	>F1I  2%v{{2  2%v{{2xrT   c                 8    U R                  5       nUS   US   -   $ )a7  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   )rM   second_moments     rI   polar_second_moment_of_area#Polygon.polar_second_moment_of_area  s'    6 224Q-"222rT   c                    U R                   u  p#Uc0  U R                  u  pEpg[        X5-
  Xs-
  5      n[        X$-
  Xb-
  5      n	OUR                  U-
  nUR                  U-
  n	U R                  5       n
U
S   U-  nU
S   U	-  nX4$ )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

r   r   )r}   boundsmaxrW   rV   r   )rM   r   x_cy_cx_miny_minx_maxy_maxrW   rV   r   S_xS_ys                rI   section_modulusPolygon.section_modulus,  s    T ===)-&E%CK-ACK-A #A#A113Aq Aq xrT   c           	          / nU R                   n[        [        U5      * S5       H%  nUR                  [	        X#   X#S-      5      5        M'     U$ )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   )rC   rL   r7   r8   r   )rM   r]   r@   rF   s       rI   sidesPolygon.sidesh  sI    6 }}D	z1%AJJwtwU45 &
rT   c                     U R                   nU Vs/ s H  o"R                  PM     nnU Vs/ s H  o"R                  PM     nn[        U5      [        U5      [	        U5      [	        U5      4$ s  snf s  snf )zgReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding
rectangle for the geometric figure.

)rC   rV   rW   minr   )rM   vertsrE   xsyss        rI   r   Polygon.bounds  s`      !5acc5! !5acc5!BR#b'3r733 "!s
   A-A2c                    U R                   nU R                  US   US   US   5      n[        S[        U5      5       H+  nX R                  XS-
     XS-
     X   5      -  (       d  M+    g   U R                  n[        U5       H~  u  p5UR                  n[        U[        U5      S-
  :X  a  SOSUS-
  5       HF  nXG   nUR                  U;  d  M  UR                  U;  d  M+  UR                  U5      n	U	(       d  ME      g   M     g)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

r4   r   r   r2   FT)
rC   r^   rL   r7   r   	enumerater@   p1p2intersection)
rM   r@   cwrF   r   siptsjsjhits
             rI   	is_convexPolygon.is_convex  s    8 }}R$r(DG<q#d)$A&&tE{DQKIII % 

u%EA''CSZ!^ 31AEBX55#S(8//"-Cs$ C & rT   c                   ^ [        TSS9mTU R                  ;   d$  [        U4S jU R                   5       5      (       a  g/ nU R                   H-  nUR	                  UT-
  5        US   R
                  (       d  M-    g   [        U6 nUR                  n[        [        [        U5      * S5      5      nUR                  5       (       a}  SnU Ht  nXX   n	XXS-      n
U	R                  * U
R                  U	R                  -
  -  U	R                  * U
R                  U	R                  -
  -  -
  R                  nUc  UnMn  XLd  Mt    g   gSnUS	   R                  u  pUSS  Ho  nXX   R                  u  nnS	[        UU5      :  aH  S	[!        UU5      ::  a8  S	[!        X5      ::  a)  UU:w  a#  U* X-
  -  UU-
  -  U-   nX:X  d  S	U::  a  U(       + nUUpMq     U$ )
a\  
Return True if p is enclosed by (is inside of) self.

Notes
=====

Being on the border of self is considered False.

Parameters
==========

p : Point

Returns
=======

encloses_point : True, False or None

See Also
========

sympy.geometry.point.Point, 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

r2   r3   c              3   .   >#    U  H
  nTU;   v   M     g 7fNr/   ).0srE   s     rI   	<genexpr>)Polygon.encloses_point.<locals>.<genexpr>  s     $@ZQ!VZ   Fr4   Nr   Tr   )r   rC   anyr   r8   free_symbolsr-   r@   r6   rL   r7   r   rW   rV   is_negativer   r   )rM   rE   litr|   polyr@   indicesorientationrF   rB   rG   testhit_oddp1xp1yp2xp2yxinterss    `                rI   encloses_pointPolygon.encloses_point  s   T !O$@TZZ$@!@!@ AJJq1u2w### 
 }
 yyuc$iZ+,>>KGQK##acc	*qssdQSS133Y-??LL&"&K,   7<<Aw||HC3sC= C%CM)#:(+tci&8#)&Ds&JG"zQ'\.5+C  rT   c           	         [        USS9nUR                  S U R                   5       ;   a  [        SUR                  -  5      e/ nU R                  nSnU R
                   H_  nUR                  U-  nXW-   nUR                  U5      R                  X"U-
  U-  5      n	UR                  U	[        XR:*  X(:  5      45        UnMa     [        U6 $ )aC  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              3   8   #    U  H  oR                   v   M     g 7fr   )name)r   fs     rI   r   *Polygon.arbitrary_point.<locals>.<genexpr>F  s     8&7ff&7   zFSymbol %s already appears in object and cannot be used as a parameter.r   )r   r   r   rY   rr   r   lengtharbitrary_pointsubsr8   r   r   )
rM   	parametertr   rr   perim_fraction_startr   side_perim_fractionperim_fraction_endpts
             rI   r   Polygon.arbitrary_point  s    V ID)668d&7&788ehihnhnnooNN	 A"#((9"4!5!K""9-22,,.AACBLLc.3Q5KLNP#5   %  rT   c                 ,   [        U[        5      (       d  [        XR                  S9n[        U[        5      (       d  [	        S5      eUR
                  (       a  [        S5      eSnU R                  [        5      nUR                   HU  u  pV[        XQ-
  [        SS9nU(       d  M  US   [           n[        UR                  [        U5      5      S:X  a  X(0s  $ SnMW     U(       a  [	        S[        U 5      -  5      e[	        S	[        U 5      -  5      e)
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   rm   rY   r   NotImplementedErrorr   Tr@   r   r   r   r&   )	rM   otherr   unknownrE   r   condsolvalues	            rI   parameter_valuePolygon.parameter_valueU  s    %//%%;%;<E%&&455%&?@@  #HB
AD1CF1IE		!U+,4z!G  ;ioMNN3ioEFFrT   c                      [        USS9nUSS/$ )ai  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   )rM   r   r   s      rI   plot_intervalPolygon.plot_intervalj  s    0 94(1ayrT   c                    / n[        U[        5      (       a  UR                  OU/nU R                   H,  nU H#  nUR                  UR	                  U5      5        M%     M.     [        [        U5      5      nU Vs/ s H  n[        U[        5      (       d  M  UPM     nnU Vs/ s H  n[        U[        5      (       d  M  UPM     nnU(       au  U(       an  [        [        U V	V
s/ s H  o  H  oU
;   d  M
  U	PM     M     sn
n	5      5      nU(       a  U H  nUR                  U5        M     [        [        X-   5      5      $ [        [        U5      5      $ s  snf s  snf s  sn
n	f )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)]
)r   r-   r   extendr   r6   r"   r   r   remover
   )rM   ointersection_resultksideside1entitypointssegmentsr   segmentpoints_in_segmentsrF   s                rI   r   Polygon.intersection  s(   J !!!W--AGGA3JJD#**4+<+<U+CD   #4(;#<=':X':VjQV>W&':X)<\)<v
6SZ@[F)<\h!%dv+rveU]'jqaqEU]Ev+r&s!t!+AMM!$ , 1233 3455 Y\ ,ss$   ;EE$EE&E#8
E#c                 V   U R                  U5      nU(       d  [        S5      e[        U R                  5      nUR	                  US   5        UR                  [        [        5      nUR                  [        5      nUR                  [        5      n/ n/ nSn	Sn
U GH.  nU(       a4  UR                  [        UR                  [        UR                  05      U-  O"UR                  [        UR                  5      U-  nUS:  a_  U	(       dD  [        X5      nUR                  U5      nUR	                  US   5        UR	                  US   5        UR	                  U5        Sn	OeU	(       aK  U
(       aD  [        X5      nUR                  U5      nUR	                  US   5        UR	                  US   5        UR	                  U5        Sn	Un
GM1     Su  nnU(       a#  [        [        U6 [        5      (       a  [        U6 nU(       a#  [        [        U6 [        5      (       a  [        U6 nUU4$ )a  
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   rY   r6   rC   r8   equationrV   rW   coeffr   r   r   r-   )rM   lineintersection_pointsr  eqrB   rG   upper_verticeslower_verticesprev
prev_pointr   compareedge	new_pointupper_polygonlower_polygons                    rI   r   Polygon.cut_section  s   f #//5"GHHdmm$fQi ]]1a  HHQKHHQK
E >?bggq%''1egg679EGG,Q.  {  2D $ 1 1$ 7I")))A,7")))A,7%%e,J2D $ 1 1$ 7I")))A,7")))A,7%%e,J5 8 (2$}j.)A7KK#^4Mj.)A7KK#^4Mm++rT   c                 z   [        U[        5      (       aM  [        nU R                   H5  nUR	                  U5      nUS:X  a  [
        R                  s  $ XB:  d  M3  UnM7     U$ [        U[        5      (       a;  U R                  5       (       a&  UR                  5       (       a  U R                  U5      $ [        5       e)ag  
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   rq   r   Zeror-   r   _do_poly_distancer   )rM   r  distr  currents        rI   rq   Polygon.distance(  s      aD

--*a<66M^"D # K7##(8(8Q[[]]))!,,!##rT   c                 l   U n UR                   nUR                   n[        R                  n[        R                  nUR                   H"  n[        R
                  " X75      nXX:  d  M   UnM$     UR                   H"  n[        R
                  " XG5      nXh:  d  M   UnM$     [        R
                  " X45      n	XU-   ::  a  [        R                  " SSS9   [	        S[        * 5      n
[	        S[        5      nUR                   HW  nUR                  U
R                  :  d8  UR                  U
R                  :X  d  M9  UR                  U
R                  :  d  MU  Un
MY     UR                   HW  nUR                  UR                  :  d8  UR                  UR                  :X  d  M9  UR                  UR                  :  d  MU  UnMY     [        R
                  " X5      n 0 n0 nUR                   H  nUR                  U;   a(  XR                     R                  UR                  5        OUR                  /XR                  '   UR                  U;   a)  XR                     R                  UR                  5        M  UR                  /XR                  '   M     UR                   H  nUR                  U;   a(  XR                     R                  UR                  5        OUR                  /XR                  '   UR                  U;   a)  XR                     R                  UR                  5        M  UR                  /XR                  '   M     U
nUn[        [	        [        R                  [        R                  5      [	        [        R                   [        R                  5      5      n X   S   nX   S   nUR#                  [        U
U5      5      nUR#                  [        U
U5      5      nUU:  a  UnO>UU:  a  UnO5[        R
                  " U
U5      [        R
                  " U
U5      :  a  UnOUnX   S   nX   S   nUR#                  [        UU5      5      nUR#                  [        UU5      5      nUU:  a  UnO>UU:  a  UnO5[        R
                  " UU5      [        R
                  " UU5      :  a  UnOUn  UR#                  [        UU5      5      n[$        UR#                  [        UU5      5      -
  nUU:  SL aq  [        UU5      n['        UU5      nUR                  U5      nUR)                  5       UR)                  5       :  a  UnUU   S   U:w  a  UnUU   S   nGO;UnUU   S   nGO/UU:  SL ao  [        UU5      n['        UU5      nUR                  U5      nUR)                  5       UR)                  5       :  a  UnUU   S   U:w  a  UnUU   S   nOUnUU   S   nO[        UU5      n['        UU5      n['        UU5      nUR                  U5      nUR                  U5      n[+        UU5      nUR)                  5       UR)                  5       :  a  UnUU   S   U:w  a  UnUU   S   nO
UnUU   S   nUU   S   U:w  a  UnUU   S   nO
UnUU   S   nUU
:X  a	  UU:X  a   U$ GM  )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 outputr(   )
stacklevelr   r   T)r}   r   r  rC   r   rq   warningswarnr   rW   rV   r   r   r8   r   r   Onera   r   r   evalfr   ) rM   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min2s                                    rI   r  Polygon._do_poly_distanceE  s   J ZKK	KK	kkFy1A  ! " kkFy1A  ! " nnY:-77MMM%&(	 B3-2,kkFxx'))#GII(=&((WYYBV  " kkFxx'))#GII(=&((WYYBV  " >>'3	 HHDww.(ww'..tww7+/77)ww'ww.(ww'..tww7+/77)ww'  HHDww.(ww'..tww7+/77)ww'ww.(ww'..tww7+/77)ww'  

E!&&!&&153GH	
  (+(+++D&,AB++D&,ABF?Gf_G^^GV,u~~gv/NNGG(+(+++D&,AB++D&,ABF?Gf_G^^GV,u~~gv/NNGG	 #11$z72KLHL66tG8% & &H 8#,#J8$Z9
#-#6#6z#B #))+hnn.>>/H!'*1-;!(J,W5a8G!(J,W5a8GX%$.#GZ8$Z9
#-#6#6z#B #))+hnn.>>/H!'*1-;!(J,W5a8G!(J,W5a8G#J8$Z9
$Z9
!**73!**73#&tT? #))+hnn.>>/H!'*1-;!(J,W5a8G!(J,W5a8G!'*1-;!(J,W5a8G!(J,W5a8GW$w)>w rT   c                 $   [        [        U R                  5      nU Vs/ s H)  nSR                  UR                  UR
                  5      PM+     nnSR                  US   SR                  USS 5      5      nSR                  SU-  Xb5      $ s  snf )	zReturns 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".
z{},{}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   rC   formatrV   rW   join)rM   scale_factor
fill_colorr   rE   coordspaths          rI   _svgPolygon._svg  s     At}}%49:Eq'..acc*E:##F1Iuzz&*/EF:fR,&9	: ;s   0Bc                 2  ^	 0 m	U	4S jnU" U R                   5      n[        U[        U5      5      nU" [        [	        U R                   5      5      5      n[        U[        U5      5      nX5:  a  UnOUnU Vs/ s H  nT	U   PM
     nn[        U5      $ s  snf )Nc                    > 0 n[        [        [        U 5      5      5       H  u  p#X!U'   UTU'   M     U  Vs/ s H  o1U   PM	     sn$ s  snf r   )r   r
   set)
point_listkeerF   rE   Ds       rI   ref_list+Polygon._hashable_content.<locals>.ref_list#  sN    C!'#j/":;A! < %//JqFJ///s   A)r@   r#   r$   r6   reversedtuple)
rM   rW  S1r_norS2r_revr/  ordercanonical_argsrV  s
            @rI   _hashable_contentPolygon._hashable_content   s    	0 dii Br 23d8DII./0Br 23=AA1241U84^$$ 5s   8Bc                 $  ^ [        T[        5      (       a  U T:H  $ [        T[        5      (       a  [        U4S jU R                   5       5      $ [        T[
        5      (       a,  TU R                  ;   a  gU R                   H  nTU;   d  M    g   g)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   .   >#    U  H
  nTU;   v   M     g 7fr   r/   )r   r   r  s     rI   r   'Polygon.__contains__.<locals>.<genexpr>_  s     2z!qAvzr   TF)r   r-   r   r   r   r   rC   )rM   r  r  s    ` rI   __contains__Polygon.__contains__5  sx    N a!!197##2tzz2225!!DMM!

9 # rT   c           	         0 n[        U R                  5      nUR                  US   5        [        R                  " USS 6 nU(       a  [        [        U5      5      nU R                  R                  5        H  u  pVUR                  U5      n[        R                  " X7   X7S-      5      u  p[        X5      R                  US-  U5      n
U
R                  n[        U
R                  U
R                  XR                  S5      -  -   5      n
Ub/  [        U
R                  U
R                   R#                  U5      5      n
XU'   M     U$ )a1  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   Nr(   r   r2   rx   )r6   r@   r8   r-   r^   rY  rj   itemsindexr   _normalize_dimensionr   rotate	directionr   rq   r   r0   )rE   precrG   r   r   r|   rB   rF   r   r   raydirs               rI   	bisectorsPolygon.bisectorsi  s   " 166l

3q6""CG,x}%CHHNN$DA		!A//E
CFBb+$$QqS!,C--Ccffcffs<<+?'??@C#&&#&&((4.1aD % rT   r   )r   )g      ?z#66cc99)$__name__
__module____qualname____firstlineno____doc__	__slots__r=   propertyrN   staticmethodr^   rj   rm   rr   rC   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   rq   r  rO  ra  rf  rq  __static_attributes__r/   rT   rI   r-   r-      s6   Yv I ! ).V ." ."`  * 1 1f 2 2  8 ! !F  5  5F< ~BJ3>9x  @ 	4 	4,\Un9!vG*666rg,T$:FP:&%*2h rT   r-   c                     ^  \ rS rSrSrSrS S jrS!S jr\S 5       r	S r
S r\S	 5       r\S
 5       r\S 5       r\r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS rS"S jrS#S jrS r\S 5       r S r!U 4S jr"Sr#U =r$$ )$r:   i  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_rotc                    [        [        X#U45      u  p#n[        U4SS0UD6n[        U[        5      (       d  [        SU-  5      eUR                  (       a  [        U5        US:  a  [        SU-  5      e[        R                  " XX#40 UD6nX6l
        Xl        X&l        UR                  (       a   US[        R                  -  U-  -  Ul        U$ UUl        U$ )Nr3   r2   z r must be an Expr object, not %sr(   zn must be a >= 3, not %s)rH  r   r   r   r   r   	is_Numberr%   r   r=   r}  r~  r  	is_numberr   rb   r  )rM   rH   r/  r0   rotrA   objs          rI   r=   RegularPolygon.__new__  s    !-	c!%%f%!T"" BQ FGG;;1I1u#$>$BCC$$Ta=f='*}}3!ADD&(#
 ;>
rT   c                     U R                   u  p4pV[        U5      nX4U4 Vs/ s H  oR                  " SSU0UD6PM     snu  p4nU R                  X4XV5      $ s  snf )Nr0   r/   )r@   r'   r'  func)	rM   rn  optionsrH   r/  r0   rB   dpsrF   s	            rI   _eval_evalfRegularPolygon._eval_evalf  s[    YY
a$78Qi@i77,S,G,i@ayyq$$ As   Ac                 ^    U R                   U R                  U R                  U R                  4$ )z
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)
)r~  r  r}  r  rn   s    rI   r@   RegularPolygon.args  s#     ||T\\477DII==rT   c                 2    S[        U R                  5      -  $ NzRegularPolygon(%s, %s, %s, %s)rZ  r@   rn   s    rI   __str__RegularPolygon.__str__      /%		2BBBrT   c                 2    S[        U R                  5      -  $ r  r  rn   s    rI   __repr__RegularPolygon.__repr__  r  rT   c                     U R                   u  pp4[        U5      U-  U R                  S-  -  S[        [        U-  5      -  -  $ )zReturns the area.

Examples
========

>>> from sympy import RegularPolygon
>>> square = RegularPolygon((0, 0), 1, 4)
>>> square.area
2
>>> _ == square.length**2
True
r2      )r@   r   r   r   r   )rM   rH   r/  r0   r  s        rI   rN   RegularPolygon.area  s=     yyaAwqya'3r!t955rT   c                 Z    U R                   S-  [        [        U R                  -  5      -  $ )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

r2   )radiusr   r   r}  rn   s    rI   r   RegularPolygon.length
  s#    ( {{1}SDGG_,,rT   c                     U R                   $ )aV  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)
)r~  rn   s    rI   centerRegularPolygon.center   s    0 ||rT   c                     U R                   $ )z
Alias for center.

Examples
========

>>> from sympy import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.circumcenter
Point2D(0, 0)
)r  rn   s    rI   circumcenterRegularPolygon.circumcenter<  s     {{rT   c                     U R                   $ )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

)r  rn   s    rI   r  RegularPolygon.radiusK  s    6 ||rT   c                     U R                   $ )z
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
)r  rn   s    rI   circumradiusRegularPolygon.circumradiush  s     {{rT   c                     U R                   $ )a  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

r  rn   s    rI   rotationRegularPolygon.rotationy  s    4 yyrT   c                 h    U R                   [        [        R                  U R                  -  5      -  $ )a  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

)r  r   r   rb   r}  rn   s    rI   apothemRegularPolygon.apothem  s$    6 {{Sdgg...rT   c                     U R                   $ )z
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
)r  rn   s    rI   inradiusRegularPolygon.inradius  s     ||rT   c                 \    U R                   S-
  [        R                  -  U R                   -  $ )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

r2   )r}  r   rb   rn   s    rI   interior_angleRegularPolygon.interior_angle  s$    . !QTT!$''))rT   c                 B    S[         R                  -  U R                  -  $ )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

r2   )r   rb   r}  rn   s    rI   exterior_angleRegularPolygon.exterior_angle  s    . vdgg~rT   c                 B    [        U R                  U R                  5      $ )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   r  r  rn   s    rI   circumcircleRegularPolygon.circumcircle  s    . dkk4;;//rT   c                 B    [        U R                  U R                  5      $ )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   r  r  rn   s    rI   incircleRegularPolygon.incircle  s    . dkk4<<00rT   c                 P    0 nU R                   nU R                   H  nX!U'   M	     U$ )aA  
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}
)r  rC   )rM   rf   angr|   s       rI   rj   RegularPolygon.angles'  s.      !!AF 
rT   c                     U R                   n[        X!5      R                  nX0R                  :  a  gX0R                  :  a  g[
        R                  X5      $ )aF  
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)r  r   r   r  r  r-   r   )rM   rE   rH   ds       rI   r   RegularPolygon.encloses_point=  sJ    ` KKAM   ))$22rT   c                 .    U =R                   U-  sl         g)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

Nr  )rM   angles     rI   spinRegularPolygon.spinw  s    ( 			U	rT   c                     [        U 5      " U R                  6 nU=R                  U-  sl        [        R                  " X1U5      $ )am  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

)typer@   r  r   rl  )rM   r  r   r/  s       rI   rl  RegularPolygon.rotate  s6    & J		"	%$$Qr22rT   c                 :   U(       aJ  [        USS9nU R                  " U* R                  6 R                  X5      R                  " UR                  6 $ X:w  a!  [	        U R
                  6 R                  X5      $ U R                  u  pEpgXQ-  nU R                  XEXg5      $ )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))

r2   r   )r   	translater@   scaler-   rC   r  )rM   rV   rW   r   rH   r/  r0   r  s           rI   r  RegularPolygon.scale  s    " rq!B>>RC::.44Q:DDbggNN6DMM*0066yya	yyq&&rT   c                    U R                   u  p#pEU R                  S   nXb-
  nUR                  U5      nUR                  U5      n	X-
  n
[        SU
5      n[        SU5      nUR	                  U5      nX]-  nU R                  X* XE5      $ )zOverride 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   rx   )r@   rC   reflectr   closing_angler  )rM   r  rH   r/  r0   r  r|   r  ccvvddl1l2r  s                 rI   r  RegularPolygon.reflect  s     yyaMM!EYYt_YYt_W _^r"
yyR((rT   c                 ~   U R                   n[        U R                  5      nU R                  nS[        R
                  -  U R                  -  n[        U R                  5       Vs/ s HK  n[        UR                  U[        XT-  U-   5      -  -   UR                  U[        XT-  U-   5      -  -   5      PMM     sn$ s  snf )aL  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)]

r2   )r~  absr  r  r   rb   r}  rL   r   rV   r   rW   r   )rM   rH   r/  r  r|   r  s         rI   rC   RegularPolygon.vertices  s    0 LLiiaddF477N tww)'A accAc!#)n,,accAc!#)n4D.DE') 	) )s   %AB:c                     [        U[        5      (       d  g[        U[        5      (       d  [        R                  X5      $ U R                  UR                  :H  $ )NF)r   r-   r:   __eq__r@   )rM   r  s     rI   r  RegularPolygon.__eq__  sA    !W%%A~..>>!**yyAFF""rT   c                     > [         TU ]  5       $ r   )super__hash__)rM   	__class__s    rI   r  RegularPolygon.__hash__  s    w!!rT   r/   )r   )   r   )r   r   N)%rs  rt  ru  rv  rw  rx  r=   r  ry  r@   r  r  rN   r   r  r}   r  r  r  r  r  r  r  r  r  r  rj   r   r  rl  r  r  rC   r  r  r{  __classcell__)r  s   @rI   r:   r:     s   ;z 5I"% > >CC 6 6  - -*  2 H   8     6 / /8    * *0  0 0 00 1 10  *83t,3.'4)8 ) )>#" "rT   r:   c                   2   \ rS rSrSrS r\S 5       rS rS r	S r
S rS	 r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)r>   i  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                 d   [        U5      S:w  a  SU;   a%  [        US    Vs/ s H  n[        U5      PM     sn6 $ SU;   a%  [        US    Vs/ s H  n[        U5      PM     sn6 $ SU;   a%  [	        US    Vs/ s H  n[        U5      PM     sn6 $ Sn[        U5      eU Vs/ s H  n[        U4SS0UD6PM     nn/ nU H%  nU(       a
  XvS   :X  a  M  UR                  U5        M'     [        U5      S	:  a  US   US
   :X  a  UR                  5         SnU[        U5      S-
  :  a  [        U5      S:  a  [        Xh   XhS	-      XhS-      /[        S9u  p9n
[        R                  " X9U
5      (       a  X6U'   S XhS	-   '   UR                  US	-   5        US	-  nU[        U5      S-
  :  a  [        U5      S:  a  M  [        [        S U5      5      n[        U5      S:X  a  [        R                  " U /UQ70 UD6$ [        U5      S:X  a  [!        U0 UD6$ [        U0 UD6$ s  snf s  snf s  snf s  snf )Nr(   sssasasasz;Triangle instantiates with three points or a valid keyword.r3   r2   r4   r   r   r5   )keyc                 
    U S L$ r   r/   )rV   s    rI   <lambda>"Triangle.__new__.<locals>.<lambda>`  s    $rT   )r7   _sssr   _asa_sasr   r   r8   r;   sortedr	   r<   r6   filterr   r=   r   )r?   r@   rA   rB   msgrC   rD   rE   rF   rG   rH   s              rI   r=   Triangle.__new__?  s(   t9>6%=A=ahqk=ABB6%=A=ahqk=ABB6%=A=ahqk=ABBOC$$7;<t!E!--f-t< ABiLLO  u:>eBi583IIK #e*q. SZ!^5Q<1u6<LNGA!!!!**a#!e		!a% FA #e*q. SZ!^ 6>?x=A!))#CCFCC]aH///(-f--K BAA =s   HH#8H("H-c                     U R                   $ )aC  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))

)r@   rn   s    rI   rC   Triangle.verticesi  s    0 yyrT   c                    [        U[        5      (       d  gU R                   Vs/ s H  o"R                  PM     snu  p4nUR                   Vs/ s H  o"R                  PM     nnS nU" X4U/UQ76 =(       dN    U" X5U/UQ76 =(       d=    U" XCU/UQ76 =(       d,    U" XEU/UQ76 =(       d    U" XSU/UQ76 =(       d
    U" XTU/UQ76 $ s  snf s  snf )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                     [        X-  5      n[        X-  5      n[        X%-  5      n[        Xg:H  5      =(       a    [        Xx:H  5      $ r   )r   bool)	u1u2u3v1v2v3r)  r(  e3s	            rI   _are_similar)Triangle.is_similar.<locals>._are_similar  s:    "%B"%B"%B>4d28n4rT   )r   r-   r   r   )t1t2r  s1_1s1_2s1_3s2r  s           rI   
is_similarTriangle.is_similar  s    D "g&&46HH=HDKKH=D&(hh/hdkkh/	5 D2r2 0T/B/0T/B/0 T/B/0 T/B/	0
 T/B/	0 >/s   CCc                 D    [        S U R                   5       5      (       + $ )a  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              3   8   #    U  H  oR                   v   M     g 7fr   r   r   r   s     rI   r   *Triangle.is_equilateral.<locals>.<genexpr>  s     <Axxr   )r!   r   rn   s    rI   is_equilateralTriangle.is_equilateral  s    8 <<<<<rT   c                 :    [        S U R                   5       5      $ )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              3   8   #    U  H  oR                   v   M     g 7fr   r  r  s     rI   r   (Triangle.is_isosceles.<locals>.<genexpr>  s     5*Q*r   r    r   rn   s    rI   is_isoscelesTriangle.is_isosceles  s    , 5$**555rT   c                 D    [        S U R                   5       5      (       + $ )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              3   8   #    U  H  oR                   v   M     g 7fr   r  r  s     rI   r   &Triangle.is_scalene.<locals>.<genexpr>	  s     9jHHjr   r  rn   s    rI   
is_scaleneTriangle.is_scalene  s    , 9djj9999rT   c                     U R                   n[        R                  " US   US   5      =(       dA    [        R                  " US   US   5      =(       d    [        R                  " US   US   5      $ )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   r2   )r   r   is_perpendicularrM   r   s     rI   is_rightTriangle.is_right	  sd    . JJ''!ad3 1$$QqT1Q401$$QqT1Q40	1rT   c           	          U R                   nU R                  nUS   US   R                  US   5      US   US   R                  US   5      US   US   R                  US   5      0$ )as  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   r2   )r   rC   perpendicular_segmentrM   r   r|   s      rI   	altitudesTriangle.altitudes#	  st    < JJMM!ad0016!ad0016!ad00168 	8rT   c                     U R                   nU R                  n[        XS      5      R                  [        XS      5      5      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&  rC   r   r   )rM   rB   r|   s      rI   orthocenterTriangle.orthocenterG	  s@    6 NNMMAdG}))$q1w-8;;rT   c                     U R                    Vs/ s H  oR                  5       PM     snu  p#nUR                  U5      S   $ s  snf )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)
r   )r   perpendicular_bisectorr   )rM   rV   rB   rG   rH   s        rI   r  Triangle.circumcenterf	  sA    2 8<zzBz!++-zBa~~a ## Cs   Ac                 ^    [         R                  " U R                  U R                  S   5      $ )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   rq   r  rC   rn   s    rI   r  Triangle.circumradius	  s$    2 ~~d//q1ABBrT   c                 B    [        U R                  U R                  5      $ )ae  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   r  r  rn   s    rI   r  Triangle.circumcircle	  s    0 d''):):;;rT   c                    U R                    Vs/ s H  n[        U5      PM     nnU R                  nU R                  n[	        US   [        US   U5      R                  US   5      S   5      n[	        US   [        US   U5      R                  US   5      S   5      n[	        US   [        US   U5      R                  US   5      S   5      nUS   XSS   XcS   U0$ s  snf )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

r   r   r2   )r   r   rC   incenterr   r   )rM   lr   r|   rH   r  r  l3s           rI   rq  Triangle.bisectors	  s    @ #jj)jT!Wj)MMMMQqT4!a=55ad;A>?QqT4!a=55ad;A>?QqT4!a=55ad;A>?!bA$aD"-- *s   C c           
         U R                   n[        S Vs/ s H  o!U   R                  PM     sn5      n[        U5      nU R                  n[        UR                  [        U Vs/ s H  ofR                  PM     sn5      5      U-  5      n[        UR                  [        U Vs/ s H  ofR                  PM     sn5      5      U-  5      n[        Xx5      $ s  snf s  snf s  snf )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)

)r   r2   r   )
r   r   r   rc   rC   r   dotrV   rW   r   )	rM   r   rF   r4  rE   r|   virV   rW   s	            rI   r3  Triangle.incenter	  s    6 JJ3AaDKK34FMMQUU6!"4!B44!"456q89QUU6!"4!B44!"456q89Q{ 4 #5"4s   C%C%C!c                 L    [        SU R                  -  U R                  -  5      $ )a5  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

r2   )r   rN   rr   rn   s    rI   r  Triangle.inradius
  s     0 DII677rT   c                 B    [        U R                  U R                  5      $ )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   r3  r  rn   s    rI   r  Triangle.incircle
  s    6 dmmT]]33rT   c           
      V   U R                   nUS   R                  nUS   R                  nUS   R                  nX#-   U-   S-  nU R                  nU R                   S   [        XeU-
  -  5      U R                   S   [        XeU-
  -  5      U R                   S   [        XeU-
  -  5      0nU$ )a  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   r2   )r   r   rN   r   )rM   r  rB   rG   rH   r   rN   exradiis           rI   r@  Triangle.exradii9
  s    L zzGNNGNNGNNSUAIyy::a=(41:"6::a=(41:"6::a=(41:"68 rT   c                    U R                   nU R                  nUS   R                  nUS   R                  nUS   R                  nUS   R                  US   R                  US   R                  /nUS   R                  US   R                  US   R                  /n[        U* US   -  XFS   -  -   XVS   -  U* U-   U-   -  -   5      [        X6S   -  XFS   -  -
  XVS   -  X4-
  U-   -  -   5      [        X6S   -  XFS   -  -   XVS   -  X4-   U-
  -  -
  5      [        U* US   -  XGS   -  -   XWS   -  U* U-   U-   -  -   5      [        X7S   -  XGS   -  -
  XWS   -  X4-
  U-   -  -   5      [        X7S   -  XGS   -  -   XWS   -  X4-   U-
  -  -
  5      S.nUS   [        US   US   5      US   [        US   US   5      US   [        US	   US
   5      0n	U	$ )a  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   r2   )rO   rQ   x3rP   rR   y3rO   rP   rQ   rR   rC  rD  )r   rC   r   rV   rW   r   r   )
rM   r   r|   rB   rG   rH   rV   rW   
exc_coords	excenterss
             rI   rF  Triangle.excentersk
  s   L JJMMaDKKaDKKaDKKqTVVQqTVVQqTVV$qTVVQqTVVQqTVV$ A2ad71qT6>!aD&1"Q$q&/9:1qT6!aD&=Q4Q781qT6!aD&=Q4Q78A2ad71qT6>!aD&1"Q$q&/9:1qT6!aD&=Q4Q781qT6!aD&=Q4Q78

 aD%
4(*T*:;aD%
4(*T*:;aD%
4(*T*:;
	 rT   c           
          U R                   nU R                  nUS   [        US   US   R                  5      US   [        US   US   R                  5      US   [        US   US   R                  5      0$ )aV  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   r2   )r   rC   r   midpointr%  s      rI   mediansTriangle.medians
  st    < JJMM!gadAaDMM2!gadAaDMM2!gadAaDMM24 	4rT   c                     U R                   n[        US   R                  US   R                  US   R                  5      $ )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   r2   )r   r>   rI  r   s     rI   medialTriangle.medial
  s4    4 JJ!qt}}admmDDrT   c                 :    [        U R                  R                  6 $ )ae  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   rM  rC   rn   s    rI   nine_point_circleTriangle.nine_point_circle
  s    < t{{++,,rT   c                     U R                  5       (       a  U R                  $ [        U R                  U R                  5      $ )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   r  rn   s    rI   	eulerlineTriangle.eulerline  s8    ,   ###D$$d&7&788rT   r/   N)rs  rt  ru  rv  rw  r=   ry  rC   r
  r  r  r  r!  r&  r)  r  r  r  rq  r3  r  r  r@  rF  rJ  rM  rP  rS  r{  r/   rT   rI   r>   r>     sc   7r(.T  240l=<60:018 !8 !8F < << $ $6 C C4 < <2&.P    D 8 82 4 48 / /b < <| !4 !4F E E8 - -> 9 9rT   r>   c                     U [         -  S-  $ )zAReturn the radian value for the given degrees (pi = 180 degrees).   r   )r  s    rI   radrX  %      R48OrT   c                     U [         -  S-  $ )zAReturn the degree value for the given radians (pi = 180 degrees).rV  rW  )r/  s    rI   degr[  *  rY  rT   c                 .    [        [        U 5      5      nU$ r   )r   rX  )r  rvs     rI   _sloper^  /  s    	SVBIrT   c           	          [        S[        U 5      S9R                  [        US4[        SU-
  5      S95      S   n[        SUS4U5      $ )z8Return triangle having side with length l on the x-axis.rx   r   r   rV  )r   r^  r   r>   )d1r4  d2xys       rI   r  r  4  sO    	fF2J	'	4	4aV6#(+,
../
1BFQFB''rT   c                     [        SU5      n[        U S4U5      nUR                  U5       Vs/ s H!  oUR                  R                  (       d  M  UPM#     nnU(       d  gUS   n[	        SU S4U5      $ s  snf )z7Return triangle having side of length l1 on the x-axis.rx   r   N)r   r   rW   is_nonnegativer>   )r  r  r5  c1c2rB   interr   s           rI   r  r  ;  so    		B	Q	B+B+1ss/A/AQ+EB	qBFRGR((	 Cs   A4A4c                     [        SS5      n[        US5      n[        [        [        U5      5      U -  [        [        U5      5      U -  5      n[	        X4U5      $ )z9Return triangle having side with length l2 on the x-axis.r   )r   r   rX  r   r>   )r  r  r  r   r   p3s         rI   r  r  F  sI    	q!B	r1B	s3q6{2~s3q6{2~	.BBBrT   )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   r   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$  rL   rV   rW   r   r-   r:   r>   rX  r[  r^  r  r  r  )rF   s   0rI   <module>rz     s    / /  8 4 4 5 : B B  / % $ $   ! , ' ^ ^ 2 +  7<Ah
?h5t,h
?1amk m`+v	"W v	"r^9w ^9@


() [Y @s   #C/