� ��g:����dZddlmZddlmZddlmZddlmZm Z m Z ddl m Z ddl mZddlmZdd lmZmZmZdd lmZdd lmZdd lmZmZmZmZd dlmZm Z d dl!m"Z"d dl#m$Z$m%Z%d dl&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6m7Z7ddl8Z8d�e9d��D��\Z:Z;Gd�de ��Z<Gd�de<��Z=Gd �d!e<��Z>Gd"�d#e<��Z?Gd$�d%e<��Z@Gd&�d'e@e=��ZAGd(�d)e@e>��ZBGd*�d+e@e?��ZCGd,�d-e<��ZDGd.�d/eDe=��ZEGd0�d1eDe>��ZFGd2�d3eDe?��ZGdS)4z�Line-like geometrical entities. Contains ======== LinearEntity Line Ray Segment LinearEntity2D Line2D Ray2D Segment2D LinearEntity3D Line3D Ray3D Segment3D �)�Tuple)�N)�Expr)�Rational�oo�Float)�Eq)�S)�ordered)�_symbol�Dummy�uniquely_named_symbol)�sympify)� Piecewise)� _pi_coeff�acos�tan�atan2�)�GeometryEntity� GeometrySet)� GeometryError)�Point�Point3D)�find� intersection)�And)�Matrix)� Intersection��simplify)�solve)� linear_coeffs)� Undecidable� filldedentNc�,�g|]}td����S)� line_dummy)r ��.0�is �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/geometry/line.py� <listcomp>r,/s ��.�.�.���l���.�.�.��c��eZdZdZdd�Zd�Zd�Zed���Zd�Z d�Z dd �Z e d ���Z d �Zed ���Zd�Zd�Zd�Zd�Zed���Zed���Zed���Zd�Zd�Zd�Zed���Zd�Zdd�Zd�ZdS)� LinearEntityanA base class for all linear entities (Line, Ray and Segment) in n-dimensional Euclidean space. Attributes ========== ambient_dimension direction length p1 p2 points Notes ===== This is an abstract class and is not meant to be instantiated. See Also ======== sympy.geometry.entity.GeometryEntity Nc ��tj||��\}}||krtd|jz���t |��t |��krtd|jz���t j|||fi|��S)N�&%s.__new__ requires two unique Points.z2%s.__new__ requires two Points of equal dimension.)r�_normalize_dimension� ValueError�__name__�lenr�__new__��cls�p1�p2�kwargss r+r7zLinearEntity.__new__Ks����+�B��3�3���B� ��8�8��8�3�<�G�I�I� I� �r�7�7�c�"�g�g� � ��D�s�|�S�U�U� U��%�c�2�r�<�<�V�<�<�<r-c�`�|�|��}|�|Std|�d|�d����)z}Return a definitive answer or else raise an error if it cannot be determined that other is on the boundaries of self.NzCannot decide whether 'z ' contains '�')�containsr$)�self�other�results r+� __contains__zLinearEntity.__contains__XsG�����u�%�%�� � ��M��+�>B�d�d�E�E�E�J�L�L� Lr-c�x�|j|krdS||jz }|j}|�|��dkrdSdS)aTest whether the point `other` lies in the positive span of `self`. A point x is 'in front' of a point y if x.dot(y) >= 0. Return -1 if `other` is behind `self.p1`, 0 if `other` is `self.p1` and and 1 if `other` is in front of `self.p1`.rr�����)r:� direction�dot)r@rA�rel_pos�ds r+� _span_testzLinearEntity._span_testcsG�� �7�e� � ��1��$�'�/�� �N�� �5�5��>�>�A� � ��1��rr-c�*�t|j��S)aCA property method that returns the dimension of LinearEntity object. Parameters ========== p1 : LinearEntity Returns ======= dimension : integer Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(1, 1) >>> l1 = Line(p1, p2) >>> l1.ambient_dimension 2 >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1) >>> l1 = Line(p1, p2) >>> l1.ambient_dimension 3 )r6r:�r@s r+�ambient_dimensionzLinearEntity.ambient_dimensionqs��>�4�7�|�|�r-c��t|t��s$t|t��std���|j|j}}t |�|��t |��t |��zz ��S)a�Return the non-reflex angle formed by rays emanating from the origin with directions the same as the direction vectors of the linear entities. Parameters ========== l1 : LinearEntity l2 : LinearEntity Returns ======= angle : angle in radians Notes ===== From the dot product of vectors v1 and v2 it is known that: ``dot(v1, v2) = |v1|*|v2|*cos(A)`` where A is the angle formed between the two vectors. We can get the directional vectors of the two lines and readily find the angle between the two using the above formula. See Also ======== is_perpendicular, Ray2D.closing_angle Examples ======== >>> from sympy import Line >>> e = Line((0, 0), (1, 0)) >>> ne = Line((0, 0), (1, 1)) >>> sw = Line((1, 1), (0, 0)) >>> ne.angle_between(e) pi/4 >>> sw.angle_between(e) 3*pi/4 To obtain the non-obtuse angle at the intersection of lines, use the ``smallest_angle_between`` method: >>> sw.smallest_angle_between(e) pi/4 >>> from sympy import Point3D, Line3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0) >>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3) >>> l1.angle_between(l2) acos(-sqrt(2)/3) >>> l1.smallest_angle_between(l2) acos(sqrt(2)/3) �#Must pass only LinearEntity objects)� isinstancer0� TypeErrorrFrrG�abs��l1�l2�v1�v2s r+� angle_betweenzLinearEntity.angle_between�ss��t�"�l�+�+� C�J�r�<�4P�4P� C��A�B�B� B���r�|�B���B�F�F�2�J�J��B����B����0�1�1�1r-c�.�t|t��s$t|t��std���|j|j}}t t |�|����t |��t |��zz ��S)agReturn the smallest angle formed at the intersection of the lines containing the linear entities. Parameters ========== l1 : LinearEntity l2 : LinearEntity Returns ======= angle : angle in radians Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 0), Point(0, 4), Point(2, -2) >>> l1, l2 = Line(p1, p2), Line(p1, p3) >>> l1.smallest_angle_between(l2) pi/4 See Also ======== angle_between, is_perpendicular, Ray2D.closing_angle rO)rPr0rQrFrrRrGrSs r+�smallest_angle_betweenz#LinearEntity.smallest_angle_between�sx��:�"�l�+�+� C�J�r�<�4P�4P� C��A�B�B� B���r�|�B���C����r� � �O�O�S��W�W�S��W�W�_�5�6�6�6r-�tc���t|d���}|jd�|jD��vr$tt d|jz�����|j|j|jz |zzS)a+A parameterized point on the Line. Parameters ========== parameter : str, optional The name of the parameter which will be used for the parametric point. The default value is 't'. When this parameter is 0, the first point used to define the line will be returned, and when it is 1 the second point will be returned. Returns ======= point : Point Raises ====== ValueError When ``parameter`` already appears in the Line's definition. See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(1, 0), Point(5, 3) >>> l1 = Line(p1, p2) >>> l1.arbitrary_point() Point2D(4*t + 1, 3*t) >>> from sympy import Point3D, Line3D >>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 1) >>> l1 = Line3D(p1, p2) >>> l1.arbitrary_point() Point3D(4*t + 1, 3*t, t) T��realc3�$K�|] }|jV�� dS�N)�name)r)�fs r+� <genexpr>z/LinearEntity.arbitrary_point.<locals>.<genexpr>!s$����8�8��a�f�8�8�8�8�8�8r-zx Symbol %s already appears in object and cannot be used as a parameter. )r ra� free_symbolsr4r%r:r;�r@� parameterr[s r+�arbitrary_pointzLinearEntity.arbitrary_point�s���V �I�D� )� )� )�� �6�8�8�d�&7�8�8�8� 8� 8��Z�)��f�)����� � �w�$�'�D�G�+�Q�.�.�.r-c�P�t|�}|jrt|��dkrdSdS)a�Is a sequence of linear entities concurrent? Two or more linear entities are concurrent if they all intersect at a single point. Parameters ========== lines A sequence of linear entities. Returns ======= True : if the set of linear entities intersect in one point False : otherwise. See Also ======== sympy.geometry.util.intersection Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(3, 5) >>> p3, p4 = Point(-2, -2), Point(0, 2) >>> l1, l2, l3 = Line(p1, p2), Line(p1, p3), Line(p1, p4) >>> Line.are_concurrent(l1, l2, l3) True >>> l4 = Line(p2, p3) >>> Line.are_concurrent(l2, l3, l4) False >>> from sympy import Point3D, Line3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 5, 2) >>> p3, p4 = Point3D(-2, -2, -2), Point3D(0, 2, 1) >>> l1, l2, l3 = Line3D(p1, p2), Line3D(p1, p3), Line3D(p1, p4) >>> Line3D.are_concurrent(l1, l2, l3) True >>> l4 = Line3D(p2, p3) >>> Line3D.are_concurrent(l2, l3, l4) False rTF)r� is_FiniteSetr6)�lines� common_pointss r+�are_concurrentzLinearEntity.are_concurrent*s6��^%�e�,� � � %� �#�m�*<�*<��*A�*A��4��ur-c��t���)z�Subclasses should implement this method and should return True if other is on the boundaries of self; False if not on the boundaries of self; None if a determination cannot be made.)�NotImplementedError�r@rAs r+r?zLinearEntity.contains^s�� "�#�#�#r-c� �|j|jz S)a]The direction vector of the LinearEntity. Returns ======= p : a Point; the ray from the origin to this point is the direction of `self` Examples ======== >>> from sympy import Line >>> a, b = (1, 1), (1, 3) >>> Line(a, b).direction Point2D(0, 2) >>> Line(b, a).direction Point2D(0, -2) This can be reported so the distance from the origin is 1: >>> Line(b, a).direction.unit Point2D(0, -1) See Also ======== sympy.geometry.point.Point.unit )r;r:rLs r+rFzLinearEntity.directiones��>�w��� � r-c�D�d�}d�}d�}t|t��st||j���}|jr|�|��r|gSgSt|t ���r�tj|j|j |j|j ��}tj |�}|dk�r t|t��r|gSt|t��r|gSt|t��r!t|t��r |||��St|t��r!t|t��r |||��St|t��r!t|t��r |||��St|t��r!t|t��r |||��S�nW|dk�rNt|dd��}t|dd��}|j�|j��rgSt!|j|j g�����} t!|j|jz g�����} | �d| ���d� ��\} } t)| ��dkr#t+d �| | �����| d } |j| z|jz}t|t��rt|t��r|gSt|t��s|�|��r|�|��r|gS|�t0��s|�t0��sgSt3|�t6��|�t8��z t6t8d� ��d }d�}||t6|��r||t8|��r|gSgSgS|�|��S)a:The intersection with another geometrical entity. Parameters ========== o : Point or LinearEntity Returns ======= intersection : list of geometrical entities See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line, Segment >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(7, 7) >>> l1 = Line(p1, p2) >>> l1.intersection(p3) [Point2D(7, 7)] >>> p4, p5 = Point(5, 0), Point(0, 3) >>> l2 = Line(p4, p5) >>> l1.intersection(l2) [Point2D(15/8, 15/8)] >>> p6, p7 = Point(0, 5), Point(2, 6) >>> s1 = Segment(p6, p7) >>> l1.intersection(s1) [] >>> from sympy import Point3D, Line3D, Segment3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(7, 7, 7) >>> l1 = Line3D(p1, p2) >>> l1.intersection(p3) [Point3D(7, 7, 7)] >>> l1 = Line3D(Point3D(4,19,12), Point3D(5,25,17)) >>> l2 = Line3D(Point3D(-3, -15, -19), direction_ratio=[2,8,8]) >>> l1.intersection(l2) [Point3D(1, 1, -3)] >>> p6, p7 = Point3D(0, 5, 2), Point3D(2, 6, 3) >>> s1 = Segment3D(p6, p7) >>> l1.intersection(s1) [] c�&�|j�|j��dkr$|�|j��dkr|gn|gS|�|j��}|dkrgS|dkr|jgSt |j|j��gS�Nr)rFrGrJr:�Segment)�ray1�ray2�sts r+�intersect_parallel_raysz:LinearEntity.intersection.<locals>.intersect_parallel_rays�s����~�!�!�$�.�1�1�A�5�5�"&�����!9�!9�Q�!>�!>��v�v�T�F�J��_�_�T�W�-�-����6�6��I��1�W�W� �G�9�$������1�1�2�2r-c��|�|j��|�|j��}}|dkr|dkrgS|dkr |dkr|gS|dkrt|j|j��gSt|j|j��gSrs)rJr:r;rt)�ray�seg�st1�st2s r+�"intersect_parallel_ray_and_segmentzELinearEntity.intersection.<locals>.intersect_parallel_ray_and_segment�s����~�~�c�f�-�-�s�~�~�c�f�/E�/E��C��Q�w�w�3��7�7�� �����c�Q�h�h��u� ����������/�/�0�0������/�/�0�0r-c��|�|��r|gS|�|��r|gS|j�|j��dkrt|j|j��}|�|j��dkr||}}|�|j��dkrgSt|j|j��gSrs)r?rFrGrtr;r:rJ)�seg1�seg2s r+�intersect_parallel_segmentsz>LinearEntity.intersection.<locals>.intersect_parallel_segments�s����}�}�T�"�"� ��v� ��}�}�T�"�"� ��v� ��~�!�!�$�.�1�1�A�5�5��t�w���0�0�����t�w�'�'�!�+�+�!�4�d�����t�w�'�'�!�+�+�� ��D�G�T�W�-�-�.� .r-��dimrr.NTr z+Failed when solving Mx=b when M={} and b={})rr.)�dictrc���t|t��rdSt|t��r|jSt|t��r|jo d|z jSt d���)NTrzunexpected line type)rP�Line�Ray�is_nonnegativertr4)�p�ls r+�okz%LinearEntity.intersection.<locals>.ok'sk��!�!�T�*�*�$�#�t�!�!�S�)�)�0� �/�/�!�!�W�-�-�K� �/�J�Q��U�4J�J�$�%;�<�<�<r-)rPrrrM�is_Pointr?r0r3r:r;� affine_rankr�r�rtrF�is_scalar_multipler� transpose� col_insert�rrefr6r�format�atomsrr"rgr[�ur)r@rArxr~r��pts�rankrTrU�m�v�m_rref�pivots�coeff�line_intersection�tur�s r+rzLinearEntity.intersection�s@��b 3� 3� 3� 1� 1� 1� /� /� /� �%��0�0� =��%�T�%;�<�<�<�E� �>�U ��}�}�U�#�#� ��w��� � ��|� ,� ,�P ��,�T�W�d�g�u�x���R�R�C��$�c�*�D��q�y�y��d�D�)�)�#�!�7�N��e�T�*�*�"� �6�M��d�C�(�(�@�Z��s�-C�-C�@�2�2�4��?�?�?��d�C�(�(�K�Z��w�-G�-G�K�=�=�d�E�J�J�J��d�G�,�,�K��E�3�1G�1G�K�=�=�e�T�J�J�J��d�G�,�,�D��E�7�1K�1K�D�6�6�t�U�C�C�C�������3�r��r�7�^���3�q�r�r�7�^�� �<�2�2�2�<�@�@���I��B�L�2�<�-�8�9�9�C�C�E�E���B�E�B�E�M�?�+�+�5�5�7�7��"#���a��!3�!3�!8�!8�$�!8�!G�!G�����v�;�;�!�#�#�'�(U�(\�(\�]^�`a�(b�(b�c�c�c��t� ��$&�L��$6���$@�!��d�D�)�)�/�j���.E�.E�/�-�.�.���d�+�+�/��]�]�#4�5�5�/����'8�9�9�/�.�.�.��z�z�%�(�(�����U�1C�1C���I� �4�/�/��2�2�U�5J�5J�1�5M�5M�M��q�t�%�%�%�%&�(�� =� =� =��2�b��e�T�?�?�/�r�r�"�Q�%��'7�'7�/�-�.�.�� �� ��!�!�$�'�'�'r-c��t|t��s$t|t��std���|j�|j��S)aAre two linear entities parallel? Parameters ========== l1 : LinearEntity l2 : LinearEntity Returns ======= True : if l1 and l2 are parallel, False : otherwise. See Also ======== coefficients Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(1, 1) >>> p3, p4 = Point(3, 4), Point(6, 7) >>> l1, l2 = Line(p1, p2), Line(p3, p4) >>> Line.is_parallel(l1, l2) True >>> p5 = Point(6, 6) >>> l3 = Line(p3, p5) >>> Line.is_parallel(l1, l3) False >>> from sympy import Point3D, Line3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 4, 5) >>> p3, p4 = Point3D(2, 1, 1), Point3D(8, 9, 11) >>> l1, l2 = Line3D(p1, p2), Line3D(p3, p4) >>> Line3D.is_parallel(l1, l2) True >>> p5 = Point3D(6, 6, 6) >>> l3 = Line3D(p3, p5) >>> Line3D.is_parallel(l1, l3) False rO)rPr0rQrFr��rTrUs r+� is_parallelzLinearEntity.is_parallel;sQ��Z�"�l�+�+� C�J�r�<�4P�4P� C��A�B�B� B��|�.�.�r�|�<�<�<r-c���t|t��s$t|t��std���tj�|j�|j����S)a�Are two linear entities perpendicular? Parameters ========== l1 : LinearEntity l2 : LinearEntity Returns ======= True : if l1 and l2 are perpendicular, False : otherwise. See Also ======== coefficients Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 1) >>> l1, l2 = Line(p1, p2), Line(p1, p3) >>> l1.is_perpendicular(l2) True >>> p4 = Point(5, 3) >>> l3 = Line(p1, p4) >>> l1.is_perpendicular(l3) False >>> from sympy import Point3D, Line3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0) >>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3) >>> l1.is_perpendicular(l2) False >>> p4 = Point3D(5, 3, 7) >>> l3 = Line3D(p1, p4) >>> l1.is_perpendicular(l3) False rO)rPr0rQr �Zero�equalsrFrGr�s r+�is_perpendicularzLinearEntity.is_perpendicularms_��V�"�l�+�+� C�J�r�<�4P�4P� C��A�B�B� B��v�}�}�R�\�-�-�b�l�;�;�<�<�<r-c�`�t|j|j��}|�|��S)aC Return True if self and other are contained in the same line. Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 1), Point(3, 4), Point(2, 3) >>> l1 = Line(p1, p2) >>> l2 = Line(p1, p3) >>> l1.is_similar(l2) True )r�r:r;r?)r@rAr�s r+� is_similarzLinearEntity.is_similar�s)�� ���$�'� "� "���z�z�%� � � r-c��tjS)z� The length of the line. Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(3, 5) >>> l1 = Line(p1, p2) >>> l1.length oo )r �InfinityrLs r+�lengthzLinearEntity.length�s ���z�r-c��|jdS)a=The first defining point of a linear entity. See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(5, 3) >>> l = Line(p1, p2) >>> l.p1 Point2D(0, 0) r��argsrLs r+r:zLinearEntity.p1����&�y��|�r-c��|jdS)a>The second defining point of a linear entity. See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(5, 3) >>> l = Line(p1, p2) >>> l.p2 Point2D(5, 3) rr�rLs r+r;zLinearEntity.p2�r�r-c�^�t||j���}t|||jz��S)a?Create a new Line parallel to this linear entity which passes through the point `p`. Parameters ========== p : Point Returns ======= line : Line See Also ======== is_parallel Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2) >>> l1 = Line(p1, p2) >>> l2 = l1.parallel_line(p3) >>> p3 in l2 True >>> l1.is_parallel(l2) True >>> from sympy import Point3D, Line3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0) >>> l1 = Line3D(p1, p2) >>> l2 = l1.parallel_line(p3) >>> p3 in l2 True >>> l1.is_parallel(l2) True r�)rrMr�rF�r@r�s r+� parallel_linezLinearEntity.parallel_line�s1��P �!��/� 0� 0� 0���A�q�4�>�)�*�*�*r-c��t||j���}||vr||jjz}t ||�|����S)a�Create a new Line perpendicular to this linear entity which passes through the point `p`. Parameters ========== p : Point Returns ======= line : Line See Also ======== sympy.geometry.line.LinearEntity.is_perpendicular, perpendicular_segment Examples ======== >>> from sympy import Point3D, Line3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0) >>> L = Line3D(p1, p2) >>> P = L.perpendicular_line(p3); P Line3D(Point3D(-2, 2, 0), Point3D(4/29, 6/29, 8/29)) >>> L.is_perpendicular(P) True In 3D the, the first point used to define the line is the point through which the perpendicular was required to pass; the second point is (arbitrarily) contained in the given line: >>> P.p2 in L True r�)rrMrF�orthogonal_directionr�� projectionr�s r+�perpendicular_linezLinearEntity.perpendicular_linesN��J �!��/� 0� 0� 0�� ��9�9��D�N�7�7�A��A�t���q�)�)�*�*�*r-c���t||j���}||vr|S|�|��}tt |j|j��|��\}t||��S)aCreate a perpendicular line segment from `p` to this line. The endpoints of the segment are ``p`` and the closest point in the line containing self. (If self is not a line, the point might not be in self.) Parameters ========== p : Point Returns ======= segment : Segment Notes ===== Returns `p` itself if `p` is on this linear entity. See Also ======== perpendicular_line Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2) >>> l1 = Line(p1, p2) >>> s1 = l1.perpendicular_segment(p3) >>> l1.is_perpendicular(s1) True >>> p3 in s1 True >>> l1.perpendicular_segment(Point(4, 0)) Segment2D(Point2D(4, 0), Point2D(2, 2)) >>> from sympy import Point3D, Line3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 2, 0) >>> l1 = Line3D(p1, p2) >>> s1 = l1.perpendicular_segment(p3) >>> l1.is_perpendicular(s1) True >>> p3 in s1 True >>> l1.perpendicular_segment(Point3D(4, 0, 0)) Segment3D(Point3D(4, 0, 0), Point3D(4/3, 4/3, 4/3)) r�)rrMr�rr�r:r;rt�r@r�r�r;s r+�perpendicular_segmentz"LinearEntity.perpendicular_segment=sh��h �!��/� 0� 0� 0�� ��9�9��H� � #� #�A� &� &���4�����1�1�1�5�5����q�"�~�~�r-c��|j|jfS)a�The two points used to define this linear entity. Returns ======= points : tuple of Points See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(5, 11) >>> l1 = Line(p1, p2) >>> l1.points (Point2D(0, 0), Point2D(5, 11)) )r:r;rLs r+�pointszLinearEntity.pointszs��0����!�!r-c�p��t|t��st|�j���}�fd�}t|t��r ||��St|t��r�||j��||j��}}||kr|S|�||��}t�|��}|j r|S|j rt|��dkr|\}|S�j � |j ��dkr |j\}}|�||��}|St!d|�d������)a�Project a point, line, ray, or segment onto this linear entity. Parameters ========== other : Point or LinearEntity (Line, Ray, Segment) Returns ======= projection : Point or LinearEntity (Line, Ray, Segment) The return type matches the type of the parameter ``other``. Raises ====== GeometryError When method is unable to perform projection. Notes ===== A projection involves taking the two points that define the linear entity and projecting those points onto a Line and then reforming the linear entity using these projections. A point P is projected onto a line L by finding the point on L that is closest to P. This point is the intersection of L and the line perpendicular to L that passes through P. See Also ======== sympy.geometry.point.Point, perpendicular_line Examples ======== >>> from sympy import Point, Line, Segment, Rational >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(Rational(1, 2), 0) >>> l1 = Line(p1, p2) >>> l1.projection(p3) Point2D(1/4, 1/4) >>> p4, p5 = Point(10, 0), Point(12, 1) >>> s1 = Segment(p4, p5) >>> l1.projection(s1) Segment2D(Point2D(5, 5), Point2D(13/2, 13/2)) >>> p1, p2, p3 = Point(0, 0, 1), Point(1, 1, 2), Point(2, 0, 1) >>> l1 = Line(p1, p2) >>> l1.projection(p3) Point3D(2/3, 2/3, 5/3) >>> p4, p5 = Point(10, 0, 1), Point(12, 1, 3) >>> s1 = Segment(p4, p5) >>> l1.projection(s1) Segment3D(Point3D(10/3, 10/3, 13/3), Point3D(5, 5, 6)) r�c�X��tj|�jz �j���jzSr`)r�projectr:rF)r�r@s �r+� proj_pointz+LinearEntity.projection.<locals>.proj_point�s$����=��T�W��d�n�=�=���G� Gr-rrzDo not know how to project z onto )rPrrrMr0r:r;� __class__r�is_emptyrir6rFrGr��funcr)r@rAr�r:r;� projected�as` r+r�zLinearEntity.projection�sq���t�%��0�0� =��%�T�%;�<�<�<�E� H� H� H� H� H� �e�U� #� #� ��:�e�$�$� $� ��|� ,� ,� ��Z���)�)�:�:�e�h�+?�+?��B��R�x�x�� �����B�/�/�I�$�T�9�5�5�I��!� !� � ��%� �#�i�.�.�A�*=�*=�������~�!�!�)�"5�6�6��:�:�"����B�%�N�N�2�r�2�2� �� ��m�7<�u�u�d�d� C�E�E� Er-c���|�tj|��}nt}|�t��}t |t ��r$t |�dd����}net |t��r|���}n;t |t��r|�dd��}ntd���|� tt|����S)a�A random point on a LinearEntity. Returns ======= point : Point See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Line, Ray, Segment >>> p1, p2 = Point(0, 0), Point(5, 3) >>> line = Line(p1, p2) >>> r = line.random_point(seed=42) # seed value is optional >>> r.n(3) Point2D(-0.72, -0.432) >>> r in line True >>> Ray(p1, p2).random_point(seed=42).n(3) Point2D(0.72, 0.432) >>> Segment(p1, p2).random_point(seed=42).n(3) Point2D(3.2, 1.92) Nrrzunhandled line type) �random�Randomrgr[rPr�rR�gaussrtr�rn�subsr)r@�seed�rng�ptr�s r+� random_pointzLinearEntity.random_point�s���< � ��-��%�%�C�C��C� � !� !�!� $� $�� �d�C� � � =��C�I�I�a��O�O�$�$�A�A� ��g� &� &� =�� � � � �A�A� ��d� #� #� =�� � �!�Q���A�A�%�&;�<�<� <��w�w�q�(�1�+�+�&�&�&r-c��t|t��std|z���||}}|jj|jjkrqt|t ��r||}}t j|j|jd���\}}t j|j|jd���\}}t||��}t||��}|std���|d}t|t��r|gS|j j } |j j } t||| z| z��} t||| z| z ��} | | gS)aNReturns the perpendicular lines which pass through the intersections of self and other that are in the same plane. Parameters ========== line : Line3D Returns ======= list: two Line instances Examples ======== >>> from sympy import Point3D, Line3D >>> r1 = Line3D(Point3D(0, 0, 0), Point3D(1, 0, 0)) >>> r2 = Line3D(Point3D(0, 0, 0), Point3D(0, 1, 0)) >>> r1.bisectors(r2) [Line3D(Point3D(0, 0, 0), Point3D(1, 1, 0)), Line3D(Point3D(0, 0, 0), Point3D(1, -1, 0))] zExpecting LinearEntity, not %s�ignore)�on_morphzThe lines do not intersectr) rPr0rr:rM�Line2Drr3r;r�rrF�unit) r@rArTrU�_r:r;�pointr��d1�d2�bis1�bis2s r+� bisectorszLinearEntity.bisectorssI��0�%��.�.� J�� @�5� H�I�I� I��u�B�� �5� "�b�e�&=� =� =��"�f�%�%� ��R�B���.�r�u�b�e�h�O�O�O�E�A�r��.�r�u�b�e�h�O�O�O�E�A�r��b�"���B��R��$�$��� �� <�=�=� =��q��B��"�d�#�#� ��v� ��\� �� �\� ���B��R��"� �%�%���B��R��"� �%�%���d�|�r-r`�r[)r5� __module__� __qualname__�__doc__r7rCrJ�propertyrMrXrZrg� staticmethodrlr?rFrr�r�r�r�r:r;r�r�r�r�r�r�r��r-r+r0r02s��������0 =� =� =� =� L� L� L� � � �����X��@>2�>2�>2�@!7�!7�!7�F3/�3/�3/�3/�j�1�1��\�1�f$�$�$��!�!��X�!�@s(�s(�s(�j0=�0=�0=�d.=�.=�.=�`!�!�!�"� � ��X� �����X��(����X��()+�)+�)+�V(+�(+�(+�T;�;�;�z�"�"��X�"�2WE�WE�WE�r+'�+'�+'�+'�Z8�8�8�8�8r-r0c�2�eZdZdZd�Zd�Zd�Zd�Zd d�ZdS) r�a�An infinite line in space. A 2D line is declared with two distinct points, point and slope, or an equation. A 3D line may be defined with a point and a direction ratio. Parameters ========== p1 : Point p2 : Point slope : SymPy expression direction_ratio : list equation : equation of a line Notes ===== `Line` will automatically subclass to `Line2D` or `Line3D` based on the dimension of `p1`. The `slope` argument is only relevant for `Line2D` and the `direction_ratio` argument is only relevant for `Line3D`. The order of the points will define the direction of the line which is used when calculating the angle between lines. See Also ======== sympy.geometry.point.Point sympy.geometry.line.Line2D sympy.geometry.line.Line3D Examples ======== >>> from sympy import Line, Segment, Point, Eq >>> from sympy.abc import x, y, a, b >>> L = Line(Point(2,3), Point(3,5)) >>> L Line2D(Point2D(2, 3), Point2D(3, 5)) >>> L.points (Point2D(2, 3), Point2D(3, 5)) >>> L.equation() -2*x + y + 1 >>> L.coefficients (-2, 1, 1) Instantiate with keyword ``slope``: >>> Line(Point(0, 0), slope=0) Line2D(Point2D(0, 0), Point2D(1, 0)) Instantiate with another linear object >>> s = Segment((0, 0), (0, 1)) >>> Line(s).equation() x The line corresponding to an equation in the for `ax + by + c = 0`, can be entered: >>> Line(3*x + y + 18) Line2D(Point2D(0, -18), Point2D(1, -21)) If `x` or `y` has a different name, then they can be specified, too, as a string (to match the name) or symbol: >>> Line(Eq(3*a + b, -18), x='a', y=b) Line2D(Point2D(0, -18), Point2D(1, -21)) c�� � �t|��dk�r3t|dttf���rt d|��� |sd}d}n,|�d� ��}|�d� ��}|rt d���|d� t� t��r� j� jz � � � fd�}||��}||��}t� ||��\}}}|rtd| |z f| |z ���S|rt| |z dft���St d td ��||hz z���t|��dkr�|d} t|��dkr |d} nd} t| t��r&| rt d ���t| j��} nOt| ��} t| ��} | � t| t��r| j| krt| ��} | d krt#| | fi|��S| d krt%| | fi|��Stj|| | fi|��SdS)Nrr�?�x�yz"expecting only x and y as keywordsc�J�� t|���S#t$r�cYSwxYwr`)rr4)r��equation�missings ��r+�find_or_missingz%Line.__new__.<locals>.find_or_missing�s<���#���8�,�,�,��!�#�#�#�"�N�N�N�#���s �� "�")�slopeznot found in equation: %s�xyz)If p1 is a LinearEntity, p2 must be None.r.�)r6rPrr r�popr4�lhs�rhsr#r�r�setr0r:rrMr��Line3Dr7)r9r�r<r�r�r�r��b�cr:r;r�r�r�s @@r+r7z Line.__new__�s����� �t�9�9��>�>�j��a��4��*�=�=�>�+�C��6�6�G�� -�������J�J�s�G�,�,���J�J�s�G�,�,��� G� �!E�F�F�F��A�w�H��(�B�'�'� 7�#�<�(�,�6�� #� #� #� #� #� #�  ���"�"�A����"�"�A�#�H�a��3�3�G�A�q�!�� 3��Q���1��I�a�R��T�2�2�2�2�� 1��a�R��T�1�I�R�0�0�0�0��8�C��I�I��A��<N�O�P�P� P��4�y�y�1�}�}��!�W���t�9�9�q�=�=��a��B�B��B��b�,�/�/�'��V�(�)T�U�U�U��b�e�*�*�C�C��r���B��b�'�'�C��~��B��)>�)>�~�2�CW�[^�C^�C^�"�2�Y�Y���!�8�8�!�"�b�3�3�F�3�3�3��A�X�X�!�"�b�3�3�F�3�3�3�#�+�C��R�B�B�6�B�B�B�+�}r-c�F�t|t��st||j���}t|t��r tj||j|j��St|t��r+tj|j|j|j|j��SdS)a2 Return True if `other` is on this Line, or False otherwise. Examples ======== >>> from sympy import Line,Point >>> p1, p2 = Point(0, 1), Point(3, 4) >>> l = Line(p1, p2) >>> l.contains(p1) True >>> l.contains((0, 1)) True >>> l.contains((0, 0)) False >>> a = (0, 0, 0) >>> b = (1, 1, 1) >>> c = (2, 2, 2) >>> l1 = Line(a, b) >>> l2 = Line(b, a) >>> l1 == l2 False >>> l1 in l2 True r�F)rPrrrM� is_collinearr:r;r0ros r+r?z Line.contains�s���6�%��0�0� =��%�T�%;�<�<�<�E� �e�U� #� #� ?��%�e�T�W�d�g�>�>� >� �e�\� *� *� L��%�d�g�t�w���%�(�K�K� K��ur-c���t|t��st||j���}|�|��r t jS|�|��jS)ap Finds the shortest distance between a line and a point. Raises ====== NotImplementedError is raised if `other` is not a Point Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(1, 1) >>> s = Line(p1, p2) >>> s.distance(Point(-1, 1)) sqrt(2) >>> s.distance((-1, 2)) 3*sqrt(2)/2 >>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1) >>> s = Line(p1, p2) >>> s.distance(Point(-1, 1, 1)) 2*sqrt(6)/3 >>> s.distance((-1, 1, 1)) 2*sqrt(6)/3 r�) rPrrrMr?r r�r�r�ros r+�distancez Line.distance�s]��6�%��0�0� =��%�T�%;�<�<�<�E� �=�=�� � � ��6�M��)�)�%�0�0�7�7r-c��t|t��sdStj|j|j|j|j��S��AReturns True if self and other are the same mathematical entitiesF)rPr�rr�r:r;ros r+r�z Line.equalss8���%��&�&� ��5��!�$�'�5�8�T�W�e�h�G�G�Gr-r[c�.�t|d���}|ddgS)a�The plot interval for the default geometric plot of line. Gives values that will produce a line that is +/- 5 units long (where a unit is the distance between the two points that define the line). Parameters ========== parameter : str, optional Default value is 't'. Returns ======= plot_interval : list (plot interval) [parameter, lower_bound, upper_bound] Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(5, 3) >>> l1 = Line(p1, p2) >>> l1.plot_interval() [t, -5, 5] Tr]�������r res r+� plot_intervalzLine.plot_interval s"��6 �I�D� )� )� )���2�q�z�r-Nr�) r5r�r�r�r7r?r�r�r�r�r-r+r�r�Usz������F�F�N7C�7C�7C�r!�!�!�F8�8�8�BH�H�H� �����r-r�c�R�eZdZdZd d�Zdd�Zd�Zd�Zd �Zdd �Z e d ���Z dS)r�aA Ray is a semi-line in the space with a source point and a direction. Parameters ========== p1 : Point The source of the Ray p2 : Point or radian value This point determines the direction in which the Ray propagates. If given as an angle it is interpreted in radians with the positive direction being ccw. Attributes ========== source See Also ======== sympy.geometry.line.Ray2D sympy.geometry.line.Ray3D sympy.geometry.point.Point sympy.geometry.line.Line Notes ===== `Ray` will automatically subclass to `Ray2D` or `Ray3D` based on the dimension of `p1`. Examples ======== >>> from sympy import Ray, Point, pi >>> r = Ray(Point(2, 3), Point(3, 5)) >>> r Ray2D(Point2D(2, 3), Point2D(3, 5)) >>> r.points (Point2D(2, 3), Point2D(3, 5)) >>> r.source Point2D(2, 3) >>> r.xdirection oo >>> r.ydirection oo >>> r.slope 2 >>> Ray(Point(0, 0), angle=pi/4).slope 1 Nc ��t|��}|�%tj|t|����\}}t|��}|dkrt||fi|��S|dkrt ||fi|��St j|||fi|��S�Nr.r�)rr3r6�Ray2D�Ray3Dr0r7�r9r:r;r<r�s r+r7z Ray.__new__ts��� �2�Y�Y�� �>��/��E�"�I�I�>�>�F�B���"�g�g�� �!�8�8���R�*�*�6�*�*� *� �A�X�X���R�*�*�6�*�*� *��#�C��R�:�:�6�:�:�:r-��?�#66cc99c� �t|j��t|j��f}d�|D��}d�|dd�|dd�����}d�d|z||��S) �'Returns SVG path element for the LinearEntity. 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{},{}�r�r�r��r)r�s r+r,zRay._svg.<locals>.<listcomp>��*��:�:�:�q�'�.�.���a�c�*�*�:�:�:r-� M {} L {}r� L rNz�<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="0.6" d="{1}" marker-start="url(#markerCircle)" marker-end="url(#markerArrow)"/>�@�rr:r;r��join�r@� scale_factor� fill_color�verts�coords�paths r+�_svgzRay._svg�s����4�7���Q�t�w�Z�Z�(��:�:�E�:�:�:���!�!�&��)�U�Z�Z��q�r�r� �-C�-C�D�D�� Q� �&��L��$� � 3� 3�  4r-c��t|t��st||j���}t|t��rgtj|j|j|��rEt|j|jz �||jz ��tj k��SdSt|t��rwtj|j|j|j|j��rJt|j|jz �|j|jz ��tj k��SdSt|t��r|j|vo|j|vSdS)a� Is other GeometryEntity contained in this Ray? Examples ======== >>> from sympy import Ray,Point,Segment >>> p1, p2 = Point(0, 0), Point(4, 4) >>> r = Ray(p1, p2) >>> r.contains(p1) True >>> r.contains((1, 1)) True >>> r.contains((1, 3)) False >>> s = Segment((1, 1), (2, 2)) >>> r.contains(s) True >>> s = Segment((1, 2), (2, 5)) >>> r.contains(s) False >>> r1 = Ray((2, 2), (3, 3)) >>> r.contains(r1) True >>> r1 = Ray((2, 2), (3, 5)) >>> r.contains(r1) False r�F) rPrrrMr�r:r;�boolrGr r�r�rtros r+r?z Ray.contains�s2��:�%��0�0� =��%�T�%;�<�<�<�E� �e�U� #� #� 9��!�$�'�4�7�E�:�:� P��T�W�t�w�.�3�3�E�D�G�O�D�D���N�O�O�O��5� ��s� #� #� 9��!�$�'�4�7�E�H�e�h�G�G� S��T�W�t�w�.�3�3�E�H�u�x�4G�H�H�1�6�Q�R�R�R��5� ��w� '� '� 9��8�t�#�8���D�(8� 8��ur-c�p�t|t��st||j���}|�|��r t jSt|j|j ��� |��}|�|��rt||z ��St||j z ��S)a� Finds the shortest distance between the ray and a point. Raises ====== NotImplementedError is raised if `other` is not a Point Examples ======== >>> from sympy import Point, Ray >>> p1, p2 = Point(0, 0), Point(1, 1) >>> s = Ray(p1, p2) >>> s.distance(Point(-1, -1)) sqrt(2) >>> s.distance((-1, 2)) 3*sqrt(2)/2 >>> p1, p2 = Point(0, 0, 0), Point(1, 1, 2) >>> s = Ray(p1, p2) >>> s Ray3D(Point3D(0, 0, 0), Point3D(1, 1, 2)) >>> s.distance(Point(-1, -1, 2)) 4*sqrt(3)/3 >>> s.distance((-1, -1, 2)) 4*sqrt(3)/3 r�) rPrrrMr?r r�r�r:r;r�rR�source)r@rA�projs r+r�z Ray.distance�s���:�%��0�0� =��%�T�%;�<�<�<�E� �=�=�� � � ��6�M��D�G�T�W�%�%�0�0��7�7�� �=�=�� � � ,��u�t�|�$�$� $��u�t�{�*�+�+� +r-c�b�t|t��sdS|j|jko|j|vSr�)rPr�rr;ros r+r�z Ray.equals�s4���%��%�%� ��5��{�e�l�*�?�u�x�4�/?�?r-r[c�.�t|d���}|ddgS)a\The plot interval for the default geometric plot of the Ray. Gives values that will produce a ray that is 10 units long (where a unit is the distance between the two points that define the ray). Parameters ========== parameter : str, optional Default value is 't'. Returns ======= plot_interval : list [parameter, lower_bound, upper_bound] Examples ======== >>> from sympy import Ray, pi >>> r = Ray((0, 0), angle=pi/4) >>> r.plot_interval() [t, 0, 10] Tr]r� r�res r+r�zRay.plot_interval�s"��4 �I�D� )� )� )���1�b�z�r-c��|jS)a�The point from which the ray emanates. See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Ray >>> p1, p2 = Point(0, 0), Point(4, 1) >>> r1 = Ray(p1, p2) >>> r1.source Point2D(0, 0) >>> p1, p2 = Point(0, 0, 0), Point(4, 1, 5) >>> r1 = Ray(p2, p1) >>> r1.source Point3D(4, 1, 5) )r:rLs r+rz Ray.sources ��.�w�r-r`�rrr�) r5r�r�r�r7rr?r�r�r�r�rr�r-r+r�r�?s�������3�3�h ;� ;� ;� ;�4�4�4�4�*.�.�.�`&,�&,�&,�P@�@�@� ����:����X���r-r�c�f�eZdZdZd�Zd�Zd�Zd�Zed���Z ed���Z d d �Z d d �Z dS)rta�A line segment in space. Parameters ========== p1 : Point p2 : Point Attributes ========== length : number or SymPy expression midpoint : Point See Also ======== sympy.geometry.line.Segment2D sympy.geometry.line.Segment3D sympy.geometry.point.Point sympy.geometry.line.Line Notes ===== If 2D or 3D points are used to define `Segment`, it will be automatically subclassed to `Segment2D` or `Segment3D`. Examples ======== >>> from sympy import Point, Segment >>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts Segment2D(Point2D(1, 0), Point2D(1, 1)) >>> s = Segment(Point(4, 3), Point(1, 1)) >>> s.points (Point2D(4, 3), Point2D(1, 1)) >>> s.slope 2/3 >>> s.length sqrt(13) >>> s.midpoint Point2D(5/2, 2) >>> Segment((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1)) >>> s = Segment(Point(4, 3, 9), Point(1, 1, 7)); s Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7)) >>> s.points (Point3D(4, 3, 9), Point3D(1, 1, 7)) >>> s.length sqrt(17) >>> s.midpoint Point3D(5/2, 2, 8) c ���tjt|��t|����\}}t|��}|dkrt||fi|��S|dkrt ||fi|��St j|||fi|��Sr)rr3r6� Segment2D� Segment3Dr0r7rs r+r7zSegment.__new__bs����+�E�"�I�I�u�R�y�y�A�A���B��"�g�g�� �!�8�8��R��.�.�v�.�.� .� �A�X�X��R��.�.�v�.�.� .��#�C��R�:�:�6�:�:�:r-c ��t|t��st||j���}t|t���rmtj||j|j���rLt|t��r�d|jz � d��}|dur3|jj |j z |jj |j z zdk}|dvr|S|dur3|jj |j z |jj |j z zdk}|dvr|S||jz ||jz }}|j|jz } tttt|��t|��zt|��z d������S#t $r$t#d�||�����wxYwt|t&��r|j|vo|j|vSdS)a; Is the other GeometryEntity contained within this Segment? Examples ======== >>> from sympy import Point, Segment >>> p1, p2 = Point(0, 1), Point(3, 4) >>> s = Segment(p1, p2) >>> s2 = Segment(p2, p1) >>> s.contains(s2) True >>> from sympy import Point3D, Segment3D >>> p1, p2 = Point3D(0, 1, 1), Point3D(3, 4, 5) >>> s = Segment3D(p1, p2) >>> s2 = Segment3D(p2, p1) >>> s.contains(s2) True >>> s.contains((p1 + p2)/2) True r�rrF)TFTzCannot determine if {} is in {})rPrrrMr�r:r;r'r�r�r�r�rr!r rRrQr$r�rt)r@rA�vert�isinr�r�rIs r+r?zSegment.containsls���,�%��0�0� =��%�T�%;�<�<�<�E� �e�U� #� #� ]��!�%���$�'�:�:� ]��d�I�.�.� (��d�j�L�0�0��3�3�D��u�}�}� $�� �E�G� 3�d�g�i�%�'�6I�J�a�O���=�0�0�#'�K��t�|�|� $�� �E�G� 3�d�g�i�%�'�6I�J�a�O���=�0�0�#'�K�����%�$�'�/�B���G�d�g�%��]� ���C��G�G�c�"�g�g�,=��A���,F��)J�)J� K� K�L�L�L�� �]�]�]�%�&G�&N�&N�u�VZ�&[�&[�\�\�\�]���� �e�W� %� %� 9��8�t�#�8���D�(8� 8��us �'AE>�>.F,c��t||j��oCtt|j����tt|j����kS)r�)rPr��listr r�ros r+r�zSegment.equals�sN���%���+�+�=�� �D�I� � �1 �1 �#'��� �(;�(;�#<�#<�1=� =r-c���t|t��st||j���}t|t��r�||jz }||jz }|j�|��dk}|j�|��dk}|r/|r-t|j|j��� |��S|r|st|��S|s|rt|��St���)a� Finds the shortest distance between a line segment and a point. Raises ====== NotImplementedError is raised if `other` is not a Point Examples ======== >>> from sympy import Point, Segment >>> p1, p2 = Point(0, 1), Point(3, 4) >>> s = Segment(p1, p2) >>> s.distance(Point(10, 15)) sqrt(170) >>> s.distance((0, 12)) sqrt(73) >>> from sympy import Point3D, Segment3D >>> p1, p2 = Point3D(0, 0, 3), Point3D(1, 1, 4) >>> s = Segment3D(p1, p2) >>> s.distance(Point3D(10, 15, 12)) sqrt(341) >>> s.distance((10, 15, 12)) sqrt(341) r�r) rPrrrMr:r;rFrGr�r�rRrn)r@rA�vp1�vp2�dot_prod_sign_1�dot_prod_sign_2s r+r�zSegment.distance�s���6�%��0�0� =��%�T�%;�<�<�<�E� �e�U� #� #� ��$�'�/�C��$�'�/�C�"�n�0�0��5�5��:�O�"�n�0�0��5�5��:�O�� >�?� >��D�G�T�W�-�-�6�6�u�=�=�=�� �� ��3�x�x��"� �� ��3�x�x��!�#�#�#r-c�@�tj|j|j��S)a�The length of the line segment. See Also ======== sympy.geometry.point.Point.distance Examples ======== >>> from sympy import Point, Segment >>> p1, p2 = Point(0, 0), Point(4, 3) >>> s1 = Segment(p1, p2) >>> s1.length 5 >>> from sympy import Point3D, Segment3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3) >>> s1 = Segment3D(p1, p2) >>> s1.length sqrt(34) )rr�r:r;rLs r+r�zSegment.length����0�~�d�g�t�w�/�/�/r-c�@�tj|j|j��S)a The midpoint of the line segment. See Also ======== sympy.geometry.point.Point.midpoint Examples ======== >>> from sympy import Point, Segment >>> p1, p2 = Point(0, 0), Point(4, 3) >>> s1 = Segment(p1, p2) >>> s1.midpoint Point2D(2, 3/2) >>> from sympy import Point3D, Segment3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3) >>> s1 = Segment3D(p1, p2) >>> s1.midpoint Point3D(2, 3/2, 3/2) )r�midpointr:r;rLs r+r6zSegment.midpoint�r4r-Nc��|�|j��}|�/t||j���}||vrt ||j��S|S)akThe perpendicular bisector of this segment. If no point is specified or the point specified is not on the bisector then the bisector is returned as a Line. Otherwise a Segment is returned that joins the point specified and the intersection of the bisector and the segment. Parameters ========== p : Point Returns ======= bisector : Line or Segment See Also ======== LinearEntity.perpendicular_segment Examples ======== >>> from sympy import Point, Segment >>> p1, p2, p3 = Point(0, 0), Point(6, 6), Point(5, 1) >>> s1 = Segment(p1, p2) >>> s1.perpendicular_bisector() Line2D(Point2D(3, 3), Point2D(-3, 9)) >>> s1.perpendicular_bisector(p3) Segment2D(Point2D(5, 1), Point2D(3, 3)) Nr�)r�r6rrMrtr�s r+�perpendicular_bisectorzSegment.perpendicular_bisectorsT��H � #� #�D�M� 2� 2�� �=��q�d�4�5�5�5�B��Q�w�w��r�4�=�1�1�1��r-r[c�.�t|d���}|ddgS)a:The plot interval for the default geometric plot of the Segment gives values that will produce the full segment in a plot. Parameters ========== parameter : str, optional Default value is 't'. Returns ======= plot_interval : list [parameter, lower_bound, upper_bound] Examples ======== >>> from sympy import Point, Segment >>> p1, p2 = Point(0, 0), Point(5, 3) >>> s1 = Segment(p1, p2) >>> s1.plot_interval() [t, 0, 1] Tr]rrr�res r+r�zSegment.plot_interval2s"��4 �I�D� )� )� )���1�a�y�r-r`r�) r5r�r�r�r7r?r�r�r�r�r6r8r�r�r-r+rtrt*s�������6�6�n;�;�;�5�5�5�n=�=�=� )$�)$�)$�V�0�0��X�0�2�0�0��X�0�2)�)�)�)�V�����r-rtc�D�eZdZdZed���Zd�Zed���ZdS)�LinearEntity2Da\A base class for all linear entities (line, ray and segment) in a 2-dimensional Euclidean space. Attributes ========== p1 p2 coefficients slope points Notes ===== This is an abstract class and is not meant to be instantiated. See Also ======== sympy.geometry.entity.GeometryEntity c��|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�� Sr�)r�r s r+r,z)LinearEntity2D.bounds.<locals>.<listcomp>o��� !� !� !�a�a�c� !� !� !r-c��g|] }|j�� Sr�)r�r s r+r,z)LinearEntity2D.bounds.<locals>.<listcomp>pr>r-)r��min�max)r@r�xs�yss r+�boundszLinearEntity2D.boundshsX�� � �� !� !�5� !� !� !�� !� !�5� !� !� !���B����R���#�b�'�'�3�r�7�7�3�3r-c�h�t||j���}t|||jjz��S)aCreate a new Line perpendicular to this linear entity which passes through the point `p`. Parameters ========== p : Point Returns ======= line : Line See Also ======== sympy.geometry.line.LinearEntity.is_perpendicular, perpendicular_segment Examples ======== >>> from sympy import Point, Line >>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2) >>> L = Line(p1, p2) >>> P = L.perpendicular_line(p3); P Line2D(Point2D(-2, 2), Point2D(-5, 4)) >>> L.is_perpendicular(P) True In 2D, the first point of the perpendicular line is the point through which was required to pass; the second point is arbitrarily chosen. To get a line that explicitly uses a point in the line, create a line from the perpendicular segment from the line to the point: >>> Line(L.perpendicular_segment(p3)) Line2D(Point2D(-2, 2), Point2D(4/13, 6/13)) r�)rrMr�rFr�r�s r+r�z!LinearEntity2D.perpendicular_liness6��N �!��/� 0� 0� 0���A�q�4�>�>�>�?�?�?r-c�x�|j|jz j\}}|dkr tjSt ||z ��S)a�The slope of this linear entity, or infinity if vertical. Returns ======= slope : number or SymPy expression See Also ======== coefficients Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(3, 5) >>> l1 = Line(p1, p2) >>> l1.slope 5/3 >>> p3 = Point(0, 4) >>> l2 = Line(p1, p3) >>> l2.slope oo r)r:r;r�r r�r!)r@r�r�s r+r�zLinearEntity2D.slope�s:��:�'�D�G�#�)���B� ��7�7��:� ���2����r-N)r5r�r�r�r�rDr�r�r�r-r+r;r;Psg��������.�4�4��X�4�+@�+@�+@�Z����X���r-r;c�@�eZdZdZd d�Zd d�Zed���Zd d �ZdS)r�a3An infinite line in space 2D. A line is declared with two distinct points or a point and slope as defined using keyword `slope`. Parameters ========== p1 : Point pt : Point slope : SymPy expression See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Line, Segment, Point >>> L = Line(Point(2,3), Point(3,5)) >>> L Line2D(Point2D(2, 3), Point2D(3, 5)) >>> L.points (Point2D(2, 3), Point2D(3, 5)) >>> L.equation() -2*x + y + 1 >>> L.coefficients (-2, 1, 1) Instantiate with keyword ``slope``: >>> Line(Point(0, 0), slope=0) Line2D(Point2D(0, 0), Point2D(1, 0)) Instantiate with another linear object >>> s = Segment((0, 0), (0, 1)) >>> Line(s).equation() x Nc ��t|t��r+|�td���tj|jddi�\}}nt|d���}|�L|�J t|d���}n�#t ttf$rttd�����wxYw|�F|�Dt|��}|j durd}d}nd}|}t|j |z|j |zd� ��}ntd ���tj|||fi|��S) Nz,When p1 is a LinearEntity, pt should be Noner�r.r�z� The 2nd argument was not a valid Point. If it was a slope, enter it with keyword "slope". Frr)�evaluatez,A 2nd Point or keyword "slope" must be used.)rPr0r4rr3r�rnrQr%r� is_finiter�r�r;r7)r9r:r�r�r<r;�dx�dys r+r7zLine2D.__new__�sH�� �b�,� '� '� "��~� �!O�P�P�P��/���@�a�@�@�F�B����r�q�!�!�!�B� �>�e�m� ��2�1�%�%�%����'��J�?� � � � ��-�"�"���� ���� � �2�:��E�N�N�E���%�'�'�����������r�t�b�y�"�$��)�e�<�<�<�B�B��K�L�L� L��%�c�2�r�<�<�V�<�<�<s �A)�)4Brrc� �t|j��t|j��f}d�|D��}d�|dd�|dd�����}d�d|z||��S) r c�N�g|]"}d�|j|j����#Sr r r s r+r,zLine2D._svg.<locals>.<listcomp>rr-rrrrNz�<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="0.6" d="{1}" marker-start="url(#markerReverseArrow)" marker-end="url(#markerArrow)"/>rrrs r+rz Line2D._svg s����4�7���Q�t�w�Z�Z�(��:�:�E�:�:�:���!�!�&��)�U�Z�Z��q�r�r� �-C�-C�D�D�� W� �&��L��$� � 3� 3�  4r-c���|j\}}|j|jkrtjtj|j fS|j|jkrtjtj|j fSt d�|jj|jjz |jj|jjz |jj|jjz|jj|jjzz fD����S)a�The coefficients (`a`, `b`, `c`) for `ax + by + c = 0`. See Also ======== sympy.geometry.line.Line2D.equation Examples ======== >>> from sympy import Point, Line >>> from sympy.abc import x, y >>> p1, p2 = Point(0, 0), Point(5, 3) >>> l = Line(p1, p2) >>> l.coefficients (-3, 5, 0) >>> p3 = Point(x, y) >>> l2 = Line(p1, p3) >>> l2.coefficients (-y, x, 0) c�,�g|]}t|����Sr�r r(s r+r,z'Line2D.coefficients.<locals>.<listcomp>@s0��C�C�C�a�h�q�k�k�C�C�Cr-) r�r�r �Oner�r��tupler:r;�r@r:r;s r+� coefficientszLine2D.coefficients"s���2����B� �4�2�4�<�<��E�1�6�B�D�5�)� )� �T�R�T�\�\��F�A�E�B�D�5�)� )��C�C��w�y�4�7�9�,��w�y�4�7�9�,��w�y����*�T�W�Y�t�w�y�-@�@�B�C�C�C�D�D� Dr-r�r�c���t|d���}t|d���}|j\}}|j|jkr ||jz S|j|jkr ||jz S|j\}}}||z||zz|zS)auThe equation of the line: ax + by + c. Parameters ========== x : str, optional The name to use for the x-axis, default value is 'x'. y : str, optional The name to use for the y-axis, default value is 'y'. Returns ======= equation : SymPy expression See Also ======== sympy.geometry.line.Line2D.coefficients Examples ======== >>> from sympy import Point, Line >>> p1, p2 = Point(1, 0), Point(5, 3) >>> l1 = Line(p1, p2) >>> l1.equation() -3*x + 4*y + 3 Tr])r r�r�r�rT)r@r�r�r:r;r�r�r�s r+r�zLine2D.equationEs���> �A�D� !� !� !�� �A�D� !� !� !������B� �4�2�4�<�<��r�t�8�O� �T�R�T�\�\��r�t�8�O��#���1�a���s�Q�q�S�y�1�}�r-�NNr$)r�r�) r5r�r�r�r7rr�rTr�r�r-r+r�r��sz������)�)�T=�=�=�=�>4�4�4�4�*� D� D��X� D�D(�(�(�(�(�(r-r�c�L�eZdZdZdd�Zed���Zed���Zd�ZdS)rap A Ray is a semi-line in the space with a source point and a direction. Parameters ========== p1 : Point The source of the Ray p2 : Point or radian value This point determines the direction in which the Ray propagates. If given as an angle it is interpreted in radians with the positive direction being ccw. Attributes ========== source xdirection ydirection See Also ======== sympy.geometry.point.Point, Line Examples ======== >>> from sympy import Point, pi, Ray >>> r = Ray(Point(2, 3), Point(3, 5)) >>> r Ray2D(Point2D(2, 3), Point2D(3, 5)) >>> r.points (Point2D(2, 3), Point2D(3, 5)) >>> r.source Point2D(2, 3) >>> r.xdirection oo >>> r.ydirection oo >>> r.slope 2 >>> Ray(Point(0, 0), angle=pi/4).slope 1 Nc ��t|d���}|�c|�a t|d���}n7#tttf$rtt d�����wxYw||krtd����n�|���|���t |��}t |��}d}|��|jr�|jdkr>|j dkr|tdd��z}ng|j dkr|tdd��z}nH|jdkr=|j dkr|tdd��z}n|j dkr|tdd��z}|�|tj z}n|dtj zz}|s�d|ztj z }td|k|dk��}td|ftdt|dzd��fd ��d f��} tt|�� |ftdt|d��fdt|d��ft|��d f��d f��} |t| | ��z}ntd ���t!j|||fi|��S) Nr.r�z� The 2nd argument was not a valid Point; if it was meant to be an angle it should be given with keyword "angle".z#A Ray requires two distinct points.rrr�rE)rTTz,A 2nd point or keyword "angle" must be used.)rrnrQr4r%rr� is_Rational�qr�r �Pirrr rr;r7) r9r:r��angler<r;r�r��leftr�r�s r+r7z Ray2D.__new__�sx�� �2�1� � � �� �>�e�m� 5��2�1�%�%�%����'��J�?� 5� 5� 5� ��-3�"4�"4�5�5�5� 5���� �R�x�x� �!F�G�G�G�� � �2�:��E�N�N�E��%� � �A��B��}��=� 3��s�a�x�x��3�!�8�8�!#�e�A�q�k�k�!1�B�B��S�A�X�X�!#�e�A�r�l�l�!2�B��������3�!�8�8�!#�e�A�q�k�k�!1�B�B��S�A�X�X�!#�e�B��l�l�!2�B��:����I�A���Q�q�t�V�$��� &��a�C���H���1�q�5�!�a�%�(�(���r�4�j�9�a��A��E�1���5F� �+R�+R�TX�*Y�Z�Z����A���w��o� �1�b��A�h�h�-�"�b�QR�TU�h�h��Z]�^_�Z`�Z`�bf�Yg�0h�0h�jn�/o�p�p���%��1�+�+�%����K�L�L� L��%�c�2�r�<�<�V�<�<�<s �)�4Ac��|jj|jjkr tjS|jj|jjkr tjStjS)aThe x direction of the ray. Positive infinity if the ray points in the positive x direction, negative infinity if the ray points in the negative x direction, or 0 if the ray is vertical. See Also ======== ydirection Examples ======== >>> from sympy import Point, Ray >>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, -1) >>> r1, r2 = Ray(p1, p2), Ray(p1, p3) >>> r1.xdirection oo >>> r2.xdirection 0 �r:r�r;r r�r��NegativeInfinityrLs r+� xdirectionzRay2D.xdirection��B��2 �7�9�t�w�y� � ��:� � �W�Y�$�'�)� #� #��6�M��%� %r-c��|jj|jjkr tjS|jj|jjkr tjStjS)aThe y direction of the ray. Positive infinity if the ray points in the positive y direction, negative infinity if the ray points in the negative y direction, or 0 if the ray is horizontal. See Also ======== xdirection Examples ======== >>> from sympy import Point, Ray >>> p1, p2, p3 = Point(0, 0), Point(-1, -1), Point(-1, 0) >>> r1, r2 = Ray(p1, p2), Ray(p1, p3) >>> r1.ydirection -oo >>> r2.ydirection 0 �r:r�r;r r�r�r`rLs r+� ydirectionzRay2D.ydirection�rbr-c��td�||fD����std���ttt |jj�����}ttt |jj�����}||zdkr4|dkrdtjz|zn|}|dkrdtjz|zn|}||z S)a�Return the angle by which r2 must be rotated so it faces the same direction as r1. Parameters ========== r1 : Ray2D r2 : Ray2D Returns ======= angle : angle in radians (ccw angle is positive) See Also ======== LinearEntity.angle_between Examples ======== >>> from sympy import Ray, pi >>> r1 = Ray((0, 0), (1, 0)) >>> r2 = r1.rotate(-pi/2) >>> angle = r1.closing_angle(r2); angle pi/2 >>> r2.rotate(angle).direction.unit == r1.direction.unit True >>> r2.closing_angle(r1) -pi/2 c3�@K�|]}t|t��V��dSr`)rPr)r)�rs r+rcz&Ray2D.closing_angle.<locals>.<genexpr>, s,����:�:�A�:�a��'�'�:�:�:�:�:�:r-z%Both arguments must be Ray2D objects.rr.) �allrQrr-�reversedrFr�r r[)�r1�r2�a1�a2s r+� closing_anglezRay2D.closing_angle s���B�:�:�"�b��:�:�:�:�:� E��C�D�D� D� �D��"�,�"3�4�4�5�5� 6�� �D��"�,�"3�4�4�5�5� 6�� �b�5�1�9�9� "�Q����1�4��"���B�B� "�Q����1�4��"���B�B��B�w�r-rV) r5r�r�r�r7r�rareror�r-r+rrpsy������-�-�\*=�*=�*=�*=�X�&�&��X�&�>�&�&��X�&�>,�,�,�,�,r-rc� �eZdZdZd�Zdd�ZdS)r'a�A line segment in 2D space. Parameters ========== p1 : Point p2 : Point Attributes ========== length : number or SymPy expression midpoint : Point See Also ======== sympy.geometry.point.Point, Line Examples ======== >>> from sympy import Point, Segment >>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts Segment2D(Point2D(1, 0), Point2D(1, 1)) >>> s = Segment(Point(4, 3), Point(1, 1)); s Segment2D(Point2D(4, 3), Point2D(1, 1)) >>> s.points (Point2D(4, 3), Point2D(1, 1)) >>> s.slope 2/3 >>> s.length sqrt(13) >>> s.midpoint Point2D(5/2, 2) c �~�t|d���}t|d���}||kr|Stj|||fi|��S)Nr.r�)rr;r7r8s r+r7zSegment2D.__new__` �Q�� �2�1� � � �� �2�1� � � �� ��8�8��I��%�c�2�r�<�<�V�<�<�<r-rrc� �t|j��t|j��f}d�|D��}d�|dd�|dd�����}d�d|z||��S) r c�N�g|]"}d�|j|j����#Sr r r s r+r,z"Segment2D._svg.<locals>.<listcomp>u rr-rrrrNza<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="0.6" d="{1}" />rrrs r+rzSegment2D._svgi s}���4�7���Q�t�w�Z�Z�(��:�:�E�:�:�:���!�!�&��)�U�Z�Z��q�r�r� �-C�-C�D�D�� :� �&��L��$� � 3� 3� 4r-Nr$)r5r�r�r�r7rr�r-r+r'r': sB������$�$�J=�=�=�4�4�4�4�4�4r-r'c�H�eZdZdZd�ZdZed���Zed���ZdS)�LinearEntity3Da An base class for all linear entities (line, ray and segment) in a 3-dimensional Euclidean space. Attributes ========== p1 p2 direction_ratio direction_cosine points Notes ===== This is a base class and is not meant to be instantiated. c ��t|d���}t|d���}||krtd|jz���tj|||fi|��S)Nr�r�r2)rr4r5rr7r8s r+r7zLinearEntity3D.__new__� sm�� �R�Q� � � �� �R�Q� � � �� ��8�8��8�3�<�G�I�I� I��%�c�2�r�<�<�V�<�<�<r-r�c�@�|j\}}|�|��S)a\The direction ratio of a given line in 3D. See Also ======== sympy.geometry.line.Line3D.equation Examples ======== >>> from sympy import Point3D, Line3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1) >>> l = Line3D(p1, p2) >>> l.direction_ratio [5, 3, 1] )r��direction_ratiorSs r+ryzLinearEntity3D.direction_ratio� s#��$����B��!�!�"�%�%�%r-c�@�|j\}}|�|��S)a�The normalized direction ratio of a given line in 3D. See Also ======== sympy.geometry.line.Line3D.equation Examples ======== >>> from sympy import Point3D, Line3D >>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1) >>> l = Line3D(p1, p2) >>> l.direction_cosine [sqrt(35)/7, 3*sqrt(35)/35, sqrt(35)/35] >>> sum(i**2 for i in _) 1 )r��direction_cosinerSs r+r{zLinearEntity3D.direction_cosine� s#��(����B��"�"�2�&�&�&r-N) r5r�r�r�r7rMr�ryr{r�r-r+rvrv} si��������"=�=�=��� �&�&��X�&�(�'�'��X�'�'�'r-rvc�2��eZdZdZd d�Zd d�Z�fd �Z�xZS) r�ahAn infinite 3D line in space. A line is declared with two distinct points or a point and direction_ratio as defined using keyword `direction_ratio`. Parameters ========== p1 : Point3D pt : Point3D direction_ratio : list See Also ======== sympy.geometry.point.Point3D sympy.geometry.line.Line sympy.geometry.line.Line2D Examples ======== >>> from sympy import Line3D, Point3D >>> L = Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1)) >>> L Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1)) >>> L.points (Point3D(2, 3, 4), Point3D(3, 5, 1)) Nr�c ��t|t��r|�td���|j\}}nt |d���}|�%t |��dkrt |d���}n`t |��dkr>|�<t |j|dz|j|dz|j |dz��}ntd���tj |||fi|��S)Nz)if p1 is a LinearEntity, pt must be None.r�r�rrr.z6A 2nd Point or keyword "direction_ratio" must be used.) rPrvr4r�rr6rr�r��zr7�r9r:r�ryr<s r+r7zLine3D.__new__� s��� �b�.� )� )� "��~� �!L�M�M�M��W�F�B����r�q�!�!�!�B� �>�c�/�2�2�a�7�7��r�q�!�!�!�B�B� �� !� !�Q� &� &�2�:������ 2�2�B�D�?�1�;M�4M����� 2�2�4�4�B�B��(�)�)� )��%�c�2�r�<�<�V�<�<�<r-r�r�r~c����d�|||dfD��\}}}�|j\}}|�|��\}}}|\} } } | �z|z| z | �z|z| z | �z|z| z g} t| ��D]M\} }|����r3t | | ���d�| �| ��n�Nt ��fd�| D���S)a.Return the equations that define the line in 3D. Parameters ========== x : str, optional The name to use for the x-axis, default value is 'x'. y : str, optional The name to use for the y-axis, default value is 'y'. z : str, optional The name to use for the z-axis, default value is 'z'. Returns ======= equation : Tuple of simultaneous equations Examples ======== >>> from sympy import Point3D, Line3D, solve >>> from sympy.abc import x, y, z >>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 0) >>> l1 = Line3D(p1, p2) >>> eq = l1.equation(x, y, z); eq (-3*x + 4*y + 3, z) >>> solve(eq.subs(z, 0), (x, y, z)) {x: 4*y/3 + 1} c�0�g|]}t|d�����S)Tr]r�r(s r+r,z#Line3D.equation.<locals>.<listcomp> s%��D�D�D��g�a�d�+�+�+�D�D�Dr-�krc�l��g|]0}|��������d��1S)r)r��as_numer_denom)r)r*r��kks ��r+r,z#Line3D.equation.<locals>.<listcomp>! s6���F�F�F�Q�q�v�v�a��}�}�3�3�5�5�a�8�F�F�Fr-)r�ry� enumerate�hasr"r�r)r@r�r�r~r:r;r�r��d3�x1�y1�z1�eqsr*�er�r�s @@r+r�zLine3D.equation� s����<E�D�a��A�s�^�D�D�D� ��1�a������B��'�'��+�+� ��B��� ��B���s�1�u�q�y�2�~��s�1�u�q�y�2�~��s�1�u�q�y�2�~�>���c�N�N� � �D�A�q��u�u�Q�x�x� ��3�q�6�1�%�%�a�(������ � � ��� ��F�F�F�F�F�#�F�F�F�G�Gr-c���ddlm}t|ttf��r! t |��}n#t $rYnwxYwt|t ��r!t���|��St|t��r�||kr tj S|� |��r&t���|j ��St|j��}t|j��}|�|��}||j |���}|j �|��St||��r|�|��S|�dt#|���d�}t%|���)a� Finds the shortest distance between a line and another object. Parameters ========== Point3D, Line3D, Plane, tuple, list Returns ======= distance Notes ===== This method accepts only 3D entities as it's parameter Tuples and lists are converted to Point3D and therefore must be of length 3, 2 or 1. NotImplementedError is raised if `other` is not an instance of one of the specified classes: Point3D, Line3D, or Plane. Examples ======== >>> from sympy.geometry import Line3D >>> l1 = Line3D((0, 0, 0), (0, 0, 1)) >>> l2 = Line3D((0, 1, 0), (1, 1, 1)) >>> l1.distance(l2) 1 The computed distance may be symbolic, too: >>> from sympy.abc import x, y >>> l1 = Line3D((0, 0, 0), (0, 0, 1)) >>> l2 = Line3D((0, x, 0), (y, x, 1)) >>> l1.distance(l2) Abs(x*y)/Abs(sqrt(y**2)) r)�Plane)r:� normal_vectorz has type z, which is unsupported)�planer�rPrRr-rr4�superr�r�r r�r�r:rry�cross�typern) r@rAr��self_direction�other_direction�normal�plane_through_self�msgr�s �r+r�zLine3D.distance# s����X !� � � � � � �e�e�T�]� +� +� � ��������� � � ��� ���� �e�W� %� %� +��7�7�#�#�E�*�*� *� �e�V� $� $� 9��u�}�}��v� �����&�&� 2��w�w�'�'���1�1�1�$�D�$8�9�9�N�$�U�%:�;�;�O�#�)�)�/�:�:�F�!&��$�'��!H�!H�!H� ��8�$�$�%7�8�8� 8� �e�U� #� #� (��>�>�$�'�'� '��E�E�$�u�+�+�E�E�E��!�#�&�&�&s�5� A�A�Nr�)r�r�r~)r5r�r�r�r7r�r�� __classcell__)r�s@r+r�r�� sx���������:=�=�=�=�$)H�)H�)H�)H�VH'�H'�H'�H'�H'�H'�H'�H'�H'r-r�c�\�eZdZdZdd�Zed���Zed���Zed���ZdS) ra# A Ray is a semi-line in the space with a source point and a direction. Parameters ========== p1 : Point3D The source of the Ray p2 : Point or a direction vector direction_ratio: Determines the direction in which the Ray propagates. Attributes ========== source xdirection ydirection zdirection See Also ======== sympy.geometry.point.Point3D, Line3D Examples ======== >>> from sympy import Point3D, Ray3D >>> r = Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0)) >>> r Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0)) >>> r.points (Point3D(2, 3, 4), Point3D(3, 5, 0)) >>> r.source Point3D(2, 3, 4) >>> r.xdirection oo >>> r.ydirection oo >>> r.direction_ratio [1, 2, -4] Nr�c ���t|t��r|�td���|j\}}nt |d���}|�%t |��dkrt |d���}nmt |��dkr>|�<t |j|dz|j|dz|j |dz��}nttd�����tj |||fi|��S)Nz(If p1 is a LinearEntity, pt must be Noner�r�rrr.zT A 2nd Point or keyword "direction_ratio" must be used. ) rPrvr4r�rr6rr�r�r~r%r7rs r+r7z Ray3D.__new__� s �� �b�.� )� )� "��~� �!K�L�L�L��W�F�B����r�q�!�!�!�B� �>�c�/�2�2�a�7�7��r�q�!�!�!�B�B� �� !� !�Q� &� &�2�:������ 2�2�B�D�?�1�;M�4M����� 2�2�4�4�B�B��Z�)����� ��%�c�2�r�<�<�V�<�<�<r-c��|jj|jjkr tjS|jj|jjkr tjStjS)a/The x direction of the ray. Positive infinity if the ray points in the positive x direction, negative infinity if the ray points in the negative x direction, or 0 if the ray is vertical. See Also ======== ydirection Examples ======== >>> from sympy import Point3D, Ray3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, -1, 0) >>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3) >>> r1.xdirection oo >>> r2.xdirection 0 r_rLs r+razRay3D.xdirection� rbr-c��|jj|jjkr tjS|jj|jjkr tjStjS)a5The y direction of the ray. Positive infinity if the ray points in the positive y direction, negative infinity if the ray points in the negative y direction, or 0 if the ray is horizontal. See Also ======== xdirection Examples ======== >>> from sympy import Point3D, Ray3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0) >>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3) >>> r1.ydirection -oo >>> r2.ydirection 0 rdrLs r+rezRay3D.ydirection� rbr-c��|jj|jjkr tjS|jj|jjkr tjStjS)aYThe z direction of the ray. Positive infinity if the ray points in the positive z direction, negative infinity if the ray points in the negative z direction, or 0 if the ray is horizontal. See Also ======== xdirection Examples ======== >>> from sympy import Point3D, Ray3D >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0) >>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3) >>> r1.ydirection -oo >>> r2.ydirection 0 >>> r2.zdirection 0 )r:r~r;r r�r�r`rLs r+� zdirectionzRay3D.zdirection� sB��6 �7�9�t�w�y� � ��:� � �W�Y�$�'�)� #� #��6�M��%� %r-r�) r5r�r�r�r7r�rarer�r�r-r+rrn s�������,�,�Z=�=�=�=�&�&�&��X�&�>�&�&��X�&�>�&�&��X�&�&�&r-rc��eZdZdZd�ZdS)r(a�A line segment in a 3D space. Parameters ========== p1 : Point3D p2 : Point3D Attributes ========== length : number or SymPy expression midpoint : Point3D See Also ======== sympy.geometry.point.Point3D, Line3D Examples ======== >>> from sympy import Point3D, Segment3D >>> Segment3D((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1)) >>> s = Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7)); s Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7)) >>> s.points (Point3D(4, 3, 9), Point3D(1, 1, 7)) >>> s.length sqrt(17) >>> s.midpoint Point3D(5/2, 2, 8) c �~�t|d���}t|d���}||kr|Stj|||fi|��S)Nr�r�)rrvr7r8s r+r7zSegment3D.__new__6 rrr-N)r5r�r�r�r7r�r-r+r(r( s.������"�"�F=�=�=�=�=r-r()Hr��sympy.core.containersr�sympy.core.evalfr�sympy.core.exprr�sympy.core.numbersrrr�sympy.core.relationalr �sympy.core.singletonr �sympy.core.sortingr �sympy.core.symbolr r r�sympy.core.sympifyr�$sympy.functions.elementary.piecewiser�(sympy.functions.elementary.trigonometricrrrr�entityrr� exceptionsrr�rr�utilrr�sympy.logic.boolalgr�sympy.matricesr�sympy.sets.setsr�sympy.simplify.simplifyr!�sympy.solvers.solversr"�sympy.solvers.solvesetr#�sympy.utilities.miscr$r%r��ranger[r�r0r�r�rtr;r�rr'rvr�rr(r�r-r+�<module>r�s|����&(�'�'�'�'�'������� � � � � � �2�2�2�2�2�2�2�2�2�2�$�$�$�$�$�$�"�"�"�"�"�"�&�&�&�&�&�&�C�C�C�C�C�C�C�C�C�C�&�&�&�&�&�&�:�:�:�:�:�:�R�R�R�R�R�R�R�R�R�R�R�R�/�/�/�/�/�/�/�/�%�%�%�%�%�%�!�!�!�!�!�!�!�!�$�$�$�$�$�$�$�$�#�#�#�#�#�#�!�!�!�!�!�!�(�(�(�(�(�(�,�,�,�,�,�,�'�'�'�'�'�'�0�0�0�0�0�0�8�8�8�8�8�8�8�8�� � � �/�.�U�U�1�X�X�.�.�.���1�`�`�`�`�`�;�`�`�`�F!g�g�g�g�g�<�g�g�g�Th�h�h�h�h�,�h�h�h�Vc�c�c�c�c�l�c�c�c�L p�p�p�p�p�\�p�p�p�fj�j�j�j�j�^�T�j�j�j�ZG�G�G�G�G�N�C�G�G�G�T@4�@4�@4�@4�@4���@4�@4�@4�FH'�H'�H'�H'�H'�\�H'�H'�H'�Vc'�c'�c'�c'�c'�^�T�c'�c'�c'�La&�a&�a&�a&�a&�N�C�a&�a&�a&�H+=�+=�+=�+=�+=���+=�+=�+=�+=�+=r-
Memory