K idZddlmZddlmZddlmZmZmZddl m Z ddl m Z ddl mZddlmZmZdd lmZdd lmZmZmZdd lmZdd lmZdd lmZmZddlm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:ddl;mm?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFddlGZGeHdDcgc] }edd c}\ZIZJGd!d"e&ZKGd#d$eKZLdd%lMmNZNmOZOycc}w)&z?Elliptical geometrical entities. Contains * Ellipse * Circle )Expr)Eq)Spisympify)N)global_parameters) fuzzy_bool)Rationaloo)ordered)Dummyuniquely_named_symbol_symbol)simplify)trigsimp)sqrtMax)cossin) elliptic_e)GeometryEntity GeometrySet) GeometryError)LineSegmentRay2D Segment2DLine2DLinearEntity3D)PointPoint2DPoint3D)idifffind) DomainErrorPolyPolynomialError) _not_a_coeff_nsort)solve) linear_coeffs) filldedent func_name) prec_to_dpsN ellipse_dummyTrealceZdZdZdZdZfdZ d(dZd)dZe dZ e dZ d*d Z e d Z e d Ze d Ze d Ze dZdZd+dZd,dZe dZe dZe dZdZdZe dZe dZd-dZe dZe dZdZdZ d*dZ!d-dZ"d Z#d.fd! Z$d/d"Z%d#Z&e d$Z'd-d%Z(d&Z)d-d'Z*xZ+S)0Ellipsea"An elliptical GeometryEntity. Parameters ========== center : Point, optional Default value is Point(0, 0) hradius : number or SymPy expression, optional vradius : number or SymPy expression, optional eccentricity : number or SymPy expression, optional Two of `hradius`, `vradius` and `eccentricity` must be supplied to create an Ellipse. The third is derived from the two supplied. Attributes ========== center hradius vradius area circumference eccentricity periapsis apoapsis focus_distance foci Raises ====== GeometryError When `hradius`, `vradius` and `eccentricity` are incorrectly supplied as parameters. TypeError When `center` is not a Point. See Also ======== Circle Notes ----- Constructed from a center and two radii, the first being the horizontal radius (along the x-axis) and the second being the vertical radius (along the y-axis). When symbolic value for hradius and vradius are used, any calculation that refers to the foci or the major or minor axis will assume that the ellipse has its major radius on the x-axis. If this is not true then a manual rotation is necessary. Examples ======== >>> from sympy import Ellipse, Point, Rational >>> e1 = Ellipse(Point(0, 0), 5, 1) >>> e1.hradius, e1.vradius (5, 1) >>> e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5)) >>> e2 Ellipse(Point2D(3, 1), 3, 9/5) c(t|trm|jttj t|jt|ji}t t|tjuSt|tr||k(Sy)NF) isinstancer"equationxysubsrrrZeror6)selforess \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/geometry/ellipse.py __contains__zEllipse.__contains__ksg a --1%**AqssAqss+;r?s rA__eq__zEllipse.__eq__ssS!W%F4;;!((+B,E+/<<199+D,E+/<<199+D FrCc t|SN)super__hash__)r> __class__s rArMzEllipse.__hash__ysw!!rCc t|}t|}| tdd}n5t|dk7rtdj |t|d}tt t d|||fdk7rttd|Ot|}|jr td||td|dzz z }n||td|dzz z}||k(r t||fi|Stj||fvr8tt|d|z |d|z t|d|z|d|zS|jd us|jd ur td t!j"||||fi|S) Nrr1z2The center of "{}" must be a two dimensional pointdimc |duSrK)r:s rAz!Ellipse.__new__..s Qd]rCzt Exactly two arguments of "hradius", "vradius", and "eccentricity" must not be None.z8Eccentricity of ellipse/circle should lie between [0, 1)rFz;Invalid value encountered when computing hradius / vradius.)rr"len ValueErrorformatlistfilterr. is_negativerrCirclerr=ris_realr__new__)clsrErFrG eccentricitykwargss rAr]zEllipse.__new__|s'"'" >1a[F6{a !U!\!\]`!abb6q)F tF2Wg|4TUV W[\ \Z)456 6  #"<0L''#$^__!D\1_)<$==!D\1_)<$== g &'4V4 4 66gw' '5W!4fQi'6IJERXYZR[^eRegmnogpszgzL{| | ??e #w%'? ]^ ^%%c67GNvNNrCct|j}t|jt|j}}dj d|z||j |j ||S)a%Returns SVG ellipse element for the Ellipse. 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". zkg@)rrErFrGrWr:r;)r> scale_factor fill_colorchvs rA_svgz Ellipse._svgsW dkkN$,,1 U &l"JQSS!Q ? @rCcy)Nr1rSr>s rAambient_dimensionzEllipse.ambient_dimensionsrCc:|jd|jzzS)aThe apoapsis of the ellipse. The greatest distance between the focus and the contour. Returns ======= apoapsis : number See Also ======== periapsis : Returns shortest distance between foci and contour Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.apoapsis 2*sqrt(2) + 3 rmajorr_ris rAapoapsiszEllipse.apoapsis4zzQ!2!2233rCcht|d}|jd|jDvr!tt d|jzt |j j|jt|zz|j j|jt|zzS)aXA parameterized point on the ellipse. Parameters ========== parameter : str, optional Default value is 't'. Returns ======= arbitrary_point : Point Raises ====== ValueError When `parameter` already appears in the functions. See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Ellipse >>> e1 = Ellipse(Point(0, 0), 3, 2) >>> e1.arbitrary_point() Point2D(3*cos(t), 2*sin(t)) Tr3c34K|]}|jywrK)name).0fs rA z*Ellipse.arbitrary_point..s8aff8szFSymbol %s already appears in object and cannot be used as a parameter.) rrr free_symbolsrVr.r"rEr:rFrr;rGrr> parameterts rAarbitrary_pointzEllipse.arbitrary_pointsD ID ) 668d&7&78 8Z)MOPvv)VWX XT[[]]T\\#a&%88[[]]T\\#a&%88: :rCchttj|jz|jzS)a The area of the ellipse. Returns ======= area : number Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.area 3*pi )rrPirFrGris rAareaz Ellipse.areas%&t||+dll:;;rCc|j|j}}|jj|z |jj|z |jj|z|jj|zfS)zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure. )rFrGrEr:r;)r>rerfs rAboundszEllipse.boundssY||T\\1 !4;;==1#4dkkmma6GYZIZ[[rCc |jdS)abThe center of the ellipse. Returns ======= center : number See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.center Point2D(0, 0) rargsris rArEzEllipse.center0yy|rCc|jdk(rd|jzS|jdk(rdtz|jzSd|jzt |jdzzS)zThe circumference of the ellipse. Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.circumference 12*elliptic_e(8/9) rrr1)r_rmrrFrris rA circumferencezEllipse.circumference7sd    !TZZ<    ! #R4 $ $TZZ< 4+<+>> from sympy import Point, Ellipse, sqrt >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, sqrt(2)) >>> e1.eccentricity sqrt(7)/3 )focus_distancermris rAr_zEllipse.eccentricityNs&""TZZ//rCc^t|d}||vryt|jdk(rB|jDcgc]}|j|c}\}}d|jz||zz }n(|j |j j|z }t|jScc}w)a Return True if p is enclosed by (is inside of) self. Notes ----- Being on the border of self is considered False. Parameters ========== p : Point Returns ======= encloses_point : True, False or None See Also ======== sympy.geometry.point.Point Examples ======== >>> from sympy import Ellipse, S >>> from sympy.abc import t >>> e = Ellipse((0, 0), 3, 2) >>> e.encloses_point((0, 0)) True >>> e.encloses_point(e.arbitrary_point(t).subs(t, S.Half)) False >>> e.encloses_point((4, 0)) False r1rPF) r"rUfocidistancermradiusrEr is_positive)r>prth1h2tests rAencloses_pointzEllipse.encloses_pointcsJ !O 9 tyy>Q  .2YY7ajjm7FBTZZ<27+D;;!5!5a!88D$**++ 8sB*ct|d}t|d}||jjz }||jjz }|P|||zz dz}||z|zdz}d|dzz}||jdzz} ||j dzz} || z || z zdz S||j z dz} ||jz dz} | | zdz S)a Returns the equation of an ellipse aligned with the x and y axes; when slope is given, the equation returned corresponds to an ellipse with a major axis having that slope. Parameters ========== x : str, optional Label for the x-axis. Default value is 'x'. y : str, optional Label for the y-axis. Default value is 'y'. _slope : Expr, optional The slope of the major axis. Ignored when 'None'. Returns ======= equation : SymPy expression See Also ======== arbitrary_point : Returns parameterized point on ellipse Examples ======== >>> from sympy import Point, Ellipse, pi >>> from sympy.abc import x, y >>> e1 = Ellipse(Point(1, 0), 3, 2) >>> eq1 = e1.equation(x, y); eq1 y**2/4 + (x/3 - 1/3)**2 - 1 >>> eq2 = e1.equation(x, y, _slope=1); eq2 (-x + y + 1)**2/8 + (x + y - 1)**2/18 - 1 A point on e1 satisfies eq1. Let's use one on the x-axis: >>> p1 = e1.center + Point(e1.major, 0) >>> assert eq1.subs(x, p1.x).subs(y, p1.y) == 0 When rotated the same as the rotated ellipse, about the center point of the ellipse, it will satisfy the rotated ellipse's equation, too: >>> r1 = p1.rotate(pi/4, e1.center) >>> assert eq2.subs(x, r1.x).subs(y, r1.y) == 0 References ========== .. [1] https://math.stackexchange.com/questions/108270/what-is-the-equation-of-an-ellipse-that-is-not-aligned-with-the-axis .. [2] https://en.wikipedia.org/wiki/Ellipse#Shifted_ellipse Tr3r1r)rrEr:r;rmminorrFrG) r>r:r;_slopedxdyLlrebat1t2s rAr9zEllipse.equationsr AD ! AD !      fRi!#AR!#AFAI A$**a-A$**a-AQ319q= T\\/A%BT\\/A%B7Q; rCct|jdk7r tdt|d}t|d}|j||j j z ztddz}|j||j jz ztddz}||z|jdz|jdzz tddzz S)aThe equation of evolute of the ellipse. Parameters ========== x : str, optional Label for the x-axis. Default value is 'x'. y : str, optional Label for the y-axis. Default value is 'y'. Returns ======= equation : SymPy expression Examples ======== >>> from sympy import Point, Ellipse >>> e1 = Ellipse(Point(1, 0), 3, 2) >>> e1.evolute() 2**(2/3)*y**(2/3) + (3*x - 3)**(2/3) - 5**(2/3) z.Evolute of arbitrary Ellipse is not supported.Tr3r1) rUrNotImplementedErrorrrFrEr:r rGr;r>r:r;rrs rAevolutezEllipse.evolutes0 tyy>Q %&VW W AD ! AD !llA -.!Q ?llA -.!Q ?Bw$,,/DLL!O;hq!nLLLrCcf|j}|j|j}}||k(r||fSt|jdz|j dzz }||j k(r|t d| z|t d|zfS||jk(r|t | dz|t |dzfSy)ahThe foci of the ellipse. Notes ----- The foci can only be calculated if the major/minor axes are known. Raises ====== ValueError When the major and minor axis cannot be determined. See Also ======== sympy.geometry.point.Point focus_distance : Returns the distance between focus and center Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.foci (Point2D(-2*sqrt(2), 0), Point2D(2*sqrt(2), 0)) r1rN)rErFrGrrmrr")r>rdhrvrfds rArz Ellipse.focis< KKt||B 8q6M$**a-$**a-/ 0  a" %q5B<'78 8 4:: rc1 %q5Q<'78 8rCc\tj|j|jdS)aThe focal distance of the ellipse. The distance between the center and one focus. Returns ======= focus_distance : number See Also ======== foci Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.focus_distance 2*sqrt(2) r)r"rrErris rArzEllipse.focus_distance1s!4~~dkk499Q<88rCc |jdS)a^The horizontal radius of the ellipse. Returns ======= hradius : number See Also ======== vradius, major, minor Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.hradius 3 rrris rArFzEllipse.hradiusMrrCc t|tr ||vr|gSgSt|ttfr|j t t }t|t|jd|jdj t t gt t gdd}tt|Dcgc]}||vst|c}St|tr|j|St|ttfr||k(r|S|j t t }ttt||j t t gt t gddDcgc] }t|c}St|t r t#dt#dt%|zcc}wcc}w)aCThe intersection of this ellipse and another geometrical entity `o`. Parameters ========== o : GeometryEntity Returns ======= intersection : list of GeometryEntity objects Notes ----- Currently supports intersections with Point, Line, Segment, Ray, Circle and Ellipse types. See Also ======== sympy.geometry.entity.GeometryEntity Examples ======== >>> from sympy import Ellipse, Point, Line >>> e = Ellipse(Point(0, 0), 5, 7) >>> e.intersection(Point(0, 0)) [] >>> e.intersection(Point(5, 0)) [Point2D(5, 0)] >>> e.intersection(Line(Point(0,0), Point(0, 1))) [Point2D(0, -7), Point2D(0, 7)] >>> e.intersection(Line(Point(5,0), Point(5, 1))) [Point2D(5, 0)] >>> e.intersection(Line(Point(6,0), Point(6, 1))) [] >>> e = Ellipse(Point(-1, 0), 4, 3) >>> e.intersection(Ellipse(Point(1, 0), 4, 3)) [Point2D(0, -3*sqrt(15)/4), Point2D(0, 3*sqrt(15)/4)] >>> e.intersection(Ellipse(Point(5, 0), 4, 3)) [Point2D(2, -3*sqrt(7)/4), Point2D(2, 3*sqrt(7)/4)] >>> e.intersection(Ellipse(Point(100500, 0), 4, 3)) [] >>> e.intersection(Ellipse(Point(0, 0), 3, 4)) [Point2D(3, 0), Point2D(-363/175, -48*sqrt(111)/175), Point2D(-363/175, 48*sqrt(111)/175)] >>> e.intersection(Ellipse(Point(-1, 0), 3, 4)) [Point2D(-17/5, -12/5), Point2D(-17/5, 12/5), Point2D(7/5, -12/5), Point2D(7/5, 12/5)] rrT)set5Entity must be two dimensional, not three dimensionalzIntersection not handled for %s)r8r"rrr9r:r;r,rpointsrXr Polygon intersectionr6r r! TypeErrorr/)r>r?ellipse_equationresultis rArzEllipse.intersectiongsj a Dys  Iu- .#}}Q2 ,d QXXa[/**2(1a.:<=q6F6 DaQ!Vq DEF F 7 #>>$' ' GV, -Dy #'==A#6 Gu%qzz!Q'781a&88!%"!U1X%"#$$> *ST T= ! LM M!!E%"s1 F; ; F; ,G cttryttr:j}t|try|rt fd|DSytt r:j}|syt |dk(ry|dj|dStttfr9j}t |dk(rj|ddvSyttrt fdjDStttfr tdtdt!z) aIs `o` tangent to the ellipse? Parameters ========== o : GeometryEntity An Ellipse, LinearEntity or Polygon Raises ====== NotImplementedError When the wrong type of argument is supplied. Returns ======= is_tangent: boolean True if o is tangent to the ellipse, False otherwise. See Also ======== tangent_lines Examples ======== >>> from sympy import Point, Ellipse, Line >>> p0, p1, p2 = Point(0, 0), Point(3, 0), Point(3, 3) >>> e1 = Ellipse(p0, 3, 2) >>> l1 = Line(p1, p2) >>> e1.is_tangent(l1) True FTc3K|]9}j|djj|d;ywrN) tangent_linesequals)rsrr?r>s rAruz%Ellipse.is_tangent..s<gXYD..q1!4<s rAruz%Ellipse.is_tangent..s;atq);srzIs_tangent not handled for %s)r8r#r6rallr rUrrrrrsidesr!r$rr/)r>r? intersecthits`` rArzEllipse.is_tangents3J a ! 7 #))!,I)W-g]fggg 6 "##A&C3x1}q6==Q( ( Iu- .))!,I9~"D..y|>> from sympy import Point, Ellipse, Symbol >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.major 3 >>> a = Symbol('a') >>> b = Symbol('b') >>> Ellipse(p1, a, b).major a >>> Ellipse(p1, b, a).major b >>> m = Symbol('m') >>> M = m + 1 >>> Ellipse(p1, m, M).major m + 1 rrrTF)rrUrFr>abrrr?s rArmz Ellipse.major`HYYq^ r7a<a5L1 EAI 9H %ZH||rCc|jdd}t|dk(r|dS|\}}||z dk}|dk(r|S|dk(r|S|jS)aShorter axis of the ellipse (if it can be determined) else vradius. Returns ======= minor : number or expression See Also ======== hradius, vradius, major Examples ======== >>> from sympy import Point, Ellipse, Symbol >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.minor 1 >>> a = Symbol('a') >>> b = Symbol('b') >>> Ellipse(p1, a, b).minor b >>> Ellipse(p1, b, a).minor a >>> m = Symbol('m') >>> M = m + 1 >>> Ellipse(p1, m, M).minor m rrrTF)rrUrGrs rArz Ellipse.minor,rrCc t|d} g}|j|jjk(r*|jt |jt |j |jj k(r&|jt |jd|r|S|jtt }t|t t}d|z }t |tt fj}||z }t|t d} |jt | jdj} t| jdk(r^ t!| tj#} | D cgc]3} t| t|jt| t d5} } n t)d | Dcgc]1}|jt-tt f|j.3}}|I| Dcgc]}|j1|} }|D cgc] } t3| r| n| j1|"}} t-| |Dcgc]\}}t ||c}}S#t$t&t(f$r"t+t| tdd} Y0wxYwcc} wcc}wcc}wcc} wcc}}w) aANormal lines between `p` and the ellipse. Parameters ========== p : Point Returns ======= normal_lines : list with 1, 2 or 4 Lines Examples ======== >>> from sympy import Point, Ellipse >>> e = Ellipse((0, 0), 2, 3) >>> c = e.center >>> e.normal_lines(c + Point(1, 0)) [Line2D(Point2D(0, 0), Point2D(1, 0))] >>> e.normal_lines(c) [Line2D(Point2D(0, 0), Point2D(0, 1)), Line2D(Point2D(0, 0), Point2D(1, 0))] Off-axis points require the solution of a quartic equation. This often leads to very large expressions that may be of little practical use. An approximate solution of `prec` digits can be obtained by passing in the desired value: >>> e.normal_lines((3, 3), prec=2) [Line2D(Point2D(-0.81, -2.7), Point2D(0.19, -1.2)), Line2D(Point2D(1.5, -2.0), Point2D(2.5, -2.7))] Whereas the above solution has an operation count of 12, the exact solution has an operation count of 2020. r1rPT)sloperr) separatedz7intersections for the general ellipse are not supported)r"r:rEappendrr r;r9r%rr,r<as_numer_denomexpandrUrvr( real_rootsr'r)rr+ziprnr*)r>rprecrveqdydxnormrseqyisxeqxsolrrptslopesrs rA normal_lineszEllipse.normal_lines[sFH !O Bssdkkmm# $t{{"56ssdkkmm# $t{{!45 ]]1a RA$wQA%%dlCmAggao,,.q188: s A % @C|..0EIIqeAuRWWQ]A6q9:IFI%IK K8J76J<K-%K#K >2J43J4c:|jd|jz zS)aThe periapsis of the ellipse. The shortest distance between the focus and the contour. Returns ======= periapsis : number See Also ======== apoapsis : Returns greatest distance between focus and contour Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.periapsis 3 - 2*sqrt(2) rrlris rA periapsiszEllipse.periapsisrorCc@|jd|jdzz zS)a@ Calculates the semi-latus rectum of the Ellipse. Semi-latus rectum is defined as one half of the chord through a focus parallel to the conic section directrix of a conic section. Returns ======= semilatus_rectum : number See Also ======== apoapsis : Returns greatest distance between focus and contour periapsis : The shortest distance between the focus and the contour Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.semilatus_rectum 1/3 References ========== .. [1] https://mathworld.wolfram.com/SemilatusRectum.html .. [2] https://en.wikipedia.org/wiki/Ellipse#Semi-latus_rectum rr1rlris rAsemilatus_rectumzEllipse.semilatus_rectums$HzzQ!2!2a!7788rCcjt|jt|j|jS)aReturns a Circle whose diameter is the major axis of the ellipse. Examples ======== >>> from sympy import Ellipse, Point, symbols >>> c = Point(1, 2) >>> Ellipse(c, 8, 7).auxiliary_circle() Circle(Point2D(1, 2), 8) >>> a, b = symbols('a b') >>> Ellipse(c, a, b).auxiliary_circle() Circle(Point2D(1, 2), Max(a, b)) )r[rErrFrGris rAauxiliary_circlezEllipse.auxiliary_circles$dkk3t||T\\#BCCrCczt|jt|jdz|jdzzS)a Returns a Circle consisting of all points where two perpendicular tangent lines to the ellipse cross each other. Returns ======= Circle A director circle returned as a geometric object. Examples ======== >>> from sympy import Ellipse, Point, symbols >>> c = Point(3,8) >>> Ellipse(c, 7, 9).director_circle() Circle(Point2D(3, 8), sqrt(130)) >>> a, b = symbols('a b') >>> Ellipse(c, a, b).director_circle() Circle(Point2D(3, 8), sqrt(a**2 + b**2)) References ========== .. [1] https://en.wikipedia.org/wiki/Director_circle r1)r[rErrFrGris rAdirector_circlezEllipse.director_circles/8dkk4 a$,,/(I#JKKrCc`t|d}|tj tjgS)aThe plot interval for the default geometric plot of the Ellipse. Parameters ========== parameter : str, optional Default value is 't'. Returns ======= plot_interval : list [parameter, lower_bound, upper_bound] Examples ======== >>> from sympy import Point, Ellipse >>> e1 = Ellipse(Point(0, 0), 3, 2) >>> e1.plot_interval() [t, -pi, pi] Tr3)rrr|rws rA plot_intervalzEllipse.plot_intervals'0 ID )ADD5!$$rCcttdd}|j|j\}}|tj|}nt}t |j}d|zdz }t d|dzz }t|jt|||jt||S)aPA random point on the ellipse. Returns ======= point : Point Examples ======== >>> from sympy import Point, Ellipse >>> e1 = Ellipse(Point(0, 0), 3, 2) >>> e1.random_point() # gives some random point Point2D(...) >>> p1 = e1.random_point(seed=0); p1.n(2) Point2D(2.1, 1.4) Notes ===== When creating a random point, one may simply replace the parameter with a random number. When doing so, however, the random number should be made a Rational or else the point may not test as being in the ellipse: >>> from sympy.abc import t >>> from sympy import Rational >>> arb = e1.arbitrary_point(t); arb Point2D(3*cos(t), 2*sin(t)) >>> arb.subs(t, .1) in e1 False >>> arb.subs(t, Rational(.1)) in e1 True >>> arb.subs(t, Rational('.1')) in e1 True See Also ======== sympy.geometry.point.Point arbitrary_point : Returns parameterized point on ellipse ryTr3r1r) rrzrrandomRandomr rr"r<rr) r>seedryr:r;rngrrdrs rA random_pointzEllipse.random_point6sT Cd ###A&++1  --%CC SZZ\ " aC!G QTNQVVCFA&s1vq(9::rCc &|jdtfvrE|j}|j|}|j ||j |j SdDcgc]}t|||fddc}\}}|j||}t||j|}|jt||f|jd}ttddt|d t|d t|zcc}w) aOverride GeometryEntity.reflect since the radius is not a GeometryEntity. Examples ======== >>> from sympy import Circle, Line >>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1))) Circle(Point2D(1, 0), -1) >>> from sympy import Ellipse, Line, Point >>> Ellipse(Point(3, 4), 1, 3).reflect(Line(Point(0, -4), Point(5, 0))) Traceback (most recent call last): ... NotImplementedError: General Ellipse is not supported but the equation of the reflected Ellipse is given by the zeros of: f(x, y) = (9*x/41 + 40*y/41 + 37/41)**2 + (40*x/123 - 3*y/41 - 364/123)**2 - 1 Notes ===== Until the general ellipse (with no axis parallel to the x-axis) is supported a NotImplemented error is raised and the equation whose zeros define the rotated ellipse is given. rxyc d|zS)N_rS)rs rArTz!Ellipse.reflect..s S1WrCT)modifyr4) simultaneouszeGeneral Ellipse is not supported but the equation of the reflected Ellipse is given by the zeros of: zf(z, z) = )rr rEreflectfuncrFrGrr9r"r<rrrr.str) r>linerdrrr:r;exprrrs rArzEllipse.reflectns8 ::!R  A $A99Q t||< <!"*tTl+<4I"DAq==A&Da ##D)AYYsAq6166 %379F%jF$'FCFCK@A'BC C"sDc|j|jk(r6|j|jj |||jS|t j z jrt|||Sd|zt j z jrA|j|jj |||j|jStd)aRotate ``angle`` radians counterclockwise about Point ``pt``. Note: since the general ellipse is not supported, only rotations that are integer multiples of pi/2 are allowed. Examples ======== >>> from sympy import Ellipse, pi >>> Ellipse((1, 0), 2, 1).rotate(pi/2) Ellipse(Point2D(0, 1), 1, 2) >>> Ellipse((1, 0), 2, 1).rotate(pi) Ellipse(Point2D(-1, 0), 2, 1) r1z;Only rotations of pi/2 are currently supported for Ellipse.) rFrGrrErotaterr| is_integerrLr)r>anglerrNs rArzEllipse.rotates <<4<< '99T[[//r:DLLI I !$$J " "7>%, , eGADDL $ $99T[[//r:DLL$,,W W!"_``rCc>|j}|rNt|d}|j| jj ||j|jS|j }|j }|j|j ||||z||zS)atOverride GeometryEntity.scale since it is the major and minor axes which must be scaled and they are not GeometryEntities. Examples ======== >>> from sympy import Ellipse >>> Ellipse((0, 0), 2, 1).scale(2, 4) Circle(Point2D(0, 0), 4) >>> Ellipse((0, 0), 2, 1).scale(2) Ellipse(Point2D(0, 0), 4, 1) r1rPrFrG)rEr" translaterscalerFrGr)r>r:r;rrdrerfs rArz Ellipse.scales KK rq!BD>4>>RC::.44Q:DDbggN N LL LLyyA!QqSyAArCc t|d}|j|rgS||vr|j|z }|jdz|jz}|j dz |j z}tt|j|zt|j |z}t||gSt|jdk(rO|j\}}|j }d|ztj||z tj||z } n-|jtj|j|z } | jr| jrgS|jtt } t!| t t} t|ttt j"} t%| | z | gtt g} t| dk(r| dd|jk(s| dd|j k(r2t||tddzt||tddzgSt||tddzt|| dgSt|| dt|| dgS)a`Tangent lines between `p` and the ellipse. If `p` is on the ellipse, returns the tangent line through point `p`. Otherwise, returns the tangent line(s) from `p` to the ellipse, or None if no tangent line is possible (e.g., `p` inside ellipse). Parameters ========== p : Point Returns ======= tangent_lines : list with 1 or 2 Lines Raises ====== NotImplementedError Can only find tangent lines for a point, `p`, on the ellipse. See Also ======== sympy.geometry.point.Point, sympy.geometry.line.Line Examples ======== >>> from sympy import Point, Ellipse >>> e1 = Ellipse(Point(0, 0), 3, 2) >>> e1.tangent_lines(Point(3, 0)) [Line2D(Point2D(3, 0), Point2D(3, -12))] r1rPrr)r"rrErGr:rFr;rrrUrrr is_numberrr9r%rr,)r>rdeltariserunp2f1f2majrrrrtangent_pointss rArzEllipse.tangent_liness2J !O   q !I 9KK!OELL!OUWW,DLL!O$UWW,Cxc *d +-BBK= 499~"Bll#r1-.r1-.{{U^^DKK%CC~~$"2"2 q!$BQ?DE!QK(..E#EDL"#51v>N>"a'!!$!"%(6q(9!(<(C Aa O4d1a%1+o6NOO Aa O4d1nQ>O6PQQN1-.Qq8I0JK KrCc |jdS)a\The vertical radius of the ellipse. Returns ======= vradius : number See Also ======== hradius, major, minor Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.vradius 1 r1rris rArGzEllipse.vradiusrrCc,tj|jz|jdzzdz }tj|jdzz|jzdz }d}||||fS||j|d|j j z dzzz}||j|d|j jz dzzz}||j|d|j jz z|d|j j z zz}|||fS)aReturns the second moment and product moment area of an ellipse. Parameters ========== point : Point, two-tuple of sympifiable objects, or None(default=None) point is the point about which second moment of area is to be found. If "point=None" it will be calculated about the axis passing through the centroid of the ellipse. Returns ======= I_xx, I_yy, I_xy : number or SymPy expression I_xx, I_yy are second moment of area of an ellise. I_xy is product moment of area of an ellipse. Examples ======== >>> from sympy import Point, Ellipse >>> p1 = Point(0, 0) >>> e1 = Ellipse(p1, 3, 1) >>> e1.second_moment_of_area() (3*pi/4, 27*pi/4, 0) References ========== .. [1] https://en.wikipedia.org/wiki/List_of_second_moments_of_area rrrrr1)rr|rFrGr}rEr;r:)r>pointI_xxI_yyI_xys rAsecond_moment_of_areazEllipse.second_moment_of_area3sDdll#T\\1_5q8dllAo& 5q8 =t# #dii%(T[[]]":Q!>??dii%(T[[]]":Q!>??diiqDKKMM!9:E!Ht{{}}>> from sympy import symbols, Circle, Ellipse >>> c = Circle((5, 5), 4) >>> c.polar_second_moment_of_area() 128*pi >>> a, b = symbols('a, b') >>> e = Ellipse((0, 0), a, b) >>> e.polar_second_moment_of_area() pi*a**3*b/4 + pi*a*b**3/4 References ========== .. [1] https://en.wikipedia.org/wiki/Polar_moment_of_inertia rr)r)r> second_moments rApolar_second_moment_of_areaz#Ellipse.polar_second_moment_of_areads'<224 Q-"222rCc*|j\}}|6|j\}}}}t||z ||z }t||z ||z } n)t|}|j|z }|j |z } |j } | d|z } | d| z } | | fS)aReturns a tuple with the section modulus of an ellipse Section modulus is a geometric property of an ellipse defined as the ratio of second moment of area to the distance of the extreme end of the ellipse from the centroidal axis. Parameters ========== point : Point, two-tuple of sympifyable objects, or None(default=None) point is the point at which section modulus is to be found. If "point=None" section modulus will be calculated for the point farthest from the centroidal axis of the ellipse. Returns ======= S_x, S_y: numbers or SymPy expressions S_x is the section modulus with respect to the x-axis S_y is the section modulus with respect to the y-axis A negative sign indicates that the section modulus is determined for a point below the centroidal axis. Examples ======== >>> from sympy import Symbol, Ellipse, Circle, Point2D >>> d = Symbol('d', positive=True) >>> c = Circle((0, 0), d/2) >>> c.section_modulus() (pi*d**3/32, pi*d**3/32) >>> e = Ellipse(Point2D(0, 0), 2, 4) >>> e.section_modulus() (8*pi, 4*pi) >>> e.section_modulus((2, 2)) (16*pi, 4*pi) References ========== .. [1] https://en.wikipedia.org/wiki/Section_modulus rr)rErmaxr#r;r:r) r>r x_cy_cx_miny_minx_maxy_maxr;r:rS_xS_ys rAsection_moduluszEllipse.section_modulussX;;S =)- &E5%C%K-AC%K-AENE# A# A224 Aq Aq CxrC)NNNN)g?z#66cc99)ry)r:r;Nr:r;rKrrrN),__name__ __module__ __qualname____doc__rBrIrMr]rgpropertyrjrnrzr}rrErr_rr9rrrrFrrrmrrrrrrrrrrrrrGrrr __classcell__)rNs@rAr6r6)s?BF "DH$OL@&446':R<<(\\2AA,00(3,jJXM@*9*9X9962PNdBLH,,\,,\ND`446#9#9JD L< 66;p+CZa0B*NL`4. b3D<rCr6cjeZdZdZdZd dZedZd dZdZ edZ dZ dd Z ed Z y )r[aA circle in space. Constructed simply from a center and a radius, from three non-collinear points, or the equation of a circle. Parameters ========== center : Point radius : number or SymPy expression points : sequence of three Points equation : equation of a circle Attributes ========== radius (synonymous with hradius, vradius, major and minor) circumference equation Raises ====== GeometryError When the given equation is not that of a circle. When trying to construct circle from incorrect parameters. See Also ======== Ellipse, sympy.geometry.point.Point Examples ======== >>> from sympy import Point, Circle, Eq >>> from sympy.abc import x, y, a, b A circle constructed from a center and radius: >>> c1 = Circle(Point(0, 0), 5) >>> c1.hradius, c1.vradius, c1.radius (5, 5, 5) A circle constructed from three points: >>> c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0)) >>> c2.hradius, c2.vradius, c2.radius, c2.center (sqrt(2)/2, sqrt(2)/2, sqrt(2)/2, Point2D(1/2, 1/2)) A circle can be constructed from an equation in the form `ax^2 + by^2 + gx + hy + c = 0`, too: >>> Circle(x**2 + y**2 - 25) Circle(Point2D(0, 0), 5) If the variables corresponding to x and y are named something else, their name or symbol can be supplied: >>> Circle(Eq(a**2 + b**2, 25), x='a', y=b) Circle(Point2D(0, 0), 5) c||jdtj}t|dk(r t |dt t fr|jdd}|jdd}|dj}t |t r|j|jz }t||}t||} t||dz|dz||\}}} } } tj||fvs||k7r td| |z dz } | |z dz } | dz| dzz| |z z }t!| | ft#||Sd \} }t|d k(rN|Dcgc]}t%|d| }}t'|}t |t&s|S|j(} |j*}n=t|dk(r/t%|dd| } |d} t%|d|j,}| !||dk(r| St/j0|| |fi|Std #t$r tdwxYwcc}w#t$r td wxYw)Nevaluaterrr:r;r1z+The given equation is not that of a circle.r')NNr)rQr'z-Circle with imaginary radius is not permittedz)Circle.__new__ received unknown arguments)getr r'rUr8rrrlhsrhsr&r-rVrrr=r[rr"Triangle circumcenter circumradiusr:rr])r^rr`r'r:r;r9rrrddecenter_xcenter_yr2rrys rAr]zCircle.__new__sU::j*;*D*DE t9>ja4*= 3$A 3$AAw~~'H(B'#<<(,,6Q!AQ!A S -h1adAq I 1aAvv!Q16#$QRRr!tAvHr!tAvHA+(A+.14B8X.R8L LDAq4yA~DHIqaQ:IIdO!!X.HNNNNTa$q'q8<GYaX688AI6H%--c1aB6BB KL LI S#$QRR SJ"Y'(WXXYsH H!H& H&H;c |j\}}t|}|jdd|i|}|jdd|i|}|j||dS)NrFr(rS)rr0evalfr)r>roptionsrrdpss rA _eval_evalfzCircle._eval_evalf8s^ A$ RXX ' 'w ' AGG %c %W %yyQy//rCcBdtjz|jzS)a"The circumference of the circle. Returns ======= circumference : number or SymPy expression Examples ======== >>> from sympy import Point, Circle >>> c1 = Circle(Point(3, 4), 6) >>> c1.circumference 12*pi r1)rr|rris rArzCircle.circumference?s$144x$++%%rCct|d}t|d}||jjz dz}||jjz dz}||z|jdzz S)aThe equation of the circle. Parameters ========== x : str or Symbol, optional Default value is 'x'. y : str or Symbol, optional Default value is 'y'. Returns ======= equation : SymPy expression Examples ======== >>> from sympy import Point, Circle >>> c1 = Circle(Point(0, 0), 5) >>> c1.equation() x**2 + y**2 - 25 Tr3r1)rrEr:r;rmrs rAr9zCircle.equationSsa2 AD ! AD !$++--! #$++--! #BwQ&&rCc.tj||S)aThe intersection of this circle with another geometrical entity. Parameters ========== o : GeometryEntity Returns ======= intersection : list of GeometryEntities Examples ======== >>> from sympy import Point, Circle, Line, Ray >>> p1, p2, p3 = Point(0, 0), Point(5, 5), Point(6, 0) >>> p4 = Point(5, 0) >>> c1 = Circle(p1, 5) >>> c1.intersection(p2) [] >>> c1.intersection(p4) [Point2D(5, 0)] >>> c1.intersection(Ray(p1, p2)) [Point2D(5*sqrt(2)/2, 5*sqrt(2)/2)] >>> c1.intersection(Line(p2, p3)) [] )r6rrHs rArzCircle.intersectionrs<##D!,,rCc |jdS)atThe radius of the circle. Returns ======= radius : number or SymPy expression See Also ======== Ellipse.major, Ellipse.minor, Ellipse.hradius, Ellipse.vradius Examples ======== >>> from sympy import Point, Circle >>> c1 = Circle(Point(3, 4), 6) >>> c1.radius 6 rrris rArz Circle.radiuss.yy|rCcv|j}|j|}|j||j S)aOverride GeometryEntity.reflect since the radius is not a GeometryEntity. Examples ======== >>> from sympy import Circle, Line >>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1))) Circle(Point2D(1, 0), -1) )rErrr)r>rrds rArzCircle.reflects1 KK IIdOyyT[[L))rCNc|j}|rNt|d}|j| jj ||j|jS|j ||}||fDcgc] }t |c}\}}||k(r|j |||jzS|jx}}t|||z||zScc}w)a;Override GeometryEntity.scale since the radius is not a GeometryEntity. Examples ======== >>> from sympy import Circle >>> Circle((0, 0), 1).scale(2, 2) Circle(Point2D(0, 0), 2) >>> Circle((0, 0), 1).scale(2, 4) Ellipse(Point2D(0, 0), 2, 4) r1rPr) rEr"rrrabsrrr6)r>r:r;rrdrrerfs rArz Circle.scales KK rq!BD>4>>RC::.44Q:DDbggN N GGAqM!"A'1A'1 699Q$++ . . Aq!A#qs33 (s5Cc,t|jS)a This Ellipse property is an alias for the Circle's radius. Whereas hradius, major and minor can use Ellipse's conventions, the vradius does not exist for a circle. It is always a positive value in order that the Circle, like Polygons, will have an area that can be positive or negative as determined by the sign of the hradius. Examples ======== >>> from sympy import Point, Circle >>> c1 = Circle(Point(3, 4), 6) >>> c1.vradius 6 )r?rris rArGzCircle.vradiuss&4;;rC)rr)rr r!r"r]r8r#rr9rrrrrGrSrCrAr[r[se=~1Mf0&&&'>-@0 *40  rCr[)rr,)Pr"sympy.core.exprrsympy.core.relationalr sympy.corerrrsympy.core.evalfrsympy.core.parametersr sympy.core.logicr sympy.core.numbersr r sympy.core.sortingr sympy.core.symbolrrrsympy.simplify.simplifyrsympy.simplify.trigsimpr(sympy.functions.elementary.miscellaneousrr(sympy.functions.elementary.trigonometricrr*sympy.functions.special.elliptic_integralsrentityrr exceptionsrrrrrrr r!r r"r#r$utilr%r& sympy.polysr'r(r)sympy.polys.polyutilsr*r+ sympy.solversr,sympy.solvers.solvesetr-sympy.utilities.miscr.r/mpmath.libmp.libmpfr0rranger:r;r6r[polygonrr,)rs0rAr[s!$%%3'+&CC,,>=A/%II**::606+ 388