� ��gk@����ddlmZmZmZmZmZddlmZddlm Z m Z ddl m Z m Z mZddlmZddlmZddlmZmZmZdd lmZdd lmZmZdd lmZdd lmZm Z m!Z!dd l"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7Z7d�e8d��D��\Z9Z:Z;Gd�de��Z<Gd�de<��Z=Gd�de<��Z>d�Z?d�Z@d �ZAd!�ZBd"�ZCd#�ZDdS)$�)�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�0�g|]}tdd�����S)� polygon_dummyT��real)r )�.0�is �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/geometry/polygon.py� <listcomp>r1s%�� ?� ?� ?��5��t� ,� ,� ,� ?� ?� ?��c�\�eZdZdZdZdd�d�Zed���Zed���Z ed���Z ed ���Z ed ���Z ed ���Z ed ���Zd$d�Zd$d�Zd�Zd$d�Zed���Zed���Zd�Zd�Zd%d�Zd�Zd%d�Zd�Zd�Zd�Zd�Zd&d �Zd!�Zd"�Z d$d#�Z!d S)'�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)�nc�J��|rmt|��}t|��dkr|�|��n)t|��dkr|�d|��t |i���S�fd�|D��}g}|D]&}|r ||dkr�|�|���'t|��dkr&|d|dkr|���d}|t|��dz kr�t|��dkr�||||dz||dz} } }t j|| | ��r4|�|dz��|| kr|�|��n|dz }|t|��dz krt|��dk��t|��}t|��dkrtj |g|�Ri���St|��dkr t|i���St|��dkr t|i���St |i���S)N�r3c�.��g|]}t|fddi�����S��dimr9r�r.�a�kwargss �r0r1z#Polygon.__new__.<locals>.<listcomp>��.���<�<�<�!�E�!�-�-��-�f�-�-�<�<�<r2�����rr�����) �list�len�append�insert�RegularPolygon�popr� is_collinearr�__new__�Triangler) �clsr7�argsr?�vertices�nodup�pr/r>�b�cs ` r0rJzPolygon.__new__zsJ��� � 3���:�:�D��4�y�y�A�~�~�� � �A������T���a���� � �A�q�!�!�!�!�4�2�6�2�2� 2�<�<�<�<�t�<�<�<����� � �A�� ��e�B�i���� �L�L��O�O�O�O� �u�:�:��>�>�e�B�i�5��8�3�3� �I�I�K�K�K� ���#�e�*�*�q�.� � �S��Z�Z�!�^�^��A�h��a�!�e� �e�A��E�l�!�q�A��!�!�Q��*�*� �� � �!�a�%� � � ���6�6��I�I�a�L�L�L���Q����#�e�*�*�q�.� � �S��Z�Z�!�^�^���;�;�� �x�=�=�1� � �!�)�#�C��C�C�C�F�C�C� C� ��]�]�a� � ��X�0��0�0� 0� ��]�]�a� � ��H�/��/�/� /��(�-�f�-�-� -r2c���d}|j}tt|����D]3}||dz j\}}||j\}}|||z||zz z }�4t|��dz 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 rrr9)rM�rangerDr )�self�arearMr/�x1�y1�x2�y2s r0rVz Polygon.area�sz��R���y���s�4�y�y�!�!� "� "�A��!�a�%�[�%�F�B���!�W�\�F�B�� �B�r�E�B�r�E�M� !�D�D���~�~��!�!r2c��||z }||z }t|j|jz|j|jzz ��}|j}|�t d���|S)a7Return 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 NzCan't determine orientation)r �x�y�is_nonpositive� ValueError)r>rQrR�ba�ca�t_area�ress r0� _is_clockwisezPolygon._is_clockwise�sY����U�� ��U���"�$�r�t�)�b�d�2�4�i�/�0�0���#�� �;��:�;�;� ;�� r2c�F�|j}t|��}i}t|��D]�}||dz ||dz ||}}}t||���t||����}|�|||��rdt jz|z ||<�~|||<��t|� ����t jz dz |dz z dz j } | r#dt jz} |D]}| ||z ||<�n| �td���|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) r9rNz(could not determine Polygon orientation.) rNrDrTr� angle_betweenrdr�Pi�sum�values� is_positiver_) rUrMr7�retr/r>rQrR� reflex_ang�wrong�two_pis r0�angleszPolygon.angles�s7��<�}�� ��I�I�����q��� $� $�A��1�q�5�k�4��A��;��Q��!�q�A��Q����0�0��Q����;�;�J��!�!�!�Q��*�*� $��1�4��*�,��A���#��A����c�j�j�l�l�#�#�A�D�(��*�Q��U�3�a�7�D�� � I��q�t�V�F�� )� )���#�a�&���A��� )� �]��G�H�H� H�� r2c�&�|jdjS)Nr)rN�ambient_dimension�rUs r0rqzPolygon.ambient_dimension s���}�Q��1�1r2c��d}|j}tt|����D])}|||dz �||��z }�*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 rr)rNrTrD�distancer )rUrPrMr/s r0� perimeterzPolygon.perimeter$s_��. ���}���s�4�y�y�!�!� /� /�A� ��a�!�e��%�%�d�1�g�.�.� .�A�A���{�{�r2c�*�t|j��S)aQThe 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) )rCrMrrs r0rNzPolygon.verticesAs��D�D�I���r2c�Z�dd|jzz }d\}}|j}tt|����D]F}||dz j\}}||j\}} || z||zz } || ||zzz }|| || zzz }�Gt t ||z��t ||z����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��rr)rVrMrTrDrr ) rU�A�cx�cyrMr/rWrXrYrZ�vs r0�centroidzPolygon.centroides���0 �q���{�O�����B��y���s�4�y�y�!�!� � �A��!�a�%�[�%�F�B���!�W�\�F�B���2���2�� �A� �!�R�"�W�+� �B� �!�R�"�W�+� �B�B��X�a��d�^�^�X�a��d�^�^�4�4�4r2Nc��d\}}}|j}tt|����D]�}||dz j\}}||j\} } || z| |zz } ||dz|| zz| dzz| zz }||dz|| zz| dzz| zz }||| zd|z|zzd| z| zz| |zz| zz }��|j} |jd} |jd}|dz | |dzzz }|dz | | dzzz }|dz | | |zzz }|�|||fS|| |d|z dzzz}|| |d| z dzzz}|| |d| z |d|z zzz}|||fS)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 )rrrrr9r� �)rNrTrDrMrVr~)rU�point�I_xx�I_yy�I_xyrMr/rWrXrYrZr}rz�c_x�c_y�I_xx_c�I_yy_c�I_xy_cs r0�second_moment_of_areazPolygon.second_moment_of_area�s���J#���d�D��}���s�4�y�y�!�!� :� :�A��!�A�#�Y�^�F�B���!�W�\�F�B���2���2�� �A� �R��U�R��U�]�R��U�*�A�-� -�D� �R��U�R��U�]�R��U�*�A�-� -�D� �R��U�Q�r�T�"�W�_�q��t�B�w�.��B��6��9� 9�D�D� �I���m�A����m�A����r�'�a��a��j�)���r�'�a��a��j�)���r�'�a��S��k�*�� �=��6�6�)� )���U�1�X�c�\�A�-�.�.����U�1�X�c�\�A�-�.�.����U�1�X�c�\�E�!�H�S�L�9�:�:���T�4��r2c���|r |j\}}n |j}|\}}t|d���}t|tj���}|�|��}|�|��}|dj|djkr|dn|d}|dj|djkr|dn|d} |jj|z |jz} | jj|z | jz} | | fS)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)r~rr�Infinity� cut_sectionrVr]r\) rUr��xc�yc�h_line�v_line�h_poly�v_poly�poly_1�poly_2�Q_x�Q_ys r0�first_moment_of_areazPolygon.first_moment_of_area�s���` � ��]�F�B����M�E��F�B���e�1�%�%�%���e�1�:�.�.�.���!�!�&�)�)���!�!�&�)�)��$�Q�i�n��q� ��>�>�����F�1�I��$�Q�i�n��q� ��>�>�����F�1�I���� �2�%�v�{�2���� �2�%�v�{�2���C�x�r2c�L�|���}|d|dzS)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 rr)r�)rU� second_moments r0�polar_second_moment_of_areaz#Polygon.polar_second_moment_of_area s*��6�2�2�4�4� ��Q��-��"2�2�2r2c��|j\}}|�9|j\}}}}t||z ||z ��}t||z ||z ��} n|j|z }|j|z } |���} | d|z } | d| z } | | fS)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 Nrr)r~�bounds�maxr]r\r�) rUr��x_c�y_c�x_min�y_min�x_max�y_maxr]r\r��S_x�S_ys r0�section_moduluszPolygon.section_modulus,s���T�=���S� �=�)-�� &�E�5�%���C�%�K����-�-�A��C�%�K����-�-�A�A���#� �A���#� �A��1�1�3�3� ��A��q� ���A��q� ���C�x�r2c ��g}|j}tt|�� d��D]4}|�t ||||dz�����5|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))] rr)rNrTrDrEr)rUrcrMr/s r0�sidesz Polygon.sideshsa��6���}����D� � �z�1�%�%� 6� 6�A� �J�J�w�t�A�w��Q��U� �4�4� 5� 5� 5� 5�� r2c��|j}d�|D��}d�|D��}t|��t|��t|��t|��fS)zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure. c��g|] }|j�� Sr6�r\�r.rPs r0r1z"Polygon.bounds.<locals>.<listcomp>���� !� !� !�a�a�c� !� !� !r2c��g|] }|j�� Sr6�r]r�s r0r1z"Polygon.bounds.<locals>.<listcomp>�r�r2)rN�minr�)rU�verts�xs�yss r0r�zPolygon.bounds�sX��� �� !� !�5� !� !� !�� !� !�5� !� !� !���B����R���#�b�'�'�3�r�7�7�3�3r2c��|j}|�|d|d|d��}tdt|����D]7}||�||dz ||dz ||��z rdS�8|j}t |��D]o\}}|j}t|t|��dz krdnd|dz ��D]7}||}|j|vr$|j|vr|� |��} | rdS�8�pdS)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 �����rArrr9FT) rNrdrTrDr�� enumeraterM�p1�p2� intersection) rUrM�cwr/r��si�pts�j�sj�hits r0� is_convexzPolygon.is_convex�s=��8�}�� � � ��R��$�r�(�D��G� <� <���q�#�d�)�)�$�$� � �A��D�&�&�t�A��E�{�D��Q��K��a��I�I�I� ��u�u� �� ���u�%�%� %� %�E�A�r��'�C���S��Z�Z�!�^� 3� 3�1�1��A��E�B�B� %� %���1�X���5��#�#���S�(8�(8��/�/�"�-�-�C��%�$�u�u�u��  %� �tr2c�n��t�d�����|jvs t�fd�|jD����rdSg}|jD]*}|�|�z ��|djrdS�+t |�}|j}ttt|�� d����}|� ��r^d}|D]W}||} ||dz} | j | j | j z z| j | j | j z zz j} |�| }�P| |urdS�XdSd} |d j\} }|dd�D]y}||j\}}d t||��krOd t!||��kr;d t!| |��kr'||kr!| || z z||z z | z}| |ksd |kr| } ||}} �z| 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 r9�r<c3� �K�|]}�|vV�� dS�Nr6)r.�srPs �r0� <genexpr>z)Polygon.encloses_point.<locals>.<genexpr>�s'�����$@�$@��Q�!�V�$@�$@�$@�$@�$@�$@r2FrANrTr)rrN�anyr�rE� free_symbolsr5rMrCrTrDr�r]r\� is_negativer�r�)rUrP�litr}�polyrM�indices� orientationr/r>rQ�test�hit_odd�p1x�p1y�p2x�p2y�xinterss ` r0�encloses_pointzPolygon.encloses_point�s���T �!��O�O�O�� �� � � ��$@�$@�$@�$@�T�Z�$@�$@�$@�!@�!@� ��5����� � �A� �J�J�q�1�u� � � ��2�w�#� ��t�t� ���}�� �y���u�c�$�i�i�Z��+�+�,�,�� �>�>� � � ��K�� !� !����G����Q��K���#����a�c� �*�q�s�d�Q�S�1�3�Y�-?�?�L���&�"&�K�K���,�,� �5�5�-��4�����7�<���S������ � �A��A�w�|�H�C���3�s�C�=�=� � ���C�� � �%�%��C��S�M�M�)�)��#�:�:�(+�t�c�C�i�&8�#��)�&D�s�&J�G�"�c�z�z�Q�'�\�\�.5�+���C��C�C��r2�tc ��t|d���}|jd�|jD��vrtd|jz���g}|j}d}|jD]o}|j|z }||z}|�|���|||z |z ��} |� | t||k||k��f��|}�pt|�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,c3�$K�|] }|jV�� dSr�)�name)r.�fs r0r�z*Polygon.arbitrary_point.<locals>.<genexpr>Fs$����8�8��a�f�8�8�8�8�8�8r2zFSymbol %s already appears in object and cannot be used as a parameter.r) r r�r�r_rur��length�arbitrary_point�subsrErr) rU� parameterr�r�ru�perim_fraction_startr��side_perim_fraction�perim_fraction_end�pts r0r�zPolygon.arbitrary_points ��V �I�D� )� )� )�� �6�8�8�d�&7�8�8�8� 8� 8��e�hi�hn�n�o�o� o����N� � ���� 6� 6�A�"#�(�9�"4� �!5�8K�!K� ��"�"�9�-�-�2�2��A�,�,�.A�A�C�C�B� �L�L��c�.�!�3�Q�9K�5K�L�L�N� P� P� P�#5� � ��%� � r2c�f�t|t��st||j���}t|t��st d���|jrt d���d}|�t��}|j D]i\}}t||z td���}|s�"|dt}t|� t|����dkr||icSd}�j|rt dt|��z���t d t|��z���) Nr�zother must be a pointznon-numeric coordinatesFT)�dictrzGiven point may not be on %szGiven point is not on %s)� isinstancerrrqr_r��NotImplementedErrorr��TrMr!r r�r() rU�otherr��unknownrPr��cond�sol�values r0�parameter_valuezPolygon.parameter_valueUs7���%��/�/� =��%�T�%;�<�<�<�E��%��&�&� 6��4�5�5� 5� � � A�%�&?�@�@� @��� � � �� #� #���� � �H�B����U� �A�D�1�1�1�C�� ����F�1�I�E��� � �!�U�+�+�,�,��4�4��5�z�!�!�!��G�G� � O��;�i��o�o�M�N�N� N��3�i��o�o�E�F�F�Fr2c�.�t|d���}|ddgS)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,rr)r )rUr�r�s r0� plot_intervalzPolygon.plot_intervaljs"��0 �9�4� (� (� (���1�a�y�r2c�"� �g}t|t��r|jn|g}|jD]/}|D]*}|�|�|�����+�0t t |����}d�|D��}d�|D��� |re� rct t � fd�|D������}|r|D]}|�|���t t� |z����St 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�<�g|]}t|t���|��Sr6)r�r�r.�entitys r0r1z(Polygon.intersection.<locals>.<listcomp>�s(��X�X�X�V�j��QV�>W�>W�X�&�X�X�Xr2c�<�g|]}t|t���|��Sr6)r�rr�s r0r1z(Polygon.intersection.<locals>.<listcomp>�s(��\�\�\�v� �6�SZ�@[�@[�\�F�\�\�\r2c�&��g|] }�D]}||v�|�� �Sr6r6)r.r��segment�segmentss �r0r1z(Polygon.intersection.<locals>.<listcomp>�s3���+r�+r�+r�e�U]�+r�+r�'�af�jq�aq�aq�E�aq�aq�aq�aqr2) r�r5r��extendr�rCr$�remover ) rU�o�intersection_result�k�side�side1�points�points_in_segmentsr/r�s @r0r�zPolygon.intersection�sP���J!��!�!�W�-�-� 6�A�G�G�A�3���J� E� E�D�� E� E��#�*�*�4�+<�+<�U�+C�+C�D�D�D�D� E�#�4�(;�#<�#<�=�=��X�X�':�X�X�X��\�\�)<�\�\�\�� � 6�h� 6�!%�d�+r�+r�+r�+r�v�+r�+r�+r�&s�&s�!t�!t� �!� %�+�%�%�A��M�M�!�$�$�$�$����6� 1�2�2�3�3� 3��� 3�4�4�5�5� 5r2c��|�|��}|std���t|j��}|�|d��|�t t��}|�t ��}|�t��}g}g}d} d} |D�]K} |r0|� t | jt| ji��|z n"|� t | j��|z } | dkru| s[t| | ��} | �|��}|�|d��|�|d��|�| ��d} nv| r]| r[t| | ��} | �|��}|�|d��|�|d��|�| ��d} | } ��Md\}}|r%tt|�t��r t|�}|r%tt|�t��r t|�}||fS)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 polygonrTNF)NN) r�r_rCrNrE�equationr\r]�coeffr�rr�r5)rU�line�intersection_pointsr�eqr>rQ�upper_vertices�lower_vertices�prev� prev_pointr��compare�edge� new_point� upper_polygon� lower_polygons r0r�zPolygon.cut_section�s^��f#�/�/��5�5��"� I��G�H�H� H��d�m�$�$��� � �f�Q�i� � � � �]�]�1�a� � �� �H�H�Q�K�K�� �H�H�Q�K�K��������� �� � �E�>?�/�b�g�g�q�%�'�1�e�g�6�7�7��9�9�����E�G�,�,�Q�.� ���{�{��8� ��z�2�2�D� $� 1� 1�$� 7� 7�I�"�)�)�)�A�,�7�7�7�"�)�)�)�A�,�7�7�7��%�%�e�,�,�,�����8�J�8���z�2�2�D� $� 1� 1�$� 7� 7�I�"�)�)�)�A�,�7�7�7�"�)�)�)�A�,�7�7�7��%�%�e�,�,�,����J�J�'1�$� �}� � 5�j��.�)A�7�K�K� 5�#�^�4�M� � 5�j��.�)A�7�K�K� 5�#�^�4�M��m�+�+r2c�t�t|t��rDt}|jD]3}|�|��}|dkrt jcS||kr|}�4|St|t��r=|���r)|���r|� |��St���)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�rrr�rtr�Zeror5r��_do_poly_distancer�)rUr��distr�currents r0rtzPolygon.distance(s��� �a�� � � -��D�� � #� #���-�-��*�*���a�<�<��6�M�M�M��t�^�^�"�D���K� ��7� #� #� -����(8�(8� -�Q�[�[�]�]� -��)�)�!�,�,� ,�!�#�#�#r2c�n �|} |j}|j}tj}tj}|jD]}t j||��}||kr|}� |jD]}t j||��}||kr|}� t j||��} | ||zkrt jdd��� t dt ��} t dt��} |jD]4}|j | j ks |j | j kr|j | j kr|} �5|jD]4}|j | j ks |j | j kr|j | j kr|} �5t j| | ��} i} i}|j D]�}|j | vr&| |j � |j��n|jg| |j <|j| vr&| |j� |j ���p|j g| |j<��|j D]�}|j |vr&||j � |j��n|jg||j <|j|vr&||j� |j ���p|j g||j<��| }| }tt tjtj��t tjtj����} | | d}| | d}|�t| |����}|�t| |����}||kr|}n:||kr|}n1t j| |��t j| |��kr|}n|}|| d}|| d}|�t| |����}|�t| |����}||kr|}n:||kr|}n1t j| |��t j| |��kr|}n|} |�t||����}t$|�t||����z }||kdur�t||��}t'||��}|�|��}|���| ���kr|} | |d|kr|}| |d}�n�|}| |d}�n�||kdur�t||��}t'||��}|�|��}|���| ���kr|} ||d|kr|}||d}�n |}||d}n�t||��}t'||��}t'||��}|�|��}|�|��}t+||��}|���| ���kr|} | |d|kr|}| |d}n|}| |d}||d|kr|}||d}n|}||d}|| kr|| krn���| S)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)� stacklevelrrT)r~rrrNrrt�warnings�warnrr]r\r�r�rEr�r�Onerfrr�evalfr�) rU�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 r0rzPolygon._do_poly_distanceEs��J��Z��K� ��K� ��� ��� ��k� "� "�F���y�&�1�1�A��q� � � !� ���k� "� "�F���y�&�1�1�A��q� � � !� ���n�Y� �:�:� � �-�-�7� 7� 7� �M�M�%&� (� (� (� (� ���B�3�-�-����2�,�,���k� !� !�F��x�'�)�#�#���G�I�(=�(=�&�(�W�Y�BV�BV� ����k� !� !�F��x�'�)�#�#���G�I�(=�(=�&�(�W�Y�BV�BV� ����>�'�7�3�3�� ������H� 4� 4�D��w�.�(�(��t�w�'�.�.�t�w�7�7�7�7�+/�7�)��t�w�'��w�.�(�(��t�w�'�.�.�t�w�7�7�7�7�+/�7�)��t�w�'�'��H� 4� 4�D��w�.�(�(��t�w�'�.�.�t�w�7�7�7�7�+/�7�)��t�w�'��w�.�(�(��t�w�'�.�.�t�w�7�7�7�7�+/�7�)��t�w�'�'�� �� ��E�!�&�!�&�1�1�5�����3G�3G�H�H� � �  ��(��+����(��+���+�+�D��&�,A�,A�B�B���+�+�D��&�,A�,A�B�B�� �F�?�?��G�G� �f�_�_��G�G� �^�G�V� ,� ,�u�~�g�v�/N�/N� N� N��G�G��G���(��+����(��+���+�+�D��&�,A�,A�B�B���+�+�D��&�,A�,A�B�B�� �F�?�?��G�G� �f�_�_��G�G� �^�G�V� ,� ,�u�~�g�v�/N�/N� N� N��G�G��G� �: �#�1�1�$�z�7�2K�2K�L�L�H��L�6�6�t��G�8%�8%�&�&�&�H��8�#��,�,�#�J��8�8� �$�Z��9�9� �#-�#6�#6�z�#B�#B� �#�)�)�+�+�h�n�n�.>�.>�>�>�/�H�!�'�*�1�-��;�;�!(�J�,�W�5�a�8�G�G�!(�J�,�W�5�a�8�G�G��X�%�$�.�.�#�G�Z�8�8� �$�Z��9�9� �#-�#6�#6�z�#B�#B� �#�)�)�+�+�h�n�n�.>�.>�>�>�/�H�!�'�*�1�-��;�;�!(�J�,�W�5�a�8�G�G�!(�J�,�W�5�a�8�G�G�#�J��8�8� �$�Z��9�9� �$�Z��9�9� �!�*�*�7�3�3��!�*�*�7�3�3��#&�t�T�?�?� �#�)�)�+�+�h�n�n�.>�.>�>�>�/�H�!�'�*�1�-��;�;�!(�J�,�W�5�a�8�G�G�!(�J�,�W�5�a�8�G�!�'�*�1�-��;�;�!(�J�,�W�5�a�8�G�G�!(�J�,�W�5�a�8�G��W�$�$��w�)>�)>��u: �v�r2��?�#66cc99c���tt|j��}d�|D��}d�|dd�|dd�����}d�d|z||��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�N�g|]"}d�|j|j����#S)z{},{})�formatr\r]r�s r0r1z Polygon._svg.<locals>.<listcomp>s*��:�:�:�q�'�.�.���a�c�*�*�:�:�:r2z M {} L {} zrz L rNza<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="0.6" d="{1}" />g@)�maprrNrA�join)rU� scale_factor� fill_colorr��coords�paths r0�_svgz Polygon._svg su���A�t�}�%�%��:�:�E�:�:�:���#�#�F�1�I�u�z�z�&����*�/E�/E�F�F�� :��f�R�,�&��j�9�9� :r2c�J��i��fd�}||j��}t|t|����}|tt |j������}t|t|����}||kr|}n|}�fd�|D��}t |��S)Nc����i�ttt|������D]\}}|�|<|�|<��fd�|D��S)Nc� ��g|] }�|�� Sr6r6)r.rP�kees �r0r1z?Polygon._hashable_content.<locals>.ref_list.<locals>.<listcomp>(s���/�/�/�q�C��F�/�/�/r2)r�r �set)� point_listr/rPrL�Ds @�r0�ref_listz+Polygon._hashable_content.<locals>.ref_list#s`�����C�!�'�#�j�/�/�":�":�;�;� � ���1���A����!���/�/�/�/�J�/�/�/� /r2c� ��g|] }�|�� Sr6r6)r.�orderrOs �r0r1z-Polygon._hashable_content.<locals>.<listcomp>2s���4�4�4��1�U�8�4�4�4r2)rMr%r&rC�reversed�tuple) rUrP�S1�r_nor�S2�r_revr&�canonical_argsrOs @r0�_hashable_contentzPolygon._hashable_content s���� �� 0� 0� 0� 0� 0��X�d�i� � ���B��r� 2� 2�3�3�� �X�d�8�D�I�.�.�/�/� 0� 0���B��r� 2� 2�3�3�� �5�=�=��A�A��A�4�4�4�4��4�4�4���^�$�$�$r2c� ��t�t��r|�kSt�t��r t�fd�|jD����St�t ��r�|jvrdS|jD] }�|vrdS� dS)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 c3� �K�|]}�|vV�� dSr�r6)r.r�r�s �r0r�z'Polygon.__contains__.<locals>.<genexpr>_s'�����2�2�!�q�A�v�2�2�2�2�2�2r2TF)r�r5rr�r�rrN)rUr�rs ` r0� __contains__zPolygon.__contains__5s����N �a�� !� !� ��1�9� � ��7� #� #� ��2�2�2�2�t�z�2�2�2�2�2� 2� ��5� !� !� ��D�M�!�!��t�� � � ����9�9��4�4���ur2c ��i}t|j��}|�|d��tj|dd��}|rtt |����}|j���D]�\}}|�|��}tj ||||dz��\}} t|| ��� |dz |��} | j } t| j| j| | �d��z z��} |�-t| j| j�|����} | ||<��|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))} rNr3rr9ry)rCrMrEr5rdrSro�items�indexr�_normalize_dimensionr�rotate� directionr�rtr�r7) rP�precrQr�r�r}r>r/r�r��ray�dirs r0� bisectorszPolygon.bisectorsis0��" ���1�6�l�l�� � � �3�q�6���� � "�C����G� ,�� � &��x��}�}�%�%�C��H�N�N�$�$� � �D�A�q�� � �!� � �A��/��A���A��E� �C�C�F�B���b�"�+�+�$�$�Q�q�S�!�,�,�C��-�C��c�f�c�f�s�3�<�<��+?�+?�'?�?�@�@�C����#�&�#�&�(�(�4�.�.�1�1���A�a�D�D��r2r�)r�)r=r>)"�__name__� __module__� __qualname__�__doc__� __slots__rJ�propertyrV� staticmethodrdrorqrurNr~r�r�r�r�r�r�r�r�r�r�r�r�r�rtrrHrZr]rgr6r2r0r5r5sy������Y�Y�v�I� !�).�).�).�).�).�V�."�."��X�."�`����\��*�1�1��X�1�f�2�2��X�2�����X��8�!�!��X�!�F� 5� 5��X� 5�F< �< �< �< �~B�B�B�B�J3�3�3�>9�9�9�9�x����X��@� 4� 4��X� 4�,�,�,�\U�U�U�n9!�9!�9!�9!�vG�G�G�*����666�66�66�rg,�g,�g,�T$�$�$�:F�F�F�P:�:�:�:�&%�%�%�*2�2�2�h � � � � � r2r5c����eZdZdZdZd"d�Zd#d�Zed���Zd�Z d �Z ed ���Z ed ���Z ed ���Z e Zed ���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zd�Zd�Zd$d�Zd%d�Zd�Zed���Zd �Z �fd!�Z!�xZ"S)&rGa� 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�_rotrc ��tt|||f��\}}}t|fddi|��}t|t��st d|z���|jr't|��|dkrt d|z���tj ||||fi|��}||_ ||_ ||_ |j r|dtjz|z zn||_|S)Nr<r9z r must be an Expr object, not %sr3zn must be a >= 3, not %s)rBrrr�rr� is_Numberr'rrJrprqrr� is_numberrrgrs)rUrRr&r7�rotr?�objs r0rJzRegularPolygon.__new__�s�����!�Q���-�-� ��1�c� �!� %� %�� %�f� %� %���!�T�"�"� H�� B�Q� F�G�G� G� �;� D� �1�I�I�I��1�u�u�#�$>��$B�C�C�C��$�T�1�a��=�=�f�=�=������� ��� �'*�}�=�3�!�A�D�&��(�#�#�#���� r2�c ����|j\}}}}t|�����fd�|||fD��\}}}|�||||��S)Nc�.��g|]}|jdd�i�����S)r7r6)r)r.r/�dps�optionss ��r0r1z.RegularPolygon._eval_evalf.<locals>.<listcomp>�s0���@�@�@��7�1�7�,�,�S�,�G�,�,�@�@�@r2)rMr)�func)rUrdr}rRr&r7r>r|s ` @r0� _eval_evalfzRegularPolygon._eval_evalf�s`�����Y� ��1�a���$����@�@�@�@�@�q�!�Q�i�@�@�@���1�a��y�y��A�q�!�$�$�$r2c�6�|j|j|j|jfS)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) )rqrrrprsrrs r0rMzRegularPolygon.args�s���|�T�\�4�7�D�I�=�=r2c�0�dt|j��zS�NzRegularPolygon(%s, %s, %s, %s)�rTrMrrs r0�__str__zRegularPolygon.__str__����/�%�� �2B�2B�B�Br2c�0�dt|j��zSr�r�rrs r0�__repr__zRegularPolygon.__repr__�r�r2c��|j\}}}}t|��|z|jdzzdtt|z ��zz S)z�Returns the area. Examples ======== >>> from sympy import RegularPolygon >>> square = RegularPolygon((0, 0), 1, 4) >>> square.area 2 >>> _ == square.length**2 True r9�)rMrr�rr)rUrRr&r7rws r0rVzRegularPolygon.area�sA���y� ��1�a���A�w�w�q�y���a��'��3�r�!�t�9�9��5�5r2c�P�|jdztt|jz ��zS)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 r9)�radiusrrrprrs r0r�zRegularPolygon.length s!��(�{�1�}�S��D�G��_�_�,�,r2c��|jS)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) )rqrrs r0�centerzRegularPolygon.center s ��0�|�r2c��|jS)z� Alias for center. Examples ======== >>> from sympy import RegularPolygon, Point >>> rp = RegularPolygon(Point(0, 0), 5, 4) >>> rp.circumcenter Point2D(0, 0) )r�rrs r0� circumcenterzRegularPolygon.circumcenter<s ���{�r2c��|jS)aRadius 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 )rrrrs r0r�zRegularPolygon.radiusKs ��6�|�r2c��|jS)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 )r�rrs r0� circumradiuszRegularPolygon.circumradiushs ���{�r2c��|jS)a3CCW 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 �rsrrs r0�rotationzRegularPolygon.rotationys ��4�y�r2c�T�|jttj|jz ��zS)a8The 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�rrrgrprrs r0�apothemzRegularPolygon.apothem�s!��6�{�S���d�g��.�.�.�.r2c��|jS)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 )r�rrs r0�inradiuszRegularPolygon.inradius�s ���|�r2c�@�|jdz tjz|jz 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 r9)rprrgrrs r0�interior_anglezRegularPolygon.interior_angle�s��.��!� �Q�T�!�$�'�)�)r2c�0�dtjz|jz 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 r9)rrgrprrs r0�exterior_anglezRegularPolygon.exterior_angle�s��.���v�d�g�~�r2c�6�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) )rr�r�rrs r0� circumcirclezRegularPolygon.circumcircle�s��.�d�k�4�;�/�/�/r2c�6�t|j|j��S)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)) )rr�r�rrs r0�incirclezRegularPolygon.incircles��.�d�k�4�<�0�0�0r2c�6�i}|j}|jD]}|||<�|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} )r�rN)rUrk�angr}s r0rozRegularPolygon.angles's2�� ���!���� � �A��C��F�F�� r2c��|j}t||��j}||jkrdS||jkrdSt �||��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)r�rr�r�r�r5r�)rUrPrR�ds r0r�zRegularPolygon.encloses_point=sX��` �K�� �A�q�M�M� �� �� � � ��5� ��� � ��4��)�)�$��2�2� 2r2c�&�|xj|z c_dS)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�)rU�angles r0�spinzRegularPolygon.spinws��( � � �U�� � � � r2Nc�|�t|��|j�}|xj|z c_tj|||��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 )�typerMrsrrb)rUr�r�r&s r0rbzRegularPolygon.rotate�s<��& �D��J�J�� � "�� ���%�����$�Q��r�2�2�2r2rc�,�|rBt|d���}|j| j��||��j|j�S||kr"t |j��||��S|j\}}}}||z}|�||||��S)aOverride 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)) r9r�)r� translaterM�scaler5rNr~)rUr\r]r�rRr&r7rws r0r�zRegularPolygon.scale�s���" � O��r�q�!�!�!�B�D�>�4�>�R�C�:�.�4�4�Q��:�:�D�b�g�N� N� ��6�6��D�M�*�0�0��A�6�6� 6��y� ��1�a�� �Q����y�y��A�q�#�&�&�&r2c�B�|j\}}}}|jd}||z }|�|��}|�|��} | |z } td| ��} td|��} | �| ��} || z }|�|| ||��S)a5Override 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)) rry)rMrN�reflectr� closing_angler~)rUrrRr&r7rwr}r��cc�vv�dd�l1�l2r�s r0r�zRegularPolygon.reflect�s����y� ��1�a�� �M�!� �� ��E�� �Y�Y�t�_�_�� �Y�Y�t�_�_�� �"�W�����_�_�� ���^�^�����r�"�"�� �s� ���y�y��a�R��C�(�(�(r2c�������|j�t|j���|j�dtjz|jz �����fd�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)] r9c ���g|]N}t�j�t|�z�z��zz�j�t |�z�z��zz����OSr6)rr\rr]r)r.rrRr&rwr}s ����r0r1z+RegularPolygon.vertices.<locals>.<listcomp>�sg���)�)�)���a�c�A�c�!�A�#��)�n�n�,�,�a�c�A�c�!�A�#��)�n�n�4D�.D�E�E�)�)�)r2)rq�absrrrsrrgrprT)rUrRr&rwr}s @@@@r0rNzRegularPolygon.vertices�sx������0 �L�� �� � � ���i�� �a�d�F�4�7�N��)�)�)�)�)�)�)��t�w���)�)�)� )r2c��t|t��sdSt|t��st�||��S|j|jkS)NF)r�r5rG�__eq__rM)rUr�s r0r�zRegularPolygon.__eq__�sN���!�W�%�%� +��5��A�~�.�.� +��>�>�!�T�*�*� *��y�A�F�"�"r2c�D��t�����Sr�)�super�__hash__)rU� __class__s �r0r�zRegularPolygon.__hash__s����w�w���!�!�!r2)r)ryr�)rrN)#rhrirjrkrlrJrrmrMr�r�rVr�r�r~r�r�r�r�r�r�r�r�r�r�ror�r�rbr�r�rNr�r�� __classcell__)r�s@r0rGrG�s��������;�;�z5�I�����"%�%�%�%� � >� >��X� >�C�C�C�C�C�C��6�6��X�6� �-�-��X�-�*����X��2�H� � � ��X� �����X��8����X�� ����X��6�/�/��X�/�8����X�� �*�*��X�*�0����X��0�0�0��X�0�0�1�1��X�1�0����X��*83�83�83�t���,3�3�3�3�.'�'�'�'�4)�)�)�8�)�)��X�)�>#�#�#�"�"�"�"�"�"�"�"�"r2rGc��eZdZdZd�Zed���Zd�Zd�Zd�Z d�Z d�Z ed ���Z ed ���Z ed ���Zed ���Zed ���Zd�Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���ZdS)rKa 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�R��t|��dkrhd�vrtd��dD���Sd�vrtd��dD���Sd�vrtd��dD���Sd}t |����fd �|D��}g}|D]&}|r ||d kr�|�|���'t|��d kr&|d |d kr|���d }|t|��dz kr�t|��dkr�t||||d z||dzgt���\}} } tj || | ��r%|||<d||d z<|�|d z��|d z }|t|��dz krt|��dk��ttd�|����}t|��dkrtj|g|�Ri���St|��dkr t|i���St|i���S)Nr3�sssc�,�g|]}t|����Sr6r�r.r>s r0r1z$Triangle.__new__.<locals>.<listcomp>B���A�A�A�a�h�q�k�k�A�A�Ar2�asac�,�g|]}t|����Sr6rr�s r0r1z$Triangle.__new__.<locals>.<listcomp>Dr�r2�sasc�,�g|]}t|����Sr6rr�s r0r1z$Triangle.__new__.<locals>.<listcomp>Fr�r2z;Triangle instantiates with three points or a valid keyword.c�.��g|]}t|fddi�����Sr;rr=s �r0r1z$Triangle.__new__.<locals>.<listcomp>Jr@r2rArrrBr9)�keyc� �|duSr�r6r�s r0�<lambda>z"Triangle.__new__.<locals>.<lambda>`s ���$��r2)rD�_sss�_asa�_sasrrErH�sortedr rrIrC�filterrrJr) rLrMr?�msgrNrOrPr/r>rQrRs ` r0rJzTriangle.__new__?s~��� �t�9�9��>�>������A�A�6�%�=�A�A�A�B�B������A�A�6�%�=�A�A�A�B�B������A�A�6�%�=�A�A�A�B�B�O�C���$�$� $�<�<�<�<�t�<�<�<����� � �A�� ��e�B�i���� �L�L��O�O�O�O� �u�:�:��>�>�e�B�i�5��8�3�3� �I�I�K�K�K� ���#�e�*�*�q�.� � �S��Z�Z�!�^�^���q��5��Q��<��q�1�u��6�<L�N�N�N�G�A�q�!��!�!�Q��*�*� !���a��#��a�!�e� �� � �!�a�%� � � � ��F�A��#�e�*�*�q�.� � �S��Z�Z�!�^�^���6�6��>�>�?�?�� �x�=�=�A� � �!�)�#�C��C�C�C�F�C�C� C� ��]�]�a� � ��H�/��/�/� /��(�-�f�-�-� -r2c��|jS)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)) )rMrrs r0rNzTriangle.verticesis ��0�y�r2c��t|t��sdSd�|jD��\}}}d�|jD��}d�}||||g|�R�p6||||g|�R�p+||||g|�R�p ||||g|�R�p||||g|�R�p ||||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��g|] }|j�� Sr6�r��r.rs r0r1z'Triangle.is_similar.<locals>.<listcomp>�s��=�=�=�D�D�K�=�=�=r2c��g|] }|j�� Sr6r�r�s r0r1z'Triangle.is_similar.<locals>.<listcomp>�s�� /� /� /�d�d�k� /� /� /r2c��t||z ��}t||z ��}t||z ��}t||k��ot||k��Sr�)r �bool) �u1�u2�u3�v1�v2�v3r r�e3s r0� _are_similarz)Triangle.is_similar.<locals>._are_similar�sN���"�R�%���B��"�R�%���B��"�R�%���B���b��>�>�4�d�2��8�n�n� 4r2)r�r5r�)�t1�t2�s1_1�s1_2�s1_3�s2r�s r0� is_similarzTriangle.is_similar�s��D�"�g�&�&� ��5�=�=�B�H�=�=�=���d�D� /� /�b�h� /� /� /�� 5� 5� 5��|�D�$��2�r�2�2�2�0� �L��t�T� /�B� /� /� /�0� �L��t�T� /�B� /� /� /�0� �L��t�T� /�B� /� /� /�0� �L��t�T� /�B� /� /� /� 0� �L��t�T� /�B� /� /� /�  0r2c�@�td�|jD���� S)abAre 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 c3�$K�|] }|jV�� dSr�r��r.r�s r0r�z*Triangle.is_equilateral.<locals>.<genexpr>�s$����<�<�A�q�x�<�<�<�<�<�<r2)r#r�rrs r0�is_equilateralzTriangle.is_equilateral�s&��8�<�<���<�<�<�<�<�<�<r2c�>�td�|jD����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 c3�$K�|] }|jV�� dSr�r�r�s r0r�z(Triangle.is_isosceles.<locals>.<genexpr>�s$����5�5�Q���5�5�5�5�5�5r2�r"r�rrs r0� is_isosceleszTriangle.is_isosceles�s#��,�5�5�$�*�5�5�5�5�5�5r2c�@�td�|jD���� S)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 c3�$K�|] }|jV�� dSr�r�r�s r0r�z&Triangle.is_scalene.<locals>.<genexpr> s$����9�9��A�H�9�9�9�9�9�9r2r�rrs r0� is_scalenezTriangle.is_scalene�s&��,�9�9�d�j�9�9�9�9�9�9�9r2c���|j}tj|d|d��pAtj|d|d��p tj|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 rrr9)r�r�is_perpendicular�rUr�s r0�is_rightzTriangle.is_right sb��. �J���'��!��a��d�3�3�1� � $�Q�q�T�1�Q�4� 0� 0�1� � $�Q�q�T�1�Q�4� 0� 0� 1r2c � �|j}|j}|d|d�|d��|d|d�|d��|d|d�|d��iS)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)) rrr9)r�rN�perpendicular_segment�rUr�r}s r0� altitudeszTriangle.altitudes# sy��< �J�� �M���!��a��d�0�0��1��6�6��!��a��d�0�0��1��6�6��!��a��d�0�0��1��6�6�8� 8r2c��|j}|j}t||d���t||d����dS)aThe 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) rr)r�rNrr�)rUr>r}s r0� orthocenterzTriangle.orthocenterG sG��6 �N�� �M���A�a��d�G�}�}�)�)�$�q��1��w�-�-�8�8��;�;r2c�b�d�|jD��\}}}|�|��dS)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�6�g|]}|�����Sr6)�perpendicular_bisector)r.r\s r0r1z)Triangle.circumcenter.<locals>.<listcomp> s$��B�B�B�!�1�+�+�-�-�B�B�Br2r)r�r�)rUr>rQrRs r0r�zTriangle.circumcenterf s7��2C�B�t�z�B�B�B���1�a��~�~�a� � ��#�#r2c�L�tj|j|jd��S)aThe 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)rrtr�rNrrs r0r�zTriangle.circumradius� s ��2�~�d�/���q�1A�B�B�Br2c�6�t|j|j��S)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) )rr�r�rrs r0r�zTriangle.circumcircle� s��0�d�'��):�;�;�;r2c�*�d�|jD��}|j}|j}t|dt |d|���|d��d��}t|dt |d|���|d��d��}t|dt |d|���|d��d��}|d||d||d|iS)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�,�g|]}t|����Sr6)r)r.�ls r0r1z&Triangle.bisectors.<locals>.<listcomp>� s�� )� )� )��T�!�W�W� )� )� )r2rrr9)r�rN�incenterrrr�)rUr�r}rRr�r��l3s r0rgzTriangle.bisectors� s���@ *� )�d�j� )� )� )�� �M�� �M�� �Q�q�T�4��!��a�=�=�5�5�a��d�;�;�A�>� ?� ?�� �Q�q�T�4��!��a�=�=�5�5�a��d�;�;�A�>� ?� ?�� �Q�q�T�4��!��a�=�=�5�5�a��d�;�;�A�>� ?� ?���!��b�!�A�$��A�a�D�"�-�-r2c���|j�t�fd�dD����}t|��}|j}t |�td�|D������|z ��}t |�td�|D������|z ��}t ||��S)aThe 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�*��g|]}�|j��Sr6r�)r.r/r�s �r0r1z%Triangle.incenter.<locals>.<listcomp>� s���3�3�3�A�A�a�D�K�3�3�3r2)rr9rc��g|] }|j�� Sr6r��r.�vis r0r1z%Triangle.incenter.<locals>.<listcomp>� ���"4�"4�"4�B�2�4�"4�"4�"4r2c��g|] }|j�� Sr6r�r s r0r1z%Triangle.incenter.<locals>.<listcomp>� rr2)r�rrhrNr �dotr)rUrrPr}r\r]r�s @r0rzTriangle.incenter� s����6 �J�� �3�3�3�3��3�3�3� 4� 4�� ��F�F�� �M�� �Q�U�U�6�"4�"4�!�"4�"4�"4�5�5�6�6�q�8� 9� 9�� �Q�U�U�6�"4�"4�!�"4�"4�"4�5�5�6�6�q�8� 9� 9���Q��{�{�r2c�@�td|jz|jz ��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 r9)r rVrurrs r0r�zTriangle.inradius s��0��D�I� ���6�7�7�7r2c�6�t|j|j��S)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)) )rrr�rrs r0r�zTriangle.incircle s��6�d�m�T�]�3�3�3r2c �J�|j}|dj}|dj}|dj}||z|zdz }|j}|jdt|||z z ��|jdt|||z z ��|jdt|||z z ��i}|S)aoThe 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 rrr9)r�r�rVr )rUrr>rQrRr�rV�exradiis r0rzTriangle.exradii9 s���L�z�� ��G�N�� ��G�N�� ��G�N�� �q�S��U�A�I���y���:�a�=�(�4��1��:�"6�"6��:�a�=�(�4��1��:�"6�"6��:�a�=�(�4��1��:�"6�"6�8���r2c ��|j}|j}|dj}|dj}|dj}|dj|dj|djg}|dj|dj|djg}t | |dz||dzz||dz| |z|zz z��t ||dz||dzz ||dz||z |zz z��t ||dz||dzz||dz||z|z z z ��t | |dz||dzz||dz| |z|zz z��t ||dz||dzz ||dz||z |zz z��t ||dz||dzz||dz||z|z z z ��d�}|dt |d|d��|dt |d|d��|dt |d |d ��i} | S) asExcenters 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 rrr9)rWrY�x3rXrZ�y3rWrXrYrZrr)r�rNr�r\r]r r) rUr�r}r>rQrRr\r]� exc_coords� excenterss r0rzTriangle.excentersk s>��L �J�� �M�� �a�D�K�� �a�D�K�� �a�D�K�� �q�T�V�Q�q�T�V�Q�q�T�V� $�� �q�T�V�Q�q�T�V�Q�q�T�V� $���A�2�a��d�7�1�Q�q�T�6�>�!�A�a�D�&�1�"�Q�$�q�&�/�9�:�:��1�Q�q�T�6�!�A�a�D�&�=��1�Q�4���1��Q���7�8�8��1�Q�q�T�6�!�A�a�D�&�=��1�Q�4���1��Q���7�8�8��A�2�a��d�7�1�Q�q�T�6�>�!�A�a�D�&�1�"�Q�$�q�&�/�9�:�:��1�Q�q�T�6�!�A�a�D�&�=��1�Q�4���1��Q���7�8�8��1�Q�q�T�6�!�A�a�D�&�=��1�Q�4���1��Q���7�8�8�  � � � �a�D�%� �4�(�*�T�*:�;�;� �a�D�%� �4�(�*�T�*:�;�;� �a�D�%� �4�(�*�T�*:�;�;� � � �r2c � �|j}|j}|dt|d|dj��|dt|d|dj��|dt|d|dj��iS)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)) rrr9)r�rNr�midpointr�s r0�medianszTriangle.medians� ss��< �J�� �M���!��g�a��d�A�a�D�M�2�2��!��g�a��d�A�a�D�M�2�2��!��g�a��d�A�a�D�M�2�2�4� 4r2c�t�|j}t|dj|dj|dj��S)aThe 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)) rrr9)r�rKrr�s r0�medialzTriangle.medial� s/��4 �J����!�� �q��t�}�a��d�m�D�D�Dr2c�(�t|jj�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) )rrrNrrs r0�nine_point_circlezTriangle.nine_point_circle� s��<�t�{�+�,�,r2c�l�|���r|jSt|j|j��S)aThe 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�rr�rrs r0� eulerlinezTriangle.eulerline s7��, � � � � � $��#� #��D�$�d�&7�8�8�8r2N)rhrirjrkrJrmrNr�r�r�r�r�r�r�r�r�r�rgrr�r�rrrrr!r#r6r2r0rKrKs+������7�7�r(.�(.�(.�T����X��240�40�40�l=�=�=�<6�6�6�0:�:�:�01�1�1�8�!8�!8��X�!8�F�<�<��X�<�<�$�$��X�$�6�C�C��X�C�4�<�<��X�<�2&.�&.�&.�P� � ��X� �D�8�8��X�8�2�4�4��X�4�8�/�/��X�/�b�<�<��X�<�|�!4�!4��X�!4�F�E�E��X�E�8�-�-��X�-�>�9�9��X�9�9�9r2rKc��|tzdz S)zAReturn the radian value for the given degrees (pi = 180 degrees).��r)r�s r0�radr'% ��� �R�4��8�Or2c��|tz dzS)zAReturn the degree value for the given radians (pi = 180 degrees).r%r&)r&s r0�degr** r(r2c�>�tt|����}|Sr�)rr')r��rvs r0�_sloper-/ s�� �S��V�V���B� �Ir2c ���tdt|������t|dftd|z �������d}td|df|��S)z8Return triangle having side with length l on the x-axis.ryr�rr%)rr-r�rK)�d1r�d2�xys r0r�r�4 sh�� �f�F�2�J�J� '� '� '� 4� 4� �a��V�6�#��(�+�+�,�,�,� .� .�./� 1�B� �F�Q��F�B� '� '�'r2c���td|��}t|df|��}d�|�|��D��}|sdS|d}td|df|��S)z7Return triangle having side of length l1 on the x-axis.ryrc�*�g|]}|jj�|��Sr6)r]�is_nonnegativer�s r0r1z_sss.<locals>.<listcomp>? s"�� B� B� B�1�q�s�/A� B�Q� B� B� Br2N)rr�rK)r�r�r �c1�c2�interr�s r0r�r�; so�� ��� � �B� ��Q��� � �B� B� B�����+�+� B� B� B�E� ���t� �q��B� �F�R��G�R� (� (�(r2c���tdd��}t|d��}ttt|����|ztt|����|z��}t |||��S)z9Return triangle having side with length l2 on the x-axis.r)rrr'rrK)r�r�r�r�r��p3s r0r�r�F s]�� �q�!���B� �r�1���B� �s�3�q�6�6�{�{�2�~�s�3�q�6�6�{�{�2�~� .� .�B� �B��B� � �r2)E� sympy.corerrrrr�sympy.core.evalfr�sympy.core.sortingr r �sympy.core.symbolr r r �$sympy.functions.elementary.complexesr�$sympy.functions.elementary.piecewiser�(sympy.functions.elementary.trigonometricrrr�ellipserr�rr� exceptionsrrrrrr�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)rrTr\r]r�r5rGrKr'r*r-r�r�r�r6r2r0�<module>rJs���/�/�/�/�/�/�/�/�/�/�/�/�/�/�������8�8�8�8�8�8�8�8�4�4�4�4�4�4�4�4�4�4�5�5�5�5�5�5�:�:�:�:�:�:�B�B�B�B�B�B�B�B�B�B�������/�/�/�/�/�/�/�/�%�%�%�%�%�%�$�$�$�$�$�$�$�$�$�$�������������!�!�!�!�!�!�,�,�,�,�,�,�'�'�'�'�'�'�^�^�^�^�^�^�^�^�^�^�^�^�^�^�2�2�2�2�2�2�2�2�+�+�+�+�+�+����� @� ?�e�e�A�h�h� ?� ?� ?���1�a�m�m�m�m�m�k�m�m�m�`+v "�v "�v "�v "�v "�W�v "�v "�v "�r^ 9�^ 9�^ 9�^ 9�^ 9�w�^ 9�^ 9�^ 9�@��� ��� ��� (�(�(�)�)�)� � � � � r2
Memory