K i :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/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6m7Z7ddl8Z8e9dDcgc] }ed c}\Z:Z;Gdde Z<Gdde<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=ZEGd0d1eDe>ZFGd2d3eDe?ZGycc}w)4zLine-like geometrical entities. Contains ======== LinearEntity Line Ray Segment LinearEntity2D Line2D Ray2D Segment2D LinearEntity3D Line3D Ray3D Segment3D )Tuple)N)Expr)RationalooFloat)Eq)S)ordered)_symbolDummyuniquely_named_symbol)sympify) Piecewise) _pi_coeffacostanatan2)GeometryEntity GeometrySet) GeometryError)PointPoint3D)find intersection)And)Matrix) Intersectionsimplify)solve) linear_coeffs) Undecidable filldedentN line_dummyceZdZdZddZdZdZedZdZ dZ dd Z e d Z d Zed Zd ZdZdZdZedZedZedZdZdZdZedZdZddZdZy) 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||\}}||k(rtd|jzt |t |k7rtd|jzt 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__clsp1p2kwargss Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/geometry/line.pyr0zLinearEntity.__new__Ks++B3B 883<<GI I r7c"g Ds||SU U%%c2rBEJL Lr7c|j|k(ry||jz }|j}|j|dkDryy)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)r3 directiondot)r;r<rel_posds r6 _span_testzLinearEntity._span_testcs? 77e $''/ NN 55>A r7c,t|jS)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 )r/r3r;s r6ambient_dimensionzLinearEntity.ambient_dimensionqs>477|r7ct|tst|ts td|j|j}}t |j |t |t |zz S)aReturn 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) isinstancer) TypeErrorrArrBabsl1l2v1v2s r6 angle_betweenzLinearEntity.angle_betweensYt"l+Jr<4PAB Br||BBFF2JBB011r7ct|tst|ts td|j|j}}t t |j |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 rJ)rKr)rLrArrMrBrNs r6smallest_angle_betweenz#LinearEntity.smallest_angle_betweens\:"l+Jr<4PAB Br||BCr OSWSW_566r7ct|d}|jd|jDvr!tt d|jz|j |j |j z |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) Trealc34K|]}|jywN)name).0fs r6 z/LinearEntity.arbitrary_point..!s8aff8szx Symbol %s already appears in object and cannot be used as a parameter. )r r[ free_symbolsr-r%r3r4r; parameterts r6arbitrary_pointzLinearEntity.arbitrary_pointssV ID ) 668d&7&78 8Z)ff)  ww$''DGG+Q...r7cJt|}|jrt|dk(ryy)aIs 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_FiniteSetr/)lines common_pointss r6are_concurrentzLinearEntity.are_concurrent*s*^%e,  % %#m*<*Ar7ct)zSubclasses 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.)NotImplementedErrorr;r<s r6r:zLinearEntity.contains^s "##r7c4|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 )r4r3rGs r6rAzLinearEntity.directiones>ww  r7c8d}d}d}t|tst||j}|jr|j |r|gSgSt|t r'tj|j|j|j|j}tj|}|dk(rt|tr|gSt|tr|gSt|trt|tr |||St|trt|tr |||St|trt|tr |||St|trt|tr |||S|dk(rt|dd}t|dd}|jj|jrgSt!|j|j gj#} t!|j|jz gj#} | j%d| j'd \} } t)| dk7rt+d j-| | | d } |j| z|jz}t|trt|tr|gSt|ts|j |r|j |r|gS|j/t0s|j/t0sgSt3|j5t6|j5t8z t6t8d d }d}||t6|r||t8|r|gSgSgS|j;|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) [] cD|jj|jdkDr$|j|jdk\r|gS|gS|j|j}|dkrgS|dk(r |jgSt |j|jgSNr)rArBrEr3Segment)ray1ray2sts r6intersect_parallel_raysz:LinearEntity.intersection..intersect_parallel_rayss~~!!$..1A5"&!9Q!>vJTFJ__TWW-6I1W GG9$122r7c.|j|j|j|j}}|dkr|dkrgS|dk\r|dk\r|gS|dk\r!t|j|jgSt|j|jgSro)rEr3r4rp)raysegst1st2s r6"intersect_parallel_ray_and_segmentzELinearEntity.intersection..intersect_parallel_ray_and_segments~~cff-s~~cff/ECQw37 cQhu /00/00r7c|j|r|gS|j|r|gS|jj|jdkr t|j|j }|j |j dkr||}}|j |jdkrgSt|j |jgSro)r:rArBrpr4r3rE)seg1seg2s r6intersect_parallel_segmentsz>LinearEntity.intersection..intersect_parallel_segmentss}}T"v }}T"v ~~!!$..1A5tww0tww'!+!4dtww'!+ DGGTWW-. .r7dimrr&NTr z+Failed when solving Mx=b when M={} and b={})rr&)dictrct|tryt|tr |jSt|tr|jxrd|z jSt d)NTrzunexpected line type)rKLineRayis_nonnegativerpr-)pls r6okz%LinearEntity.intersection..ok'sV!!T*#!!S) ///!!W- //JQU4J4JJ$%;<>}}U#w | ,,,TWWdgguxxRC$$c*DqydD)!7NeT* 6MdC(Zs-C24??dC(Zw-G=dEJJdG,E31G=eTJJdG,E71K6tUCC3r7^3qr7^ <<222<<@IBLL2<<-89CCEBEEBEEM?+557"#a!3!8!8$!8!Gv;!#'(U(\(\]^`a(bcct $&LL$6$@!dD)j.E-..d+]]#45'89-..zz%(U1CI 4//2U5J5J15MMqt%%&( =beT?r"Q%'7-..  !!$''r7ct|tst|ts td|jj |jS)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 rJ)rKr)rLrArrOrPs r6 is_parallelzLinearEntity.is_parallel;s=Z"l+Jr<4PAB B||..r||<>> 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 rJ)rKr)rLr ZeroequalsrArBrs r6is_perpendicularzLinearEntity.is_perpendicularmsJV"l+Jr<4PAB Bvv}}R\\--bll;<>> 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 )rr3r4r:)r;r<rs r6 is_similarzLinearEntity.is_similars' $'' "zz%  r7c"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 InfinityrGs r6lengthzLinearEntity.lengthszzr7c |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) rargsrGs r6r3zLinearEntity.p1&yy|r7c |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) rrrGs r6r4zLinearEntity.p2rr7cbt||j}t|||jzS)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)rrHrrAr;rs r6 parallel_linezLinearEntity.parallel_lines-P !// 0Aq4>>)**r7ct||j}||vr||jjz}t ||j |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 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)rrHrAorthogonal_directionr projectionrs r6perpendicular_linezLinearEntity.perpendicular_linesHJ !// 0 9DNN777AAtq)**r7ct||j}||vr|S|j|}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)rrHrrrr3r4rpr;rrr4s r6perpendicular_segmentz"LinearEntity.perpendicular_segment=s\h !// 0 9H  # #A &4115q"~r7c2|j|jfS)aThe 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)) )r3r4rGs r6pointszLinearEntity.pointszs0!!r7cRt|tst|j}fd}t|tr||St|tr||j ||j }}||k(r|S|j||}t|}|jr|S|jrt|dk(r|\}|Sjj|jdkr!|j\}}|j||}|St!d|d)aProject 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)) rcxtj|jz jjzSrZ)rprojectr3rA)rr;s r6 proj_pointz+LinearEntity.projection..proj_points)==TWWdnn=G Gr7rrzDo not know how to project z onto )rKrrrHr)r3r4 __class__ris_emptyrer/rArBrfuncr)r;r<rr3r4 projectedas` r6rzLinearEntity.projectionst%0%T%;%;>> 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) rrzunhandled line type) randomRandomrcrbrKrrMgaussrprrjsubsr)r;seedrngptrs r6 random_pointzLinearEntity.random_points<  --%CC  ! !! $ dC CIIaO$A g & A d # !QA%&;< <wwq(1+&&r7ct|tstd|z||}}|jj|jjk7r~t|t r||}}t j|j|jd\}}t j|j|jd\}}t||}t||}|s td|d}t|tr|gS|jj} |jj} 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 %signore)on_morphzThe lines do not intersectr) rKr)rr3rHLine2Drr,r4rrrAunit) r;r<rOrP_r3r4pointrd1d2bis1bis2s r6 bisectorszLinearEntity.bisectorss-0%. @5 HI IuB 55 " "bee&=&= ="f%RB..ruubeehOEAr..ruubeehOEArb"BR$ <= =qB"d#v \\   \\  BR" %BR" %d|r7rZrb)r. __module__ __qualname____doc__r0r>rEpropertyrHrSrUrc staticmethodrhr:rArrrrrr3r4rrrrrrrr7r6r)r)2s0 = L @>2@!7F3/j11f$!!@s(j0=d.=`!"  (()+V(+T;z""2WEr+'Z8r7r)c0eZdZdZdZdZdZdZddZy) raAn 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(rt|dttfrt d| |sd}d}n$|j d }|j d }|r t d|d t tr j jz fd}||}||}t ||\}}}|rtd| |z f| |z S|rt| |z dftSt d td ||hz zt|dkDr|d} t|dkDr|d} nd} t| tr#| r t d t| j} nBt| } t| } | t| tr| j | k7r t| } | d k(r t#| | fi|S| d k(r t%| | fi|Stj&|| | fi|Sy)Nrr?xyz"expecting only x and y as keywordsc@ t|S#t$rcYSwxYwrZ)rr-)requationmissings r6find_or_missingz%Line.__new__..find_or_missings)#8,,!#"N#s  )slopeznot found in equation: %sxyz)If p1 is a LinearEntity, p2 must be None.r&)r/rKrr rpopr-lhsrhsr#rrsetr)r3rrHrLine3Dr0)r2rr5rrrrbcr3r4rrrs @@r6r0z Line.__new__s t9>ja4*=+C6GJJsG,JJsG, !EFFAwH(B'#<<(,,6 #  "A"A#Ha3GAq!Q1IaRT22aRT1IR008CIA2CWCW[^C^"2Y!8!"b3F33AX!"b3F33#++CRB6BB+r7cht|tst||j}t|tr+tj||j |j St|tr@tj|j |j |j |j Sy)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 rF)rKrrrH is_collinearr3r4r)rks r6r:z Line.containss{6%0%T%;%; > e\ *%%dggtww%((K Kr7ct|tst||j}|j |rt j S|j|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) rKrrrHr:r rrrrks r6distancez Line.distancesL6%0%T%;%;>> from sympy import Point, Line >>> p1, p2 = Point(0, 0), Point(5, 3) >>> l1 = Line(p1, p2) >>> l1.plot_interval() [t, -5, 5] TrWr r`s r6 plot_intervalzLine.plot_interval s6 ID )2qzr7Nr) r.rrrr0r:rrrrr7r6rrUs'FN7Cr!F8BH r7rcJeZdZdZd dZd dZdZdZdZd dZ e d Z y) raA 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|}|dk(r t||fi|S|dk(r t ||fi|St j |||fi|SNr&r)rr,r/Ray2DRay3Dr)r0r2r3r4r5rs r6r0z Ray.__new__ts 2Y >//E"I>FB"g !8R*6* * AXR*6* *##CR:6::r7c@t|jt|jf}|Dcgc](}dj|j|j *}}dj|ddj |dd}djd|z||Scc}w) '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". {},{} M {} L {}r L rNz@rr3r4rrrjoinr; scale_factor fill_colorvertsrcoordspaths r6_svgzRay._svgs477QtwwZ(49:q'..acc*::!!&)UZZqr -CD Q &L$ 3  4;-Bct|tst||j}t|tr{tj|j |j |rOt|j |j z j||j z tjk\Syt|trtj|j |j |j |j rYt|j |j z j|j |j z tjkDSyt|tr|j |vxr|j |vSy)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 rF) rKrrrHrr3r4boolrBr rrrprks r6r:z Ray.containss:%0%T%;%;>> 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) rKrrrHr:r rrr3r4rrMsource)r;r<projs r6rz Ray.distances:%0%T%;%;>> from sympy import Ray, pi >>> r = Ray((0, 0), angle=pi/4) >>> r.plot_interval() [t, 0, 10] TrWr rr`s r6rzRay.plot_intervals4 ID )1bzr7c|jS)aThe 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) )r3rGs r6rz Ray.sources .wwr7rZg?z#66cc99r) r.rrrr0rr:rrrrrrr7r6rr?s=3h ;4*.`&,P@ :r7rcXeZdZdZdZdZdZdZedZ edZ d d Z d d Z y) rpaA 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|}|dk(r t||fi|S|dk(r t ||fi|St j |||fi|Sr)rr,r/ Segment2D Segment3Dr)r0rs r6r0zSegment.__new__bsu++E"IuRyAB"g !8R.v. . AXR.v. .##CR:6::r7c t|tst||j}t|trytj||j |j rMt|trd|jz jd}|durP|j j|jz |j j|jz zdk}|dvr|S|durP|j j|jz |j j|jz zdk}|dvr|S||j z ||j z }}|j |j z } tttt|t|zt|z dSt|t&r|j |vxr|j |vSy#t $rt#dj%||wxYw)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 rrrF)TFTzCannot determine if {} is in {})rKrrrHrr3r4rrrrrrr!r rMrLr$rrp)r;r<vertisinrrrDs r6r:zSegment.containsls,%0%T%;%;G!!%Hct||jxr=tt|jtt|jk(S)r)rKrlistr rrks r6rzSegment.equalssC%+= DII 1 #' (;#<1= =r7ct|tst||j}t|tr||jz }||j z }|j j|dk\}|j j|dk}|r1|r/t|j|j j|S|r |s t|S|s |r t|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) rr) rKrrrHr3r4rArBrrrMrj)r;r<vp1vp2dot_prod_sign_1dot_prod_sign_2s r6rzSegment.distances6%0%T%;%;>> 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) )rrr3r4rGs r6rzSegment.length0~~dggtww//r7cVtj|j|jS)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) )rmidpointr3r4rGs r6r-zSegment.midpointr+r7Nc|j|j}|1t||j}||vrt ||jS|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)) r)rr-rrHrprs r6perpendicular_bisectorzSegment.perpendicular_bisectorsMH  # #DMM 2 =qd445BQwr4==11r7c&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] TrWrrrr`s r6rzSegment.plot_interval2s4 ID )1ayr7rZr) r.rrrr0r:rrrrr-r/rrr7r6rprp*sQ6n;5n= )$V002002)Vr7rpc6eZdZdZedZdZedZy)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}|Dcgc]}|j}}|Dcgc]}|j}}t|t|t |t |fScc}wcc}w)zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure. )rrrminmax)r;r rxsyss r6boundszLinearEntity2D.boundshsb   !aacc ! ! !aacc ! !BR#b'3r733" !s A)A.cvt||j}t|||jjzS)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)rrHrrArrs r6rz!LinearEntity2D.perpendicular_liness5N !// 0Aq4>>>>>??r7c|j|jz j\}}|dk(rtjSt ||z S)aThe 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)r3r4rr rr!)r;rrs r6rzLinearEntity2D.slopes?:''DGG#))B 7:: 2r7N)r.rrrrr8rrrr7r6r2r2Ps6.44+@Zr7r2c8eZdZdZddZddZedZd dZy) ra3An 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|tr0| tdtj|j ddi\}}n t|d}|| t|d}nZ|M|Kt|}|jdurd}d}nd}|}t|j|z|j|zd }n td tj|||fi|S#t ttf$rttdwxYw) Nz,When p1 is a LinearEntity, pt should be Nonerr&rz 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.)rKr)r-rr,rrjrLr%r is_finiterrr2r0)r2r3rrr5r4dxdys r6r0zLine2D.__new__s  b, '~ !OPP//@a@FBrq!B >em 21%  2:ENE%'rttby"$$)errr s r6rz Line2D._svg s477QtwwZ(49:q'..acc*::!!&)UZZqr -CD W &L$ 3  4;rc|j\}}|j|jk(r,tjtj|j fS|j |j k(r,tjtj|j fSt |jj |jj z |jj|jjz |jj|jj z|jj |jjzz fDcgc] }t|c}Scc}w)aThe 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) ) rrr Onerrtupler3r4r!)r;r3r4is r6 coefficientszLine2D.coefficients"s2B 44244<EE166BDD5) ) TTRTT\FFAEEBDD5) )wwyy47799,wwyy47799,wwyy*TWWYYtwwyy-@@BCahqkCD DCsE.c0t|d}t|d}|j\}}|j|jk(r||jz S|j|jk(r||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 TrW)r rrrrF)r;rrr3r4rrrs r6rzLine2D.equationEs> AD ! AD !B 44244<rtt8O TTRTT\rtt8O##1asQqSy1}r7NNr)rr) r.rrrr0rrrFrrr7r6rrs.)T=>4* D DD(r7rc>eZdZdZddZedZedZdZy)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 8t|d}|!| t|d}||k(rtd||t |}t |}d}||jr|jdk(r>|jdk(r|tddz}nk|jdk(r\|tddz}nL|jdk(r=|jdk(r|tddz}n|jdk(r|tddz}|*|tjz}n|dtjzz}|sd|ztjz }td|k|dk}td|ftdt|dzdfd d f} tt| |ftdt|dfdt|dft|d fd f} |t| | z}n td t!j"|||fi|S#tttf$rtt dwxYw) Nr&rz 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.rrrr@)rTTz,A 2nd point or keyword "angle" must be used.)rrjrLr-r%rr is_Rationalqrr Pirrr rr2r0) r2r3rangler5r4rrleftrrs r6r0z Ray2D.__new__s 21  >em 521% Rx !FGG  2:ENE% AB}==ssax33!8!#eAqk!1BSSAX!#eArl!2B33!8!#eAqk!1BSSAX!#eBl!2B:IAQqttV$aCH1q5!a%(r4j9aAE15F +RTX*YZAwo 1bAh-"bQRTUhZ]^_Z`bfYg0hjn/op%1+%KL L%%c2r>> 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 r3rr4r rrNegativeInfinityrGs r6 xdirectionzRay2D.xdirectionS2 7799twwyy ::  WWYY$'')) #66M%% %r7c|jj|jjkrtjS|jj|jjk(rtj Stj S)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 r3rr4r rrrRrGs r6 ydirectionzRay2D.ydirectionrTr7ctd||fDs tdttt |j j }ttt |j j }||zdkr:|dkrdtjz|zn|}|dkrdtjz|zn|}||z S)aReturn 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|tywrZ)rKr)r\rs r6r^z&Ray2D.closing_angle.., s:A:a':sz%Both arguments must be Ray2D objects.rr&) allrLrr$reversedrArr rM)r1r2a1a2s r6 closing_anglezRay2D.closing_angle sB:"b::CD D D",,"3"345 6 D",,"3"345 6 b519 "Q144"BB "Q144"BBBwr7rH) r.rrrr0rrSrWrarr7r6rrps;-\*=X&&>&&>,r7rceZdZdZdZddZy)raA 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 tt|d}t|d}||k(r|Stj|||fi|S)Nr&r)rr2r0r1s r6r0zSegment2D.__new__` @ 21  21  8I%%c2rrrr s r6rzSegment2D._svgi s477QtwwZ(49:q'..acc*::!!&)UZZqr -CD : &L$ 3 4;rNr)r.rrrr0rrr7r6rr: s$J=4r7rc:eZdZdZdZdZedZedZy)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}||k(rtd|jztj|||fi|S)Nrrr+)rr-r.rr0r1s r6r0zLinearEntity3D.__new__ sX RQ  RQ  883<<GI I%%c2r>> 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] )rdirection_ratior;r3r4s r6rjzLinearEntity3D.direction_ratio s"$B!!"%%r7cB|j\}}|j|S)aThe 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 )rdirection_cosinerks r6rmzLinearEntity3D.direction_cosine s"(B""2&&r7N) r.rrrr0rHrrjrmrr7r6rgrg} s:"= &&(''r7rgc2eZdZdZddZddZfdZxZS)rahAn 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)) c t|tr| td|j\}}n t |d}|t |dk(rt |d}nYt |dk(r@|>t |j|dz|j|dz|j|dz}n tdtj|||fi|S)Nz)if p1 is a LinearEntity, pt must be None.rrrrr&z6A 2nd Point or keyword "direction_ratio" must be used.) rKrgr-rrr/rrrzr0r2r3rrjr5s r6r0zLine3D.__new__ s b. )~ !LMMWWFBrq!B >c/2a7rq!B  !Q &2: 22BDD?1;M4M 224B() )%%c2r>> 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} kTrWr) r rrj enumeratehasr"rrras_numer_denom)r;rrrprErsr3r4rrd3x1y1z1eqsekks r6rzLine3D.equation s <78As^Dgad+D 1aB''+ B Bs1uqy2~s1uqy2~s1uqy2~>cN DAquuQx1a[^    #FQqvva}335a8FGGEGs C/*C4cddlm}t|ttfr t |}t|t rt|!|St|tr||k(rtjS|j|rt|!|jSt|j}t|j}|j!|}||j|}|jj|St||r|j|S|dt#|d}t%|#t $rYwxYw)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)r3 normal_vectorz has type z, which is unsupported)planerrKrDr$rr-superrrr rrr3rrjcrosstyperj) r;r<rself_directionother_directionnormalplane_through_selfmsgrs r6rzLine3D.distance# s%X ! eeT] +  eW %7#E* * eV $u}vv &w'11$D$8$89N$U%:%:;O#))/:F!&$''!H 88$$%78 8 eU #>>$' 'z$u+.DE!#&&/  s D;; EENr)rrrp)r.rrrr0rr __classcell__)rs@r6rr s :=$)HVH'H'r7rcHeZdZdZddZedZedZedZy)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] Nc t|tr| td|j\}}n t |d}|t |dk(rt |d}nbt |dk(r@|>t |j|dz|j|dz|j|dz}nttdtj|||fi|S)Nz(If p1 is a LinearEntity, pt must be Nonerrrrr&zT A 2nd Point or keyword "direction_ratio" must be used. ) rKrgr-rrr/rrrrpr%r0rqs r6r0z Ray3D.__new__ s b. )~ !KLLWWFBrq!B >c/2a7rq!B  !Q &2: 22BDD?1;M4M 224BZ) %%c2r>> 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 rQrGs r6rSzRay3D.xdirection rTr7c|jj|jjkrtjS|jj|jjk(rtj Stj S)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 rVrGs r6rWzRay3D.ydirection rTr7c|jj|jjkrtjS|jj|jjk(rtj Stj S)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 )r3rpr4r rrrRrGs r6 zdirectionzRay3D.zdirection sS6 7799twwyy ::  WWYY$'')) #66M%% %r7r) r.rrrr0rrSrWrrr7r6rrn sI,Z=&&&>&&>&&r7rceZdZdZdZy)raA 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 tt|d}t|d}||k(r|Stj|||fi|S)Nrr)rrgr0r1s r6r0zSegment3D.__new__6 rdr7N)r.rrrr0rr7r6rr s "F=r7r)Hrsympy.core.containersrsympy.core.evalfrsympy.core.exprrsympy.core.numbersrrrsympy.core.relationalr sympy.core.singletonr sympy.core.sortingr sympy.core.symbolr r rsympy.core.sympifyr$sympy.functions.elementary.piecewiser(sympy.functions.elementary.trigonometricrrrrentityrr exceptionsrrrrutilrrsympy.logic.boolalgrsympy.matricesrsympy.sets.setsrsympy.simplify.simplifyr!sympy.solvers.solversr"sympy.solvers.solvesetr#sympy.utilities.miscr$r%rrangerbrr)rrrpr2rrrrgrrr)rEs0r6rs?&( 22$"&CC&:RR/%!$#!(,'08&+1X.l.1`;`F!g<gTh,hVclcL p\pfj^TjZGNCGT@4@4FH'\H'Vc'^Tc'La&NCa&H+=+=GW/s+E