K iPdZddlmZddlmZddlmZddlmZm Z ddl m Z ddl m Z ddlmZdd lmZmZmZdd lmZdd lmZdd lmZdd lmZmZmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'gdZ(e)dDcgc] }e d c}\Z*Z+e ddZ,GddeeZ-Gdde-eZ.ee.edZ!ee.edZdZ/d"d Z0d!Z1ycc}w)#aThe definition of the base geometrical entity with attributes common to all derived geometrical entities. Contains ======== GeometryEntity GeometricSet Notes ===== A GeometryEntity is any object that has special geometric properties. A GeometrySet is a superclass of any GeometryEntity that can also be viewed as a sympy.sets.Set. In particular, points are the only GeometryEntity not considered a Set. Rn is a GeometrySet representing n-dimensional Euclidean space. R2 and R3 are currently the only ambient spaces implemented. ) annotations)Basic)Tuple) EvalfMixinN)oo)Dummy)sympify)cossinataneye)dispatch)sstr)SetUnion FiniteSet)intersection_sets) union_sets)solve) func_name) is_sequence)Point2DPoint3DPoint Segment2DRay2DLine2D Segment3DLine3DRay3DSegmentRayLinePlaneTriangleRegularPolygonPolygonCircleEllipseCurveParabola entity_dummyT)realceZdZUdZdZded<dZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZd dZdZedZedZdZdZdZdZdZd!dZd"dZd#dZdZ y)$GeometryEntityzThe base class for all geometrical entities. This class does not represent any particular geometric entity, it only provides the implementation of some methods common to all subclasses. ztuple[str, ...] __slots__c|jj}|jj}||kD||kz }|syd}|jjD]#} tj |j}n|dk(r|Sd}|jjD]#} tj |j}n|dk(r|S||kD||kz S#t $rd}YwxYw#t $rd}YVwxYw)z#Comparison of two GeometryEntities.r) __class____name____mro__ordering_of_classesindex ValueError)selfothern1n2ci1clsi2s [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/geometry/entity.py__cmp__zGeometryEntity.__cmp__Qs ^^ $ $ __ % % "Wb ! >>)) C (..s||<  8H ??** C (..s||<  8HRBG$$    s$CC! CC! C/.C/cLt|t|ur||k(St)zPSubclasses should implement this method for anything more complex than equality.)typeNotImplementedErrorr=r>s rE __contains__zGeometryEntity.__contains__os% :e $5= !##c,t|jS)z=Returns a tuple that will be passed to __new__ on unpickling.)tupleargsr=s rE__getnewargs__zGeometryEntity.__getnewargs__usTYYrLc||k( S)z,Test inequality of two geometrical entities.r3r=os rE__ne__zGeometryEntity.__ne__ys19}rLcd}|Dcgc]}||rt|n t|}}tj|g|Scc}w)NcJt|dr |jryt|S)Nis_PointF)hasattrrXr)as rEis_seq_and_not_pointz4GeometryEntity.__new__..is_seq_and_not_pointsq*%!**q> !rL)rr r__new__)rCrOkwargsr[rZs rEr\zGeometryEntity.__new__}sM " OSS1!4q '!*DSS}}S(4((Ts"Ac$|j|S)z%Implementation of reverse add method.)__add__r=rZs rE__radd__zGeometryEntity.__radd__yyrLc$|j|S)z*Implementation of reverse division method.) __truediv__r`s rE __rtruediv__zGeometryEntity.__rtruediv__s}}T""rLcXt|jt|jzS)zQString representation of a GeometryEntity that can be evaluated by sympy.)rHr8reprrOrPs rE__repr__zGeometryEntity.__repr__s!Dz""T$))_44rLc$|j|S)z0Implementation of reverse multiplication method.)__mul__r`s rE__rmul__zGeometryEntity.__rmul__rbrLc$|j|S)z-Implementation of reverse subtraction method.)__sub__r`s rE__rsub__zGeometryEntity.__rsub__rbrLcXt|jt|jzS)z*String representation of a GeometryEntity.)rHr8rrOrPs rE__str__zGeometryEntity.__str__sDz""T$))_44rLcddlm}m}t|s t|r?t ||r||}||}n||}||}|j ||Sy)Nr)rr)sympy.geometry.pointrrr isinstance_subs)r=oldnewrrs rE _eval_subszGeometryEntity._eval_subssX7 s {3/$(clclCjCjJJsC( ( 0rLc |j}td|Dsyd}t t |\}}}}||k(r||k(r|dz |dz |dz|dzf\}}}}n.d}t ||z ||z g}||z} || z}|| z}|| z }|| z }||z } ||z } tt d| gdg} tt d| gdg} t | | dk(rd nt | | t | | z } |j|}d j||| | }d j||z}|j|| | }|d j||zS#ttf$rYywxYw#ttf$rYywxYw) z;SVG representation of a GeometryEntity suitable for IPythonNc3PK|]}|jxr |j ywN) is_number is_finite).0xs rE z,GeometryEntity._repr_svg_..s ?11;;.1;;.?s$&a g������?g?g������Y@i,��r���������?z {} {} {} {}zmatrix(1,0,0,-1,0,{})z{}) boundsrI TypeErrorallmaprmaxmin_svgformat)r=rsvg_topxminyminxmaxymaxexpand widest_part expand_amountdxdywidthheight scale_factorsvgview_box transforms rE _repr_svg_zGeometryEntity._repr_svg_s [[F ???("%QdD$ 4>> from sympy import RegularPolygon, Point, Polygon >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices) >>> t2 = Polygon(*RegularPolygon(Point(0, 0), 2, 3).vertices) >>> t2.encloses(t) True >>> t.encloses(t2) False rr)r#r$r%)r+)r)r(c3@K|]}j|ywrzencloses_point)r}r~r=s rErz*GeometryEntity.encloses..0s@!t**1-@Fc3@K|]}j|ywrzr)r}vr=s rErz*GeometryEntity.encloses..<sB!t**1-Br)rrrsympy.geometry.liner#r$r%sympy.geometry.ellipser+sympy.geometry.polygonr)r(rsrrpointscenterr~hradiusy intersectionverticesrI) r=rTrr#r$r%r+r)r(s ` rEencloseszGeometryEntity.enclosess4 /::2B a &&q) ) 7 #@qxx@@ @ C; ' 7 #&&qxx0)##ahhjj199,ahhjj9;)%%a(( )7 #!^,**1884 BqzzBB B!##rLc ||k(Srzr3rSs rEequalszGeometryEntity.equals?s qyrLct)a Returns a list of all of the intersections of self with o. Notes ===== An entity is not required to implement this method. If two different types of entities can intersect, the item with higher index in ordering_of_classes should implement intersections with anything having a lower index. See Also ======== sympy.geometry.util.intersection rrSs rErzGeometryEntity.intersectionBs &"##rLct)amIs this geometrical entity similar to another geometrical entity? Two entities are similar if a uniform scaling (enlarging or shrinking) of one of the entities will allow one to obtain the other. Notes ===== This method is not intended to be used directly but rather through the `are_similar` function found in util.py. An entity is not required to implement this method. If two different types of entities can be similar, it is only required that one of them be able to determine this. See Also ======== scale rrJs rE is_similarzGeometryEntity.is_similarWs *"##rLc  ddlm |}|} dd}|jjro|jdj }|s|j dS|j Dcgc]&}||jd||j z zf(}}n|jturo|jdj}|s|j dS|j Dcgc]&}||jd||jz zf(}}nt|ds,t fd|jDstd |zt|j}|j} | d | d z }  tt } | j| j!| |j dj!||j| } |j Dcgc]5}|| j#t|jt |j if7}}|j#t%|Scc}wcc}wcc}w) a Reflects an object across a line. Parameters ========== line: Line Examples ======== >>> from sympy import pi, sqrt, Line, RegularPolygon >>> l = Line((0, pi), slope=sqrt(2)) >>> pent = RegularPolygon((1, 2), 1, 5) >>> rpent = pent.reflect(l) >>> rpent RegularPolygon(Point2D(-2*sqrt(2)*pi/3 - 1/3 + 4*sqrt(2)/3, 2/3 + 2*sqrt(2)/3 + 2*pi/3), -1, 5, -atan(2*sqrt(2)) + 3*pi/5) >>> from sympy import pi, Line, Circle, Point >>> l = Line((0, pi), slope=1) >>> circ = Circle(Point(0, 0), 5) >>> rcirc = circ.reflect(l) >>> rcirc Circle(Point2D(-pi, pi), -5) rrr6)rr.)r~reflectc36K|]}t|ywrz)rs)r}argrs rErz)GeometryEntity.reflect..s5>/2JsE*5>sz)reflect undefined or non-Point args in %s)rrrslopeis_zerorOrscaleatoms translaterr~rYrrIr coefficientsrotatexreplacedict) r=lineglrTrprepsrZrAdxfrs @rErzGeometryEntity.reflectns6 /   !QK 77??q Awww}$=>WWU^LQ aQSSk 23LDL WW]q Awww}$=>WWU^LQ aQSSk 23LDL1i(5>67ff5>2>)?!CEEQWW AA2qt Aq!B#**A2q177"7&A,yy1y~ ABO1Q QQ$456ODOzz$t*%%)M MPs++I,+I8:INcg}|jD]E}t|tr"|j|j ||5|j|Gt ||S)a^Rotate ``angle`` radians counterclockwise about Point ``pt``. The default pt is the origin, Point(0, 0) See Also ======== scale, translate Examples ======== >>> from sympy import Point, RegularPolygon, Polygon, pi >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices) >>> t # vertex on x axis Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2)) >>> t.rotate(pi/2) # vertex on y axis now Triangle(Point2D(0, 1), Point2D(-sqrt(3)/2, -1/2), Point2D(sqrt(3)/2, -1/2)) )rOrsr2appendrrH)r=angleptnewargsrZs rErzGeometryEntity.rotates\* "A!^,qxxr23q!  " tDz7##rLc ddlm}|rK||d}|j| jj ||j|jSt ||jDcgc]}|j ||c}Scc}w)aScale the object by multiplying the x,y-coordinates by x and y. If pt is given, the scaling is done relative to that point; the object is shifted by -pt, scaled, and shifted by pt. See Also ======== rotate, translate Examples ======== >>> from sympy import RegularPolygon, Point, Polygon >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices) >>> t Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2)) >>> t.scale(2) Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)/2), Point2D(-1, -sqrt(3)/2)) >>> t.scale(2, 2) Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)), Point2D(-1, -sqrt(3))) rrr.dim)rrrrrOrrH)r=r~rrrrZs rErzGeometryEntity.scalesx0 / rq!BD>4>>RC::.44Q:DDbggN NtDz499=aAGGAqM=>>=s-B cg}|jD]E}t|tr"|j|j ||5|j|G|j |S)axShift the object by adding to the x,y-coordinates the values x and y. See Also ======== rotate, scale Examples ======== >>> from sympy import RegularPolygon, Point, Polygon >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices) >>> t Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2)) >>> t.translate(2) Triangle(Point2D(3, 0), Point2D(3/2, sqrt(3)/2), Point2D(3/2, -sqrt(3)/2)) >>> t.translate(2, 2) Triangle(Point2D(3, 2), Point2D(3/2, sqrt(3)/2 + 2), Point2D(3/2, 2 - sqrt(3)/2)) )rOrsr2rrfunc)r=r~rrrZs rErzGeometryEntity.translates\* "A!^,q{{1a01q!  " tyy'""rLc"ddlm}t|ts|||j}t||s t dt |jt|z td}|st dt|z||dtiS)aReturn the parameter corresponding to the given point. Evaluating an arbitrary point of the entity at this parameter value will return the given point. Examples ======== >>> from sympy import Line, Point >>> from sympy.abc import t >>> a = Point(0, 0) >>> b = Point(2, 2) >>> Line(a, b).parameter_value((1, 1), t) {t: 1/2} >>> Line(a, b).arbitrary_point(t).subs(_) Point2D(1, 1) rrrzother must be a pointT)rzGiven point is not on %s) rrrrsr2rr<rarbitrary_pointTr)r=r>trsols rEparameter_valuezGeometryEntity.parameter_values" /%0%T%;%;.&s;t((+;r)rsr is_FiniteSetrrKrJs` rE _containszGeometrySet._contains"s9 eS !e&8&8;U;; ;  ''rLN)r8rrrr4rr3rLrErrsI(rLrc|jrK|Dcgc]}|j|r|}}t|t|k(ryt|t |S|j|r|Sycc}w)zO Returns the union of self and o for use with sympy.sets.Set, if possible. N)rrlenrr)r=rTr other_pointss rErr*sh ~~#$>aDNN1,=> > | A &T9l344 ~~a  ?s A,A,c 8ddlm} |jrtfd|D}nj |}t|Dcgc]}t ||s|c}}|Dcgc]}t ||r|}}t||gzS#t $rYywxYwcc}wcc}w)zD Returns a sympy.sets.Set of intersection objects, if possible. rrc3FK|]}j|s|ywrz)contains)r}rr=s rErz$intersection_sets..GsAa a0@As!!N)rrrrrrrIrsr)r=rTrinterrr non_pointss` rErr<s +  >>A1ABE%%a(EEBqZ5-AB CF"?*Q*>!?J? :( **  C?s)/BBBB1B BBc0td}||d<||d<|S)z6Return the matrix to translate a 2-D point by x and y.)r.r)r.rr)r~rrvs rErrUs" QBBtHBtH IrLNctd}||d<||d<|r=ddlm}||d}t| j}t|j}||z|zS|S)zReturn the matrix to multiply a 2-D point's coordinates by x and y. If pt is given, the scaling is done relative to that point.rr)rrrrr.r)rrrrrrO)r~rrrrtr1tr2s rErr]sb QBBtHBtH . 21 2#$!2vcz IrLcjt|}tdt|z}||d<| |d<d|d<|S)aReturn the matrix to rotate a 2-D point about the origin by ``angle``. The angle is measured in radians. To Point a point about a point other then the origin, translate the Point, do the rotation, and translate it back: >>> from sympy.geometry.entity import rotate, translate >>> from sympy import Point, pi >>> rot_about_11 = translate(-1, -1)*rotate(pi/2)*translate(1, 1) >>> Point(1, 1).transform(rot_about_11) Point2D(1, 1) >>> Point(0, 0).transform(rot_about_11) Point2D(2, 0) r)rr)rrr)r.r.)r rr )thsrs rErrms@ BA QBBBtHrBtHBtH IrLrz)2r __future__rsympy.core.basicrsympy.core.containersrsympy.core.evalfrrsympy.core.numbersrsympy.core.symbolr sympy.core.sympifyr (sympy.functions.elementary.trigonometricr r r sympy.matricesrsympy.multipledispatchrsympy.printingr sympy.setsrrr sympy.sets.handlers.intersectionrsympy.sets.handlers.unionrsympy.solvers.solversrsympy.utilities.miscrsympy.utilities.iterablesrr:ranger~rrr2rrrr)rs0rErs*#"'*!#&CC+,,>0'*10(-Qx0!n01 .t$RUJRj (.# ( +s" +s++0  U1sC!