K ihNdZddlmZmZmZmZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZmZmZmZmZmZmZmZddlmZmZdd lmZdd lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)ddl*m+Z+ddl,Z,e-dDcgc] }ed c}\Z.Z/Z0Z1GddeZ2ycc}w)z.Geometrical Planes. Contains ======== Plane )DummyRationalSSymbol)_symbol)cossinacosasinsqrt)GeometryEntity)LineRaySegmentLine3D LinearEntityLinearEntity3DRay3D Segment3D)PointPoint3D)Matrix)cancel)solvelinsolve)uniq is_sequence) filldedent func_name Undecidable) prec_to_dpsN plane_dummyceZdZdZddZdZddZdZddZe dZ d Z d Z dd Z d Zd ZdZdZedZedZdZdZdZdZdZddZddZedZy)Planea A plane is a flat, two-dimensional surface. A plane is the two-dimensional analogue of a point (zero-dimensions), a line (one-dimension) and a solid (three-dimensions). A plane can generally be constructed by two types of inputs. They are: - three non-collinear points - a point and the plane's normal vector Attributes ========== p1 normal_vector Examples ======== >>> from sympy import Plane, Point3D >>> Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2)) Plane(Point3D(1, 1, 1), (-1, 2, -1)) >>> Plane((1, 1, 1), (2, 3, 4), (2, 2, 2)) Plane(Point3D(1, 1, 1), (-1, 2, -1)) >>> Plane(Point3D(1, 1, 1), normal_vector=(1,4,7)) Plane(Point3D(1, 1, 1), (1, 4, 7)) Nc zt|d}|r|rt|d}t|d}tj|||r td|j |}|j |}t t |jt |}n|jd|}|jdd}t|r(t|dk(r|rt|jn|}nttdtd|Dr td tj |||fi|S) Ndimz Enter three non-collinear points normal_vectorevaluateTz Either provide 3 3D points or a point with a normal vector expressed as a sequence of length 3c34K|]}|jywN)is_zero).0coords Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/geometry/plane.py z Plane.__new__..Lsz Plane.__new__9s RQ  qaBqaB$$RR0 !CDD""2&A""2&A!&)//&)"<=M ?A.Azz*d3H1~#a&A+3;   -I"JKK>> from sympy import Point3D, Line3D, Plane >>> a = Plane(Point3D(1, 2, 2), normal_vector=(1, 2, 3)) >>> b = Line3D(Point3D(1, 3, 4), Point3D(2, 2, 2)) >>> a.angle_between(b) -asin(sqrt(21)/6) c3&K|] }|dz ywNr^r0rfs r2r3z&Plane.angle_between..:!A:c3&K|] }|dz ywrjr^rls r2r3z&Plane.angle_between..s9!A9rnc3&K|] }|dz ywrjr^rls r2r3z&Plane.angle_between..rmrnc3&K|] }|dz ywrjr^rls r2r3z&Plane.angle_between..s7!A7rnN) rMrrr+r6dotr sumr r&r )rVrWrArBcrYrZs r2 angle_betweenzPlane.angle_betweends> a (t))*Aq(()AaAS:t'9'9::;AS9q'8'899:A1Q3= a t))*Aq'AaAS:t'9'9::;AS7q778A1Q3= rFc  |du}|rt|xsdd}n"t|xsdd}t|xsdd}|j\}}}|jj\}}} |jr>|jr2t j t jt jc n| |t jc tt|||fjt f\ |r fd fD\  fd fD\ t| t|zz t|zz| t|zzt|zz| t|zzt|zz} | St| |zz |zz| |zz|zz| |zz|zz} | S) a Returns an arbitrary point on the Plane. If given two parameters, the point ranges over the entire plane. If given 1 or no parameters, returns a point with one parameter which, when varying from 0 to 2*pi, moves the point in a circle of radius 1 about p1 of the Plane. Examples ======== >>> from sympy import Plane, Ray >>> from sympy.abc import u, v, t, r >>> p = Plane((1, 1, 1), normal_vector=(1, 0, 0)) >>> p.arbitrary_point(u, v) Point3D(1, u + 1, v + 1) >>> p.arbitrary_point(t) Point3D(1, cos(t) + 1, sin(t) + 1) While arbitrary values of u and v can move the point anywhere in the plane, the single-parameter point can be used to construct a ray whose arbitrary point can be located at angle t and radius r from p.p1: >>> Ray(p.p1, _).arbitrary_point(r) Point3D(1, r*cos(t) + 1, r*sin(t) + 1) Returns ======= Point3D NrOTrealuvc3XK|]!}|tdzdzzdzzz #ywrjr )r0wx1y1z1s r2r3z(Plane.arbitrary_point..0NA!DQQQ!677N'*c3XK|]!}|tdzdzzdzzz #ywrjr|)r0r}x2y2z2s r2r3z(Plane.arbitrary_point..rr)rr+r@r<r/rOneZeror7rr8rrr )rVryrzcirclerJrKrLrArBrtpr~rrrrrs @@@@@@r2rNzPlane.arbitrary_points@d St,ASt,ASt,A$$1a'',,1a 99JBBQJBB61a),2262r2,3GHI B N"b"NJBBN"b"NJBBBs1vI 3q6 1Bs1vI 3q6 1Bs1vI 3q6 13A BqD2a4RTBqD!bd(RT/JArFcjtt|}|D]*}t|trt d|j zt |dkryt|}|jd}|j|d}|gk(ry|d}|ddD]}|j|}|r|d|vsyy)a}Is a sequence of Planes concurrent? Two or more Planes are concurrent if their intersections are a common line. Parameters ========== planes: list Returns ======= Boolean Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(5, 0, 0), normal_vector=(1, -1, 1)) >>> b = Plane(Point3D(0, -2, 0), normal_vector=(3, 1, 1)) >>> c = Plane(Point3D(0, -1, 0), normal_vector=(5, -1, 9)) >>> Plane.are_concurrent(a, b) True >>> Plane.are_concurrent(a, b, c) False z'All objects should be Planes but got %srkFrr NT) listrrMr&r5r`r;r9 intersection)planesrffirstsollinels r2are_concurrentzPlane.are_concurrents<d6l# UAa' !JQVV!STT U v;?f 1   + "9q6DABZ !&&q)AaD,  !rFc^|j|gk7rtjSt|tt fr|j |j}}|jt||\}||vr|j|S|t ||vr|j|St|tdusJ|j|St|tr|n |j }t|jj}||j z j|}t|S)a@Distance between the plane and another geometric entity. Parameters ========== Point3D, LinearEntity3D, Plane. Returns ======= distance Notes ===== This method accepts only 3D entities as it's parameter, but if you want to calculate the distance between a 2D entity and a plane you should first convert to a 3D entity by projecting onto a desired plane and then proceed to calculate the distance. Examples ======== >>> from sympy import Point3D, Line3D, Plane >>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 1, 1)) >>> b = Point3D(1, 2, 3) >>> a.distance(b) sqrt(3) >>> c = Line3D(Point3D(2, 3, 1), Point3D(1, 2, 2)) >>> a.distance(c) 0 T)rrrrMrrr@rDrdistancerr+unitrrabs)rVrWrArBpir]rYs r2rzPlane.distancesD   Q 2 %66M a)U+ ,44qA##F1aL1CBQw}}R((iA&&}}Q''!!Y/4777}}Q''Aw'AQTT D&& ' , , [  a 1v rFct|tr<|j}|j}t||z j Sy)a Returns True if self and o are the same mathematical entities. Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(1, 2, 3), normal_vector=(1, 1, 1)) >>> b = Plane(Point3D(1, 2, 3), normal_vector=(2, 2, 2)) >>> c = Plane(Point3D(1, 2, 3), normal_vector=(-1, 4, 6)) >>> a.equals(a) True >>> a.equals(b) True >>> a.equals(c) False F)rMr&rIr is_constant)rVrWrArBs r2rQz Plane.equals6s>$ a  A A!A#;**, ,rFct|||fdDcgc]\}}|r|n t|dc}}\}}}t|||}|jj |}|j }t dt||DScc}}w)aqThe equation of the Plane. Examples ======== >>> from sympy import Point3D, Plane >>> a = Plane(Point3D(1, 1, 2), Point3D(2, 4, 7), Point3D(3, 5, 1)) >>> a.equation() -23*x + 11*y - 2*z + 16 >>> a = Plane(Point3D(1, 4, 2), normal_vector=(6, 6, 6)) >>> a.equation() 6*x + 6*y + 6*z - 42 xyzTrwc3,K|] \}}||zywr.r^r0rfjs r2r3z!Plane.equation..cs.DAqAaC.)rTrrr@r6r+rs) rVrJrKrLrfrrArBrts r2rIzPlane.equationPsADQ1Iu@UV11vad33V1a Aq!  GG # #A &   .C1I../ WsBct|ts t|d}t|tr ||vr|gSgSt|ttfrv|j |j }}t|tr t||}nRt|tr t||}n5t|tr t||}ntd|jz||vr|gSt|j!t"}|j t|j$}}t'||z j)|t"}|sgS|Dcgc]}|j*dus|}}t-|dkDr|Dcgc]}|j*s|}}t-|dk7r t/d|j1t"|d}||vrgS|gSt|t2r|j5|r|gS|j7|rgSt9t:d\} } } t=|j$gt=|j$g} }t?|jA| }|jC| | | } |jC| | | }t?tE| |g| | | d}| | | fD]}|j1|d}tt|| gSy cc}wcc}w) a  The intersection with other geometrical entity. Parameters ========== Point, Point3D, LinearEntity, LinearEntity3D, Plane Returns ======= List Examples ======== >>> from sympy import Point3D, Line3D, Plane >>> a = Plane(Point3D(1, 2, 3), normal_vector=(1, 1, 1)) >>> b = Point3D(1, 2, 3) >>> a.intersection(b) [Point3D(1, 2, 3)] >>> c = Line3D(Point3D(1, 4, 7), Point3D(2, 2, 2)) >>> a.intersection(c) [Point3D(2, 2, 2)] >>> d = Plane(Point3D(6, 0, 0), normal_vector=(2, -5, 3)) >>> e = Plane(Point3D(2, 0, 0), normal_vector=(3, 4, -3)) >>> d.intersection(e) [Line3D(Point3D(78/23, -24/23, 0), Point3D(147/23, 321/23, 23))] r(r)zunhandled linear entity: %sFr znot sure which point is realrrr6N)#rMrrrrr@rDrrrrrrr5r`rrNrOr+rrris_realr;r!rPr&rQ is_parallelmaprrrr8rIr)rVrWr@rDrAr]rtrfrrJrKrLrBrYrZresults r2rzPlane.intersectionfs<!^,aQA a Dys  a,7 8TT144B!W%b"%As#"bMAt$2rN !>!GHHDys A--a01););!AV[[A->F>wvBCC A7sK K 1KKct|trftjtt t |jtt t z jtt t  St|tr|vSt|trtfdDSt|trtdjddDSy)a8 Returns True if `o` is coplanar with self, else False. Examples ======== >>> from sympy import Plane >>> o = (0, 0, 0) >>> p = Plane(o, (1, 1, 1)) >>> p2 = Plane(o, (2, 2, 2)) >>> p == p2 False >>> p.is_coplanar(p2) True c3&K|]}|v ywr.r^)r0rfrVs r2r3z$Plane.is_coplanar..s/QqDy/sc3&K|] }|dk( yw)rNr^rls r2r3z$Plane.is_coplanar..s>!qAv>rnNrk) rMr&rrIrJrKrLhasrrr=rr+)rVrWs` r2 is_coplanarzPlane.is_coplanars a dmmAq!4QZZ1a5HHIMMaQRTUVV V a !9  > */$// / > *>t'9'9"1'=>> >+rFcNt|tr7|j}|j}t dt ||Ddk(St|t rNt|j}t|j}t|j|jSy)aIs the given geometric entity parallel to the plane? Parameters ========== LinearEntity3D or Plane Returns ======= Boolean Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6)) >>> b = Plane(Point3D(3,1,3), normal_vector=(4, 8, 12)) >>> a.is_parallel(b) True c3,K|] \}}||zywr.r^rs r2r3z$Plane.is_parallel..s1tq!qs1rrN) rMrr6r+rsrTr&rboolr8is_zero_matrixrVrrArBs r2rzPlane.is_parallels. a (!!A""A1s1ay11Q6 6 a q'At))*A 112 2 rFcRt|trGt|j}t|j}|j |j ryyt|tr@t|j}t|j}|j|dk(ryyy)aIs the given geometric entity perpendicualar to the given plane? Parameters ========== LinearEntity3D or Plane Returns ======= Boolean Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6)) >>> b = Plane(Point3D(2, 2, 2), normal_vector=(-1, 2, -1)) >>> a.is_perpendicular(b) True TFr) rMrrr6r+r8rr&rrrs r2is_perpendicularzPlane.is_perpendiculars. a (q(()At))*Awwqz(( 5 !q'At))*AuuQx1}rFc |jdS)agNormal vector of the given plane. Examples ======== >>> from sympy import Point3D, Plane >>> a = Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2)) >>> a.normal_vector (-1, 2, -1) >>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 4, 7)) >>> a.normal_vector (1, 4, 7) r r<rVs r2r+zPlane.normal_vectors yy|rFc |jdS)aThe only defining point of the plane. Others can be obtained from the arbitrary_point method. See Also ======== sympy.geometry.point.Point3D Examples ======== >>> from sympy import Point3D, Plane >>> a = Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2)) >>> a.p1 Point3D(1, 1, 1) rrrs r2r@zPlane.p1.s&yy|rFc4|j}t||S)a Plane parallel to the given plane and passing through the point pt. Parameters ========== pt: Point3D Returns ======= Plane Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(1, 4, 6), normal_vector=(2, 4, 6)) >>> a.parallel_plane(Point3D(2, 3, 5)) Plane(Point3D(2, 3, 5), (2, 4, 6)) )r+)r+r&rVrcrAs r2parallel_planezPlane.parallel_planeCs.   Rq))rFc4|j}t||S)aA line perpendicular to the given plane. Parameters ========== pt: Point3D Returns ======= Line3D Examples ======== >>> from sympy import Plane, Point3D >>> a = Plane(Point3D(1,4,6), normal_vector=(2, 4, 6)) >>> a.perpendicular_line(Point3D(9, 8, 7)) Line3D(Point3D(9, 8, 7), Point3D(11, 12, 13)) r)r+rrs r2perpendicular_linezPlane.perpendicular_line]s,   b!,,rFct|dkDr tdt|}t|dk(r|j|jt|dk(r@|j \}}}||cxk(rdk(rnnd}nd}|j|dt |z|Dcgc]}t|dc}\}}t||} t||j } | | vrC|j \}}}||cxk(rdk(rnnt ddd} n t ddd} | | vr| dz} n|t |j z} t||| Scc}w) aU Return a perpendicular passing through the given points. If the direction ratio between the points is the same as the Plane's normal vector then, to select from the infinite number of possible planes, a third point will be chosen on the z-axis (or the y-axis if the normal vector is already parallel to the z-axis). If less than two points are given they will be supplied as follows: if no point is given then pt1 will be self.p1; if a second point is not given it will be a point through pt1 on a line parallel to the z-axis (if the normal is not already the z-axis, otherwise on the line parallel to the y-axis). Parameters ========== pts: 0, 1 or 2 Point3D Returns ======= Plane Examples ======== >>> from sympy import Plane, Point3D >>> a, b = Point3D(0, 0, 0), Point3D(0, 1, 0) >>> Z = (0, 0, 1) >>> p = Plane(a, normal_vector=Z) >>> p.perpendicular_plane(a, b) Plane(Point3D(0, 0, 0), (1, 0, 0)) rkz&No more than 2 pts should be provided.rr )rr r)rrr r(r)r) r;r5rappendr@r+rrrr&) rVptsrJrKrLdirrfr@rDrr]rEs r2perpendicular_planezPlane.perpendicular_planevs;B s8a<EF F3i s8q= JJtww  s8q=((GAq!A{{ JJs1v - .+./a%q//B 2rN 2t'9'9 : 6((GAq!A{{Q1%Q1%Qwagt1122BRR  #0s Ect|ttfs td|j |j |j |j }}||k(r|St|ttfr t||St|ttfr t||St|ttfr t||Sy)a0Project the given line onto the plane through the normal plane containing the line. Parameters ========== LinearEntity or LinearEntity3D Returns ======= Point3D, Line3D, Ray3D or Segment3D Notes ===== For the interaction between 2D and 3D lines(segments, rays), you should convert the line to 3D by using this method. For example for finding the intersection between a 2D and a 3D line, convert the 2D line to a 3D line by projecting it on a required plane and then proceed to find the intersection between those lines. Examples ======== >>> from sympy import Plane, Line, Line3D, Point3D >>> a = Plane(Point3D(1, 1, 1), normal_vector=(1, 1, 1)) >>> b = Line(Point3D(1, 1), Point3D(2, 2)) >>> a.projection_line(b) Line3D(Point3D(4/3, 4/3, 1/3), Point3D(5/3, 5/3, -1/3)) >>> c = Line3D(Point3D(1, 1, 1), Point3D(2, 2, 2)) >>> a.projection_line(c) Point3D(1, 1, 1) zEnter a linear entity onlyN) rMrrNotImplementedError projectionr@rDrrrrrr)rVrrArBs r2projection_linezPlane.projection_linesH$~ >?%&BC Ctww')A1 6H dT6N +!Q<  dS%L )A;  dWi0 1Q? " 2rFc t|d}||vr|S|jt||t|jzdS)aProject the given point onto the plane along the plane normal. Parameters ========== Point or Point3D Returns ======= Point3D Examples ======== >>> from sympy import Plane, Point3D >>> A = Plane(Point3D(1, 1, 2), normal_vector=(1, 1, 1)) The projection is along the normal vector direction, not the z axis, so (1, 1) does not project to (1, 1, 2) on the plane A: >>> b = Point3D(1, 1) >>> A.projection(b) Point3D(5/3, 5/3, 2/3) >>> _ in A True But the point (1, 1, 2) projects to (1, 1) on the XY-plane: >>> XY = Plane((0, 0, 0), (0, 0, 1)) >>> XY.projection((1, 1, 2)) Point3D(1, 1, 0) r(r)r)rrrrr+)rVrcrvs r2rzPlane.projectionsJD21  :I  B9K9K1L,L!MNqQQrFc (|tj|}nt}tdt|j ddzdz t dt|j ddzdz i}|j tt j|S)a Returns a random point on the Plane. Returns ======= Point3D Examples ======== >>> from sympy import Plane >>> p = Plane((1, 0, 0), normal_vector=(0, 1, 0)) >>> r = p.random_point(seed=42) # seed value is optional >>> r.n(3) Point3D(2.29, 0, -1.35) The random point can be moved to lie on the circle of radius 1 centered on p1: >>> c = p.p1 + (r - p.p1).unit >>> c.distance(p.p1).equals(1) True rkrr )randomRandomrJrgaussrKrNrP)rVseedrngparamss r2 random_pointzPlane.random_points0  --%CC q#))Aq/**Q. q#))Aq/**Q.0##Aq)..v66rFc<t|tst||j}t|ts t d||j k(r|St|t rK|I|j||j z }|||j z jz }t||d}nQt|t r6t|t r&|j||}t||z ||fd}n t d|st dt|z|dS)a~Return the parameter(s) corresponding to the given point. Examples ======== >>> from sympy import pi, Plane >>> from sympy.abc import t, u, v >>> p = Plane((2, 0, 0), (0, 0, 1), (0, 1, 0)) By default, the parameter value returned defines a point that is a distance of 1 from the Plane's p1 value and in line with the given point: >>> on_circle = p.arbitrary_point(t).subs(t, pi/4) >>> on_circle.distance(p.p1) 1 >>> p.parameter_value(on_circle, t) {t: pi/4} Moving the point twice as far from p1 does not change the parameter value: >>> off_circle = p.p1 + (on_circle - p.p1)*2 >>> off_circle.distance(p.p1) 2 >>> p.parameter_value(off_circle, t) {t: pi/4} If the 2-value parameter is desired, supply the two parameter symbols and a replacement dictionary will be returned: >>> p.parameter_value(on_circle, u, v) {u: sqrt(10)/10, v: sqrt(10)/30} >>> p.parameter_value(off_circle, u, v) {u: sqrt(10)/5, v: sqrt(10)/15} r)zother must be a pointT)rSzexpecting 1 or 2 symbolszGiven point is not on %sr) rMrrambient_dimensionr5r@rrNrrr )rVotherryrzdeltaeqrrcs r2parameter_valuezPlane.parameter_value3sL%0%T%;%;r[rgrurN staticmethodrrrQrIrrrrpropertyr+r@rrrrrrrrr^rFr2r&r&s4H. @,!^7t..b4n40,QDh?23B&P"(*4-2@!D1#f%RN7B7r))rFr&)3r sympy.corerrrrsympy.core.symbolr(sympy.functions.elementary.trigonometricrr r r r entityrrrrrrrrrrpointrrsympy.matricesrsympy.polys.polytoolsr sympy.solversrrsympy.utilities.iterablesrrsympy.utilities.miscrr r!mpmath.libmp.libmpfr"rrangerJrKrLrOr&)rfs0r2rs~21%OO"%%%!!()7CC+ -2!H 5qeM" 5 1aP )NP )6s?B"