Ellipses

class sympy.geometry.ellipse.Ellipse(center=None, hradius=None, vradius=None, eccentricity=None, **kwargs)[source]

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.

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)

Attributes

center

hradius

vradius

area

circumference

eccentricity

periapsis

apoapsis

focus_distance

foci

property apoapsis

The 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
arbitrary_point(parameter='t')[source]

A 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.

Examples

>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.arbitrary_point()
Point2D(3*cos(t), 2*sin(t))
property area

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
property bounds

Return a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure.

property center

The center of the ellipse.

Returns

center : number

Examples

>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.center
Point2D(0, 0)
property circumference

The 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)
property eccentricity

The eccentricity of the ellipse.

Returns

eccentricity : number

Examples

>>> from sympy import Point, Ellipse, sqrt
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, sqrt(2))
>>> e1.eccentricity
sqrt(7)/3
encloses_point(p)[source]

Return True if p is enclosed by (is inside of) self.

Parameters

p : Point

Returns

encloses_point : True, False or None

Notes

Being on the border of self is considered False.

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
equation(x='x', y='y')[source]

The equation 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

See also

arbitrary_point

Returns parameterized point on ellipse

Examples

>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(1, 0), 3, 2)
>>> e1.equation()
y**2/4 + (x/3 - 1/3)**2 - 1
evolute(x='x', y='y')[source]

The 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)
property foci

The foci of the ellipse.

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

Notes

The foci can only be calculated if the major/minor axes are known.

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))
property focus_distance

The 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)
property hradius

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
intersection(o)[source]

The 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.

Examples

>>> from sympy import Ellipse, Point, Line, sqrt
>>> 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)]
is_tangent(o)[source]

Is \(o\) tangent to the ellipse?

Parameters

o : GeometryEntity

An Ellipse, LinearEntity or Polygon

Returns

is_tangent: boolean

True if o is tangent to the ellipse, False otherwise.

Raises

NotImplementedError

When the wrong type of argument is supplied.

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
property major

Longer axis of the ellipse (if it can be determined) else hradius.

Returns

major : number or expression

See also

hradius, vradius, minor

Examples

>>> 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
property minor

Shorter 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
normal_lines(p, prec=None)[source]

Normal lines between \(p\) and the ellipse.

Parameters

p : Point

Returns

normal_lines : list with 1, 2 or 4 Lines

Examples

>>> from sympy import Line, 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.

property periapsis

The 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
-2*sqrt(2) + 3
plot_interval(parameter='t')[source]

The 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]
random_point(seed=None)[source]

A random point on the ellipse.

Returns

point : Point

See also

sympy.geometry.point.Point

arbitrary_point

Returns parameterized point on ellipse

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

Examples

>>> from sympy import Point, Ellipse, Segment
>>> 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)
reflect(line)[source]

Override GeometryEntity.reflect since the radius is not a GeometryEntity.

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.

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
rotate(angle=0, pt=None)[source]

Rotate 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)
scale(x=1, y=1, pt=None)[source]

Override 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)
second_moment_of_area(point=None)[source]

Returns 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.

References

https://en.wikipedia.org/wiki/List_of_second_moments_of_area

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)
property semilatus_rectum

Calculates the semi-latus rectum of the Ellipse.

Semi-latus rectum is defined as one half of the 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

References

[1] http://mathworld.wolfram.com/SemilatusRectum.html [2] https://en.wikipedia.org/wiki/Ellipse#Semi-latus_rectum

Examples

>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.semilatus_rectum
1/3
tangent_lines(p)[source]

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.

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))]
property vradius

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
class sympy.geometry.ellipse.Circle(*args, **kwargs)[source]

A circle in space.

Constructed simply from a center and a radius, or from three non-collinear points.

Parameters

center : Point

radius : number or sympy expression

points : sequence of three Points

Raises

GeometryError

When trying to construct circle from three collinear points. When trying to construct circle from incorrect parameters.

Examples

>>> from sympy.geometry import Point, Circle
>>> # 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))

Attributes

radius (synonymous with hradius, vradius, major and minor)

circumference

equation

property circumference

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
equation(x='x', y='y')[source]

The 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
intersection(o)[source]

The 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))
[]
property radius

The radius of the circle.

Returns

radius : number or sympy expression

Examples

>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.radius
6
reflect(line)[source]

Override 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)
scale(x=1, y=1, pt=None)[source]

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)
property vradius

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