modelparameters.sympy.geometry package

Submodules

modelparameters.sympy.geometry.curve module

Curves in 2-dimensional Euclidean space.

Contains

Curve

class modelparameters.sympy.geometry.curve.Curve(function, limits)[source]

Bases: GeometrySet

A curve in space.

A curve is defined by parametric functions for the coordinates, a parameter and the lower and upper bounds for the parameter value.

Parameters:
  • function (list of functions) –

  • limits (3-tuple) – Function parameter and lower and upper bounds.

functions
parameter
limits
Raises:

ValueError – When functions are specified incorrectly. When limits are specified incorrectly.

See also

sympy.core.function.Function, sympy.polys.polyfuncs.interpolate

Examples

>>> from .. import sin, cos, Symbol, interpolate
>>> from ..abc import t, a
>>> from ..geometry import Curve
>>> C = Curve((sin(t), cos(t)), (t, 0, 2))
>>> C.functions
(sin(t), cos(t))
>>> C.limits
(t, 0, 2)
>>> C.parameter
t
>>> C = Curve((t, interpolate([1, 4, 9, 16], t)), (t, 0, 1)); C
Curve((t, t**2), (t, 0, 1))
>>> C.subs(t, 4)
Point2D(4, 16)
>>> C.arbitrary_point(a)
Point2D(a, a**2)
arbitrary_point(parameter='t')[source]

A parameterized point on the curve.

Parameters:

parameter (str or Symbol, optional) – Default value is ‘t’; the Curve’s parameter is selected with None or self.parameter otherwise the provided symbol is used.

Returns:

arbitrary_point

Return type:

Point

Raises:

ValueError – When parameter already appears in the functions.

See also

sympy.geometry.point.Point

Examples

>>> from .. import Symbol
>>> from ..abc import s
>>> from ..geometry import Curve
>>> C = Curve([2*s, s**2], (s, 0, 2))
>>> C.arbitrary_point()
Point2D(2*t, t**2)
>>> C.arbitrary_point(C.parameter)
Point2D(2*s, s**2)
>>> C.arbitrary_point(None)
Point2D(2*s, s**2)
>>> C.arbitrary_point(Symbol('a'))
Point2D(2*a, a**2)
default_assumptions = {}
property free_symbols

Return a set of symbols other than the bound symbols used to parametrically define the Curve.

Examples

>>> from ..abc import t, a
>>> from ..geometry import Curve
>>> Curve((t, t**2), (t, 0, 2)).free_symbols
set()
>>> Curve((t, t**2), (t, a, 2)).free_symbols
{a}
property functions

The functions specifying the curve.

Returns:

functions

Return type:

list of parameterized coordinate functions.

See also

parameter

Examples

>>> from ..abc import t
>>> from ..geometry import Curve
>>> C = Curve((t, t**2), (t, 0, 2))
>>> C.functions
(t, t**2)
property limits

The limits for the curve.

Returns:

limits – Contains parameter and lower and upper limits.

Return type:

tuple

See also

plot_interval

Examples

>>> from ..abc import t
>>> from ..geometry import Curve
>>> C = Curve([t, t**3], (t, -2, 2))
>>> C.limits
(t, -2, 2)
property parameter

The curve function variable.

Returns:

parameter

Return type:

SymPy symbol

See also

functions

Examples

>>> from ..abc import t
>>> from ..geometry import Curve
>>> C = Curve([t, t**2], (t, 0, 2))
>>> C.parameter
t
plot_interval(parameter='t')[source]

The plot interval for the default geometric plot of the curve.

Parameters:

parameter (str or Symbol, optional) – Default value is ‘t’; otherwise the provided symbol is used.

Returns:

plot_interval – [parameter, lower_bound, upper_bound]

Return type:

list (plot interval)

See also

limits

Returns limits of the parameter interval

Examples

>>> from .. import Curve, sin
>>> from ..abc import x, t, s
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval()
[t, 1, 2]
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval(s)
[s, 1, 2]
rotate(angle=0, pt=None)[source]

Rotate angle radians counterclockwise about Point pt.

The default pt is the origin, Point(0, 0).

Examples

>>> from .curve import Curve
>>> from ..abc import x
>>> from .. import pi
>>> Curve((x, x), (x, 0, 1)).rotate(pi/2)
Curve((-x, x), (x, 0, 1))
scale(x=1, y=1, pt=None)[source]

Override GeometryEntity.scale since Curve is not made up of Points.

Examples

>>> from .curve import Curve
>>> from .. import pi
>>> from ..abc import x
>>> Curve((x, x), (x, 0, 1)).scale(2)
Curve((2*x, x), (x, 0, 1))
translate(x=0, y=0)[source]

Translate the Curve by (x, y).

Examples

>>> from .curve import Curve
>>> from .. import pi
>>> from ..abc import x
>>> Curve((x, x), (x, 0, 1)).translate(1, 2)
Curve((x + 1, x + 2), (x, 0, 1))

modelparameters.sympy.geometry.ellipse module

Elliptical geometrical entities.

Contains * Ellipse * Circle

class modelparameters.sympy.geometry.ellipse.Circle(*args, **kwargs)[source]

Bases: Ellipse

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) –

radius(synonymous with hradius, vradius, major and minor)
circumference
equation[source]
Raises:

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

See also

Ellipse, sympy.geometry.point.Point

Examples

>>> from ..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))
property circumference

The circumference of the circle.

Returns:

circumference

Return type:

number or SymPy expression

Examples

>>> from .. import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.circumference
12*pi
default_assumptions = {}
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

Return type:

SymPy expression

Examples

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

Return type:

list of GeometryEntities

Examples

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

Return type:

number or sympy expression

Examples

>>> from .. 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 .. 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 .. 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 .. import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.vradius
6
class modelparameters.sympy.geometry.ellipse.Ellipse(center=None, hradius=None, vradius=None, eccentricity=None, **kwargs)[source]

Bases: GeometrySet

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.

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

Plotting:

>>> from ..plotting.pygletplot import PygletPlot as Plot
>>> from .. import Circle, Segment
>>> c1 = Circle(Point(0,0), 1)
>>> Plot(c1)                                
[0]: cos(t), sin(t), 'mode=parametric'
>>> p = Plot()                              
>>> p[0] = c1                               
>>> radius = Segment(c1.center, c1.random_point())
>>> p[1] = radius                           
>>> p                                       
[0]: cos(t), sin(t), 'mode=parametric'
[1]: t*cos(1.546086215036205357975518382),
t*sin(1.546086215036205357975518382), 'mode=parametric'
property ambient_dimension

What is the dimension of the space that the object is contained in?

property apoapsis

The apoapsis of the ellipse.

The greatest distance between the focus and the contour.

Returns:

apoapsis

Return type:

number

See also

periapsis

Returns shortest distance between foci and contour

Examples

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

Return type:

Point

Raises:

ValueError – When parameter already appears in the functions.

See also

sympy.geometry.point.Point

Examples

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

Return type:

number

Examples

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

Return type:

number

See also

sympy.geometry.point.Point

Examples

>>> from .. 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 .. import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.circumference
12*Integral(sqrt((-8*_x**2/9 + 1)/(-_x**2 + 1)), (_x, 0, 1))
default_assumptions = {}
property eccentricity

The eccentricity of the ellipse.

Returns:

eccentricity

Return type:

number

Examples

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

Notes

Being on the border of self is considered False.

Parameters:

p (Point) –

Returns:

encloses_point

Return type:

True, False or None

See also

sympy.geometry.point.Point

Examples

>>> from .. import Ellipse, S
>>> from ..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

Return type:

sympy expression

See also

arbitrary_point

Returns parameterized point on ellipse

Examples

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

Return type:

sympy expression

Examples

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

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

Return type:

number

See also

foci

Examples

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

Return type:

number

See also

vradius, major, minor

Examples

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

Return type:

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

Raises:

NotImplementedError – When the wrong type of argument is supplied.

Returns:

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

Return type:

boolean

See also

tangent_lines

Examples

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

Return type:

number or expression

See also

hradius, vradius, minor

Examples

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

Return type:

number or expression

See also

hradius, vradius, major

Examples

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

Return type:

list with 1, 2 or 4 Lines

Examples

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

Return type:

number

See also

apoapsis

Returns greatest distance between focus and contour

Examples

>>> from .. 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 – [parameter, lower_bound, upper_bound]

Return type:

list

Examples

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

Return type:

Point

See also

sympy.geometry.point.Point

arbitrary_point

Returns parameterized point on ellipse

Notes

A random point may not appear to be on the ellipse, ie, p in e may return False. This is because the coordinates of the point will be floating point values, and when these values are substituted into the equation for the ellipse the result may not be zero because of floating point rounding error.

Examples

>>> from .. 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)

The random_point method assures that the point will test as being in the ellipse:

>>> p1 in e1
True

Notes

An arbitrary_point with a random value of t substituted into it may not test as being on the ellipse because the expression tested that a point is on the ellipse doesn’t simplify to zero and doesn’t evaluate exactly to zero:

>>> from ..abc import t
>>> e1.arbitrary_point(t)
Point2D(3*cos(t), 2*sin(t))
>>> p2 = _.subs(t, 0.1)
>>> p2 in e1
False

Note that arbitrary_point routine does not take this approach. A value for cos(t) and sin(t) (not t) is substituted into the arbitrary point. There is a small chance that this will give a point that will not test as being in the ellipse, so the process is repeated (up to 10 times) until a valid point is obtained.

reflect(line)[source]

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

Examples

>>> from .. import Circle, Line
>>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
Circle(Point2D(1, 0), -1)
>>> from .. 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.

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

Return type:

number

See also

apoapsis

Returns greatest distance between focus and contour

periapsis

The shortest distance between the focus and the contour

Examples

>>> from .. import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.semilatus_rectum
1/3

References

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

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

Return type:

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 .. import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.tangent_lines(Point(3, 0))
[Line2D(Point2D(3, 0), Point2D(3, -12))]
>>> # This will plot an ellipse together with a tangent line.
>>> from ..plotting.pygletplot import PygletPlot as Plot
>>> from .. import Point, Ellipse
>>> e = Ellipse(Point(0,0), 3, 2)
>>> t = e.tangent_lines(e.random_point())
>>> p = Plot()
>>> p[0] = e 
>>> p[1] = t 
property vradius

The vertical radius of the ellipse.

Returns:

vradius

Return type:

number

See also

hradius, major, minor

Examples

>>> from .. import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.vradius
1

modelparameters.sympy.geometry.entity module

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

class modelparameters.sympy.geometry.entity.GeometryEntity(*args, **kwargs)[source]

Bases: Basic

The base class for all geometrical entities.

This class doesn’t represent any particular geometric entity, it only provides the implementation of some methods common to all subclasses.

property ambient_dimension

What is the dimension of the space that the object is contained in?

property bounds

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

default_assumptions = {}
encloses(o)[source]

Return True if o is inside (not on or outside) the boundaries of self.

The object will be decomposed into Points and individual Entities need only define an encloses_point method for their class.

See also

sympy.geometry.ellipse.Ellipse.encloses_point, sympy.geometry.polygon.Polygon.encloses_point

Examples

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

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

is_similar(other)[source]

Is 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

reflect(line)[source]
rotate(angle, pt=None)[source]

Rotate angle radians counterclockwise about Point pt.

The default pt is the origin, Point(0, 0)

See also

scale, translate

Examples

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

Scale 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 .. 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)))
translate(x=0, y=0)[source]

Shift the object by adding to the x,y-coordinates the values x and y.

See also

rotate, scale

Examples

>>> from .. 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, -sqrt(3)/2 + 2))
class modelparameters.sympy.geometry.entity.GeometrySet(*args, **kwargs)[source]

Bases: GeometryEntity, Set

Parent class of all GeometryEntity that are also Sets (compatible with sympy.sets)

default_assumptions = {}
modelparameters.sympy.geometry.entity.rotate(th)[source]

Return 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 .entity import rotate, translate
>>> from .. 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)
modelparameters.sympy.geometry.entity.scale(x, y, pt=None)[source]

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

modelparameters.sympy.geometry.entity.translate(x, y)[source]

Return the matrix to translate a 2-D point by x and y.

modelparameters.sympy.geometry.exceptions module

Geometry Errors.

exception modelparameters.sympy.geometry.exceptions.GeometryError[source]

Bases: ValueError

An exception raised by classes in the geometry module.

modelparameters.sympy.geometry.line module

Line-like geometrical entities.

Contains

LinearEntity Line Ray Segment LinearEntity2D Line2D Ray2D Segment2D LinearEntity3D Line3D Ray3D Segment3D

class modelparameters.sympy.geometry.line.Line(p1, p2=None, **kwargs)[source]

Bases: LinearEntity

An infinite line in space.

A line is declared with two distinct points. A 2D line may be declared with a point and slope and a 3D line may be defined with a point and a direction ratio.

Parameters:
  • p1 (Point) –

  • p2 (Point) –

  • slope (sympy expression) –

  • direction_ratio (list) –

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.

See also

sympy.geometry.point.Point, sympy.geometry.line.Line2D, sympy.geometry.line.Line3D

Examples

>>> import sympy
>>> from .. import Point
>>> from ..geometry import Line, Segment
>>> 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
contains(other)[source]

Return True if other is on this Line, or False otherwise.

Examples

>>> from .. 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
default_assumptions = {}
distance(other)[source]

Finds the shortest distance between a line and a point.

Raises:

NotImplementedError is raised if other is not a Point

Examples

>>> from .. 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
equal(other)[source]
equals(other)[source]

Returns True if self and other are the same mathematical entities

plot_interval(parameter='t')[source]

The plot interval for the default geometric plot of line. Gives values that will produce a line that is +/- 5 units long (where a unit is the distance between the two points that define the line).

Parameters:

parameter (str, optional) – Default value is ‘t’.

Returns:

plot_interval – [parameter, lower_bound, upper_bound]

Return type:

list (plot interval)

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5]
class modelparameters.sympy.geometry.line.Line2D(p1, pt=None, slope=None, **kwargs)[source]

Bases: LinearEntity2D, Line

An 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

>>> import sympy
>>> from .. import Point
>>> from ..abc import L
>>> from ..geometry import Line, Segment
>>> 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
property coefficients

The coefficients (a, b, c) for ax + by + c = 0.

See also

sympy.geometry.line.Line.equation

Examples

>>> from .. import Point, Line
>>> from ..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)
default_assumptions = {}
equation(x='x', y='y')[source]

The 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

Return type:

sympy expression

See also

LinearEntity.coefficients

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3
class modelparameters.sympy.geometry.line.Line3D(p1, pt=None, direction_ratio=[], **kwargs)[source]

Bases: LinearEntity3D, Line

An 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:

See also

sympy.geometry.point.Point3D, sympy.geometry.line.Line, sympy.geometry.line.Line2D

Examples

>>> import sympy
>>> from .. import Point3D
>>> from ..geometry import Line3D, Segment3D
>>> 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))
default_assumptions = {}
equation(x='x', y='y', z='z', k='k')[source]

The equation of the line in 3D

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

  • z (str, optional) – The name to use for the x-axis, default value is ‘z’.

Returns:

equation

Return type:

tuple

Examples

>>> from .. import Point3D, Line3D
>>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 0)
>>> l1 = Line3D(p1, p2)
>>> l1.equation()
(x/4 - 1/4, y/3, zoo*z, k)
class modelparameters.sympy.geometry.line.LinearEntity(p1, p2=None, **kwargs)[source]

Bases: GeometrySet

A base class for all linear entities (Line, Ray and Segment) in n-dimensional Euclidean space.

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

property ambient_dimension

What is the dimension of the space that the object is contained in?

angle_between(l2)[source]

The angle formed between the two linear entities.

Parameters:
Returns:

angle

Return type:

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

Examples

>>> from .. import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(0, 4), Point(2, 0)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.angle_between(l2)
pi/2
>>> from .. 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)
arbitrary_point(parameter='t')[source]

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

Return type:

Point

Raises:

ValueError – When parameter already appears in the Line’s definition.

See also

sympy.geometry.point.Point

Examples

>>> from .. 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 .. 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)
static are_concurrent(*lines)[source]

Is 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 .. import Point, Line, Line3D
>>> 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 .. 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
contains(other)[source]

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

default_assumptions = {}
property direction

The direction vector of the LinearEntity.

Returns:

p – direction of self

Return type:

a Point; the ray from the origin to this point is the

Examples

>>> from ..geometry 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

intersection(other)[source]

The intersection with another geometrical entity.

Parameters:

o (Point or LinearEntity) –

Returns:

intersection

Return type:

list of geometrical entities

See also

sympy.geometry.point.Point

Examples

>>> from .. 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 .. 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)
[]
is_parallel(l2)[source]

Are two linear entities parallel?

Parameters:
Returns:

  • True (if l1 and l2 are parallel,)

  • False (otherwise.)

See also

coefficients

Examples

>>> from .. 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 .. 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
is_perpendicular(l2)[source]

Are two linear entities perpendicular?

Parameters:
Returns:

  • True (if l1 and l2 are perpendicular,)

  • False (otherwise.)

See also

coefficients

Examples

>>> from .. 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 .. 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
is_similar(other)[source]

Return True if self and other are contained in the same line.

Examples

>>> from .. 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
property length

The length of the line.

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.length
oo
property p1

The first defining point of a linear entity.

See also

sympy.geometry.point.Point

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p1
Point2D(0, 0)
property p2

The second defining point of a linear entity.

See also

sympy.geometry.point.Point

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p2
Point2D(5, 3)
parallel_line(p)[source]

Create a new Line parallel to this linear entity which passes through the point p.

Parameters:

p (Point) –

Returns:

line

Return type:

Line

See also

is_parallel

Examples

>>> from .. 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 .. 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
perpendicular_line(p)[source]

Create a new Line perpendicular to this linear entity which passes through the point p.

Parameters:

p (Point) –

Returns:

line

Return type:

Line

Examples

>>> from .. import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.perpendicular_line(p3)
>>> p3 in l2
True
>>> l1.is_perpendicular(l2)
True
>>> from .. import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0)
>>> l1 = Line3D(p1, p2)
>>> l2 = l1.perpendicular_line(p3)
>>> p3 in l2
True
>>> l1.is_perpendicular(l2)
True
perpendicular_segment(p)[source]

Create a perpendicular line segment from p to this line.

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

Return type:

Segment

Notes

Returns p itself if p is on this linear entity.

Examples

>>> from .. 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(2, 2), Point2D(4, 0))
>>> from .. 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/3, 4/3, 4/3), Point3D(4, 0, 0))
property points

The two points used to define this linear entity.

Returns:

points

Return type:

tuple of Points

See also

sympy.geometry.point.Point

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 11)
>>> l1 = Line(p1, p2)
>>> l1.points
(Point2D(0, 0), Point2D(5, 11))
projection(other)[source]

Project a point, line, ray, or segment onto this linear entity.

Parameters:

other (Point or LinearEntity (Line, Ray, Segment)) –

Returns:

projection – The return type matches the type of the parameter other.

Return type:

Point or LinearEntity (Line, Ray, Segment)

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 .. 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))
random_point()[source]

A random point on a LinearEntity.

Returns:

point

Return type:

Point

See also

sympy.geometry.point.Point

Examples

>>> from .. import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> p3 = l1.random_point()
>>> # random point - don't know its coords in advance
>>> p3 
Point2D(...)
>>> # point should belong to the line
>>> p3 in l1
True
class modelparameters.sympy.geometry.line.LinearEntity2D(p1, p2=None, **kwargs)[source]

Bases: LinearEntity

A base class for all linear entities (line, ray and segment) in a 2-dimensional Euclidean space.

p1
p2
coefficients
slope
points

Notes

This is an abstract class and is not meant to be instantiated.

See also

sympy.geometry.entity.GeometryEntity

property bounds

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

default_assumptions = {}
perpendicular_line(p)[source]

Create a new Line perpendicular to this linear entity which passes through the point p.

Parameters:

p (Point) –

Returns:

line

Return type:

Line

See also

is_perpendicular, perpendicular_segment

Examples

>>> from .. import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.perpendicular_line(p3)
>>> p3 in l2
True
>>> l1.is_perpendicular(l2)
True
property slope

The slope of this linear entity, or infinity if vertical.

Returns:

slope

Return type:

number or sympy expression

See also

coefficients

Examples

>>> from .. 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
class modelparameters.sympy.geometry.line.LinearEntity3D(p1, p2, **kwargs)[source]

Bases: LinearEntity

An base class for all linear entities (line, ray and segment) in a 3-dimensional Euclidean space.

p1
p2
direction_ratio
direction_cosine
points

Notes

This is a base class and is not meant to be instantiated.

ambient_dimension = 3
default_assumptions = {}
property direction_cosine

The normalized direction ratio of a given line in 3D.

See also

sympy.geometry.line.Line.equation

Examples

>>> from .. 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
property direction_ratio

The direction ratio of a given line in 3D.

See also

sympy.geometry.line.Line.equation

Examples

>>> from .. import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1)
>>> l = Line3D(p1, p2)
>>> l.direction_ratio
[5, 3, 1]
class modelparameters.sympy.geometry.line.Ray(p1, p2=None, **kwargs)[source]

Bases: LinearEntity

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.

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

>>> import sympy
>>> from .. import Point, pi
>>> from ..geometry import 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
contains(other)[source]

Is other GeometryEntity contained in this Ray?

Examples

>>> from .. 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
default_assumptions = {}
distance(other)[source]

Finds the shortest distance between the ray and a point.

Raises:

NotImplementedError is raised if other is not a Point

Examples

>>> from .. 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
equals(other)[source]

Returns True if self and other are the same mathematical entities

plot_interval(parameter='t')[source]

The plot interval for the default geometric plot of the Ray. Gives values that will produce a ray that is 10 units long (where a unit is the distance between the two points that define the ray).

Parameters:

parameter (str, optional) – Default value is ‘t’.

Returns:

plot_interval – [parameter, lower_bound, upper_bound]

Return type:

list

Examples

>>> from .. import Point, Ray, pi
>>> r = Ray((0, 0), angle=pi/4)
>>> r.plot_interval()
[t, 0, 10]
property source

The point from which the ray emanates.

See also

sympy.geometry.point.Point

Examples

>>> from .. 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)
class modelparameters.sympy.geometry.line.Ray2D(p1, pt=None, angle=None, **kwargs)[source]

Bases: LinearEntity2D, Ray

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.

source
xdirection
ydirection

See also

sympy.geometry.point.Point, Line

Examples

>>> import sympy
>>> from .. import Point, pi
>>> from ..geometry import 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
default_assumptions = {}
property xdirection

The x direction of the ray.

Positive infinity if the ray points in the positive x direction, negative infinity if the ray points in the negative x direction, or 0 if the ray is vertical.

See also

ydirection

Examples

>>> from .. 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
property ydirection

The 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 .. 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
class modelparameters.sympy.geometry.line.Ray3D(p1, pt=None, direction_ratio=[], **kwargs)[source]

Bases: LinearEntity3D, Ray

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.) –

source
xdirection
ydirection
zdirection

See also

sympy.geometry.point.Point3D, Line3D

Examples

>>> import sympy
>>> from .. import Point3D, pi
>>> from ..geometry import 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]
default_assumptions = {}
property xdirection

The x direction of the ray.

Positive infinity if the ray points in the positive x direction, negative infinity if the ray points in the negative x direction, or 0 if the ray is vertical.

See also

ydirection

Examples

>>> from .. 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
property ydirection

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

The 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 .. 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
class modelparameters.sympy.geometry.line.Segment(p1, p2, **kwargs)[source]

Bases: LinearEntity

An undirected line segment in space.

Parameters:
length
Type:

number or sympy expression

midpoint
Type:

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

>>> import sympy
>>> from .. import Point
>>> from ..geometry import 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(1, 1), Point2D(4, 3))
>>> s.points
(Point2D(1, 1), Point2D(4, 3))
>>> 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(1, 1, 7), Point3D(4, 3, 9))
>>> s.points
(Point3D(1, 1, 7), Point3D(4, 3, 9))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8)
contains(other)[source]

Is the other GeometryEntity contained within this Segment?

Examples

>>> from .. import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s2 = Segment(p2, p1)
>>> s.contains(s2)
True
>>> from .. 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
default_assumptions = {}
distance(other)[source]

Finds the shortest distance between a line segment and a point.

Raises:

NotImplementedError is raised if other is not a Point

Examples

>>> from .. 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 .. 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)
property length

The length of the line segment.

See also

sympy.geometry.point.Point.distance

Examples

>>> from .. import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.length
5
>>> from .. import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3)
>>> s1 = Segment3D(p1, p2)
>>> s1.length
sqrt(34)
property midpoint

The midpoint of the line segment.

See also

sympy.geometry.point.Point.midpoint

Examples

>>> from .. import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.midpoint
Point2D(2, 3/2)
>>> from .. 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)
perpendicular_bisector(p=None)[source]

The 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

Return type:

Line or Segment

Examples

>>> from .. 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(3, 3), Point2D(5, 1))
plot_interval(parameter='t')[source]

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 – [parameter, lower_bound, upper_bound]

Return type:

list

Examples

>>> from .. import Point, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.plot_interval()
[t, 0, 1]
class modelparameters.sympy.geometry.line.Segment2D(p1, p2, **kwargs)[source]

Bases: LinearEntity2D, Segment

An undirected line segment in 2D space.

Parameters:
length
Type:

number or sympy expression

midpoint
Type:

Point

See also

sympy.geometry.point.Point, Line

Examples

>>> import sympy
>>> from .. import Point
>>> from ..geometry import 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(1, 1), Point2D(4, 3))
>>> s.points
(Point2D(1, 1), Point2D(4, 3))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(5/2, 2)
default_assumptions = {}
class modelparameters.sympy.geometry.line.Segment3D(p1, p2, **kwargs)[source]

Bases: LinearEntity3D, Segment

A undirected line segment in a 3D space.

Parameters:
length
Type:

number or sympy expression

midpoint
Type:

Point3D

See also

sympy.geometry.point.Point3D, Line3D

Examples

>>> import sympy
>>> from .. import Point3D
>>> from ..geometry import 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(1, 1, 7), Point3D(4, 3, 9))
>>> s.points
(Point3D(1, 1, 7), Point3D(4, 3, 9))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8)
default_assumptions = {}

modelparameters.sympy.geometry.parabola module

Parabolic geometrical entity.

Contains * Parabola

class modelparameters.sympy.geometry.parabola.Parabola(focus=None, directrix=None, **kwargs)[source]

Bases: GeometrySet

A parabolic GeometryEntity.

A parabola is declared with a point, that is called ‘focus’, and a line, that is called ‘directrix’. Only vertical or horizontal parabolas are currently supported.

Parameters:
  • focus (Point) – Default value is Point(0, 0)

  • directrix (Line) –

focus
directrix
axis of symmetry
focal length
p parameter
vertex
eccentricity
Raises:
  • ValueError – When focus is not a two dimensional point. When focus is a point of directrix.

  • NotImplementedError – When directrix is neither horizontal nor vertical.

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7,8)))
>>> p1.focus
Point2D(0, 0)
>>> p1.directrix
Line2D(Point2D(5, 8), Point2D(7, 8))
property ambient_dimension

What is the dimension of the space that the object is contained in?

property axis_of_symmetry

The axis of symmetry of the parabola.

Returns:

axis_of_symmetry

Return type:

Line

See also

sympy.geometry.line.Line

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.axis_of_symmetry
Line2D(Point2D(0, 0), Point2D(0, 1))
default_assumptions = {}
property directrix

The directrix of the parabola.

Returns:

directrix

Return type:

Line

See also

sympy.geometry.line.Line

Examples

>>> from .. import Parabola, Point, Line
>>> l1 = Line(Point(5, 8), Point(7, 8))
>>> p1 = Parabola(Point(0, 0), l1)
>>> p1.directrix
Line2D(Point2D(5, 8), Point2D(7, 8))
property eccentricity

The eccentricity of the parabola.

Returns:

  • eccentricity (number)

  • A parabola may also be characterized as a conic section with an

  • eccentricity of 1. As a consequence of this, all parabolas are

  • similar, meaning that while they can be different sizes,

  • they are all the same shape.

See also

https

//en.wikipedia.org/wiki/Parabola

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.eccentricity
1

Notes

The eccentricity for every Parabola is 1 by definition.

equation(x='x', y='y')[source]

The equation of the parabola.

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

Return type:

sympy expression

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.equation()
-x**2 - 16*y + 64
>>> p1.equation('f')
-f**2 - 16*y + 64
>>> p1.equation(y='z')
-x**2 - 16*z + 64
property focal_length

The focal length of the parabola.

Returns:

focal_lenght

Return type:

number or symbolic expression

Notes

The distance between the vertex and the focus (or the vertex and directrix), measured along the axis of symmetry, is the “focal length”.

See also

https

//en.wikipedia.org/wiki/Parabola

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.focal_length
4
property focus

The focus of the parabola.

Returns:

focus

Return type:

Point

See also

sympy.geometry.point.Point

Examples

>>> from .. import Parabola, Point, Line
>>> f1 = Point(0, 0)
>>> p1 = Parabola(f1, Line(Point(5, 8), Point(7, 8)))
>>> p1.focus
Point2D(0, 0)
intersection(o)[source]

The intersection of the parabola and another geometrical entity o.

Parameters:

o (GeometryEntity, LinearEntity) –

Returns:

intersection

Return type:

list of GeometryEntity objects

Examples

>>> from .. import Parabola, Point, Ellipse, Line, Segment
>>> p1 = Point(0,0)
>>> l1 = Line(Point(1, -2), Point(-1,-2))
>>> parabola1 = Parabola(p1, l1)
>>> parabola1.intersection(Ellipse(Point(0, 0), 2, 5))
[Point2D(-2, 0), Point2D(2, 0)]
>>> parabola1.intersection(Line(Point(-7, 3), Point(12, 3)))
[Point2D(-4, 3), Point2D(4, 3)]
>>> parabola1.intersection(Segment((-12, -65), (14, -68)))
[]
property p_parameter

P is a parameter of parabola.

Returns:

p

Return type:

number or symbolic expression

Notes

The absolute value of p is the focal length. The sign on p tells which way the parabola faces. Vertical parabolas that open up and horizontal that open right, give a positive value for p. Vertical parabolas that open down and horizontal that open left, give a negative value for p.

See also

http

//www.sparknotes.com/math/precalc/conicsections/section2.rhtml

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.p_parameter
-4
property vertex

The vertex of the parabola.

Returns:

vertex

Return type:

Point

See also

sympy.geometry.point.Point

Examples

>>> from .. import Parabola, Point, Line
>>> p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7, 8)))
>>> p1.vertex
Point2D(0, 4)

modelparameters.sympy.geometry.plane module

Geometrical Planes.

Contains

Plane

class modelparameters.sympy.geometry.plane.Plane(p1, a=None, b=None, **kwargs)[source]

Bases: GeometryEntity

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 and a point and the plane’s normal vector.

p1
normal_vector

Examples

>>> from .. import Plane, Point3D
>>> from ..abc import x
>>> 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))
angle_between(o)[source]

Angle between the plane and other geometric entity.

Parameters:
  • LinearEntity3D

  • Plane.

Returns:

angle

Return type:

angle in radians

Notes

This method accepts only 3D entities as it’s parameter, but if you want to calculate the angle 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 angle.

Examples

>>> from .. 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)
arbitrary_point(t=None)[source]

Returns an arbitrary point on the Plane; varying t from 0 to 2*pi will move the point in a circle of radius 1 about p1 of the Plane.

Examples

>>> from .plane import Plane
>>> from ..abc import t
>>> p = Plane((0, 0, 0), (0, 0, 1), (0, 1, 0))
>>> p.arbitrary_point(t)
Point3D(0, cos(t), sin(t))
>>> _.distance(p.p1).simplify()
1
Return type:

Point3D

static are_concurrent(*planes)[source]

Is a sequence of Planes concurrent?

Two or more Planes are concurrent if their intersections are a common line.

Parameters:

planes (list) –

Return type:

Boolean

Examples

>>> from .. 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
default_assumptions = {}
distance(o)[source]

Distance beteen the plane and another geometric entity.

Parameters:
  • Point3D

  • LinearEntity3D

  • Plane.

Return type:

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 .. import Point, Point3D, Line, 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
equals(o)[source]

Returns True if self and o are the same mathematical entities.

Examples

>>> from .. 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
equation(x=None, y=None, z=None)[source]

The equation of the Plane.

Examples

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

The intersection with other geometrical entity.

Parameters:
  • Point

  • Point3D

  • LinearEntity

  • LinearEntity3D

  • Plane

Return type:

List

Examples

>>> from .. import Point, Point3D, Line, 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))]
is_coplanar(o)[source]

Returns True if o is coplanar with self, else False.

Examples

>>> from .. import Plane, Point3D
>>> o = (0, 0, 0)
>>> p = Plane(o, (1, 1, 1))
>>> p2 = Plane(o, (2, 2, 2))
>>> p == p2
False
>>> p.is_coplanar(p2)
True
is_parallel(l)[source]

Is the given geometric entity parallel to the plane?

Parameters:

Plane (LinearEntity3D or) –

Return type:

Boolean

Examples

>>> from .. 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
is_perpendicular(l)[source]

is the given geometric entity perpendicualar to the given plane?

Parameters:

Plane (LinearEntity3D or) –

Return type:

Boolean

Examples

>>> from .. 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
property normal_vector

Normal vector of the given plane.

Examples

>>> from .. 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)
property p1

The only defining point of the plane. Others can be obtained from the arbitrary_point method.

See also

sympy.geometry.point.Point3D

Examples

>>> from .. import Point3D, Plane
>>> a = Plane(Point3D(1, 1, 1), Point3D(2, 3, 4), Point3D(2, 2, 2))
>>> a.p1
Point3D(1, 1, 1)
parallel_plane(pt)[source]

Plane parallel to the given plane and passing through the point pt.

Parameters:

pt (Point3D) –

Return type:

Plane

Examples

>>> from .. 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))
perpendicular_line(pt)[source]

A line perpendicular to the given plane.

Parameters:

pt (Point3D) –

Return type:

Line3D

Examples

>>> from .. import Plane, Point3D, Line3D
>>> 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))
perpendicular_plane(*pts)[source]

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) –

Return type:

Plane

Examples

>>> from .. import Plane, Point3D, Line3D
>>> 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))
projection(pt)[source]

Project the given point onto the plane along the plane normal.

Parameters:

Point3D (Point or) –

Return type:

Point3D

Examples

>>> from .. import Plane, Point, 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)
projection_line(line)[source]

Project the given line onto the plane through the normal plane containing the line.

Parameters:

LinearEntity3D (LinearEntity or) –

Return type:

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 .. import Plane, Line, Line3D, Point, 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)
random_point(seed=None)[source]

Returns a random point on the Plane.

Return type:

Point3D

modelparameters.sympy.geometry.point module

Geometrical Points.

Contains

Point Point2D Point3D

When methods of Point require 1 or more points as arguments, they can be passed as a sequence of coordinates or Points:

>>> from .point import Point
>>> Point(1, 1).is_collinear((2, 2), (3, 4))
False
>>> Point(1, 1).is_collinear(Point(2, 2), Point(3, 4))
False
class modelparameters.sympy.geometry.point.Point(*args, **kwargs)[source]

Bases: GeometryEntity

A point in a n-dimensional Euclidean space.

Parameters:
  • coords (sequence of n-coordinate values. In the special) – case where n=2 or 3, a Point2D or Point3D will be created as appropriate.

  • evaluate (if True (default), all floats are turn into) – exact types.

  • dim (number of coordinates the point should have. If coordinates) – are unspecified, they are padded with zeros.

  • on_morph (indicates what should happen when the number of) – coordinates of a point need to be changed by adding or removing zeros. Possible values are ‘warn’, ‘error’, or ignore (default). No warning or error is given when *args is empty and dim is given. An error is always raised when trying to remove nonzero coordinates.

length
origin

appropriately-dimensioned space.

Type:

A Point representing the origin of the

:raises TypeError : When instantiating with anything but a Point or sequence: :raises ValueError : when instantiating with a sequence with length < 2 or: when trying to reduce dimensions if keyword on_morph=’error’ is set.

See also

sympy.geometry.line.Segment

Connects two Points

Examples

>>> from ..geometry import Point
>>> from ..abc import x
>>> Point(1, 2, 3)
Point3D(1, 2, 3)
>>> Point([1, 2])
Point2D(1, 2)
>>> Point(0, x)
Point2D(0, x)
>>> Point(dim=4)
Point(0, 0, 0, 0)

Floats are automatically converted to Rational unless the evaluate flag is False:

>>> Point(0.5, 0.25)
Point2D(1/2, 1/4)
>>> Point(0.5, 0.25, evaluate=False)
Point2D(0.5, 0.25)
static affine_rank(*args)[source]

The affine rank of a set of points is the dimension of the smallest affine space containing all the points. For example, if the points lie on a line (and are not all the same) their affine rank is 1. If the points lie on a plane but not a line, their affine rank is 2. By convention, the empty set has affine rank -1.

property ambient_dimension

Number of components this point has.

classmethod are_coplanar(*points)[source]

Return True if there exists a plane in which all the points lie. A trivial True value is returned if len(points) < 3 or all Points are 2-dimensional.

Parameters:

points (A set of) –

:raises ValueError : if less than 3 unique points are given:

Return type:

boolean

Examples

>>> from .. import Point3D
>>> p1 = Point3D(1, 2, 2)
>>> p2 = Point3D(2, 7, 2)
>>> p3 = Point3D(0, 0, 2)
>>> p4 = Point3D(1, 1, 2)
>>> Point3D.are_coplanar(p1, p2, p3, p4)
True
>>> p5 = Point3D(0, 1, 3)
>>> Point3D.are_coplanar(p1, p2, p3, p5)
False
canberra_distance(p)[source]

The Canberra Distance from self to point p.

Returns the weighted sum of horizontal and vertical distances to point p.

Parameters:

p (Point) –

Returns:

  • canberra_distance (The weighted sum of horizontal and vertical)

  • distances to point p. The weight used is the sum of absolute values

  • of the coordinates.

See also

sympy.geometry.point.Point.distance

Examples

>>> from ..geometry import Point
>>> p1, p2 = Point(1, 1), Point(3, 3)
>>> p1.canberra_distance(p2)
1
>>> p1, p2 = Point(0, 0), Point(3, 3)
>>> p1.canberra_distance(p2)
2
Raises:

ValueError when both vectors are zero.

See also

sympy.geometry.point.Point.distance

default_assumptions = {}
distance(p)[source]

The Euclidean distance from self to point p.

Parameters:

p (Point) –

Returns:

distance

Return type:

number or symbolic expression.

See also

sympy.geometry.line.Segment.length, sympy.geometry.point.Point.taxicab_distance

Examples

>>> from ..geometry import Point
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> p1.distance(p2)
5
>>> from ..abc import x, y
>>> p3 = Point(x, y)
>>> p3.distance(Point(0, 0))
sqrt(x**2 + y**2)
dot(p)[source]

Return dot product of self with another Point.

equals(other)[source]

Returns whether the coordinates of self and other agree.

evalf(prec=None, **options)[source]

Evaluate the coordinates of the point.

This method will, where possible, create and return a new Point where the coordinates are evaluated as floating point numbers to the precision indicated (default=15).

Parameters:

prec (int) –

Returns:

point

Return type:

Point

Examples

>>> from .. import Point, Rational
>>> p1 = Point(Rational(1, 2), Rational(3, 2))
>>> p1
Point2D(1/2, 3/2)
>>> p1.evalf()
Point2D(0.5, 1.5)
intersection(other)[source]

The intersection between this point and another GeometryEntity.

Parameters:

other (Point) –

Returns:

intersection

Return type:

list of Points

Notes

The return value will either be an empty list if there is no intersection, otherwise it will contain this point.

Examples

>>> from .. import Point
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point2D(0, 0)]
is_Point = True
is_collinear(*args)[source]

Returns True if there exists a line that contains self and points. Returns False otherwise. A trivially True value is returned if no points are given.

Parameters:

args (sequence of Points) –

Returns:

is_collinear

Return type:

boolean

See also

sympy.geometry.line.Line

Examples

>>> from .. import Point
>>> from ..abc import x
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4, p5 = Point(2, 2), Point(x, x), Point(1, 2)
>>> Point.is_collinear(p1, p2, p3, p4)
True
>>> Point.is_collinear(p1, p2, p3, p5)
False
is_concyclic(*args)[source]

Do self and the given sequence of points lie in a circle?

Returns True if the set of points are concyclic and False otherwise. A trivial value of True is returned if there are fewer than 2 other points.

Parameters:

args (sequence of Points) –

Returns:

is_concyclic

Return type:

boolean

Examples

>>> from .. import Point

Define 4 points that are on the unit circle:

>>> p1, p2, p3, p4 = Point(1, 0), (0, 1), (-1, 0), (0, -1)
>>> p1.is_concyclic() == p1.is_concyclic(p2, p3, p4) == True
True

Define a point not on that circle:

>>> p = Point(1, 1)
>>> p.is_concyclic(p1, p2, p3)
False
property is_nonzero

True if any coordinate is nonzero, False if every coordinate is zero, and None if it cannot be determined.

is_scalar_multiple(p)[source]

Returns whether each coordinate of self is a scalar multiple of the corresponding coordinate in point p.

property is_zero

True if every coordinate is zero, False if any coordinate is not zero, and None if it cannot be determined.

property length

Treating a Point as a Line, this returns 0 for the length of a Point.

Examples

>>> from .. import Point
>>> p = Point(0, 1)
>>> p.length
0
midpoint(p)[source]

The midpoint between self and point p.

Parameters:

p (Point) –

Returns:

midpoint

Return type:

Point

See also

sympy.geometry.line.Segment.midpoint

Examples

>>> from ..geometry import Point
>>> p1, p2 = Point(1, 1), Point(13, 5)
>>> p1.midpoint(p2)
Point2D(7, 3)
n(prec=None, **options)

Evaluate the coordinates of the point.

This method will, where possible, create and return a new Point where the coordinates are evaluated as floating point numbers to the precision indicated (default=15).

Parameters:

prec (int) –

Returns:

point

Return type:

Point

Examples

>>> from .. import Point, Rational
>>> p1 = Point(Rational(1, 2), Rational(3, 2))
>>> p1
Point2D(1/2, 3/2)
>>> p1.evalf()
Point2D(0.5, 1.5)
property origin

A point of all zeros of the same ambient dimension as the current point

property orthogonal_direction

Returns a non-zero point that is orthogonal to the line containing self and the origin.

Examples

>>> from ..geometry import Line, Point
>>> a = Point(1, 2, 3)
>>> a.orthogonal_direction
Point3D(-2, 1, 0)
>>> b = _
>>> Line(b, b.origin).is_perpendicular(Line(a, a.origin))
True
static project(a, b)[source]

Project the point a onto the line between the origin and point b along the normal direction.

Parameters:
Returns:

p

Return type:

Point

See also

sympy.geometry.line.LinearEntity.projection

Examples

>>> from ..geometry import Line, Point
>>> a = Point(1, 2)
>>> b = Point(2, 5)
>>> z = a.origin
>>> p = Point.project(a, b)
>>> Line(p, a).is_perpendicular(Line(p, b))
True
>>> Point.is_collinear(z, p, b)
True
taxicab_distance(p)[source]

The Taxicab Distance from self to point p.

Returns the sum of the horizontal and vertical distances to point p.

Parameters:

p (Point) –

Returns:

  • taxicab_distance (The sum of the horizontal)

  • and vertical distances to point p.

See also

sympy.geometry.point.Point.distance

Examples

>>> from ..geometry import Point
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> p1.taxicab_distance(p2)
7
property unit

Return the Point that is in the same direction as self and a distance of 1 from the origin

class modelparameters.sympy.geometry.point.Point2D(*args, **kwargs)[source]

Bases: Point

A point in a 2-dimensional Euclidean space.

Parameters:

coords (sequence of 2 coordinate values.) –

x
y
length
Raises:

TypeError – When trying to add or subtract points with different dimensions. When trying to create a point with more than two dimensions. When intersection is called with object other than a Point.

See also

sympy.geometry.line.Segment

Connects two Points

Examples

>>> from ..geometry import Point2D
>>> from ..abc import x
>>> Point2D(1, 2)
Point2D(1, 2)
>>> Point2D([1, 2])
Point2D(1, 2)
>>> Point2D(0, x)
Point2D(0, x)

Floats are automatically converted to Rational unless the evaluate flag is False:

>>> Point2D(0.5, 0.25)
Point2D(1/2, 1/4)
>>> Point2D(0.5, 0.25, evaluate=False)
Point2D(0.5, 0.25)
property bounds

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

default_assumptions = {}
rotate(angle, pt=None)[source]

Rotate angle radians counterclockwise about Point pt.

See also

rotate, scale

Examples

>>> from .. import Point2D, pi
>>> t = Point2D(1, 0)
>>> t.rotate(pi/2)
Point2D(0, 1)
>>> t.rotate(pi/2, (2, 0))
Point2D(2, -1)
scale(x=1, y=1, pt=None)[source]

Scale the coordinates of the Point by multiplying by x and y after subtracting pt – default is (0, 0) – and then adding pt back again (i.e. pt is the point of reference for the scaling).

See also

rotate, translate

Examples

>>> from .. import Point2D
>>> t = Point2D(1, 1)
>>> t.scale(2)
Point2D(2, 1)
>>> t.scale(2, 2)
Point2D(2, 2)
transform(matrix)[source]

Return the point after applying the transformation described by the 3x3 Matrix, matrix.

See also

geometry.entity.rotate, geometry.entity.scale, geometry.entity.translate

translate(x=0, y=0)[source]

Shift the Point by adding x and y to the coordinates of the Point.

See also

rotate, scale

Examples

>>> from .. import Point2D
>>> t = Point2D(0, 1)
>>> t.translate(2)
Point2D(2, 1)
>>> t.translate(2, 2)
Point2D(2, 3)
>>> t + Point2D(2, 2)
Point2D(2, 3)
property x

Returns the X coordinate of the Point.

Examples

>>> from .. import Point2D
>>> p = Point2D(0, 1)
>>> p.x
0
property y

Returns the Y coordinate of the Point.

Examples

>>> from .. import Point2D
>>> p = Point2D(0, 1)
>>> p.y
1
class modelparameters.sympy.geometry.point.Point3D(*args, **kwargs)[source]

Bases: Point

A point in a 3-dimensional Euclidean space.

Parameters:

coords (sequence of 3 coordinate values.) –

x
y
z
length
Raises:

TypeError – When trying to add or subtract points with different dimensions. When intersection is called with object other than a Point.

Examples

>>> from .. import Point3D
>>> from ..abc import x
>>> Point3D(1, 2, 3)
Point3D(1, 2, 3)
>>> Point3D([1, 2, 3])
Point3D(1, 2, 3)
>>> Point3D(0, x, 3)
Point3D(0, x, 3)

Floats are automatically converted to Rational unless the evaluate flag is False:

>>> Point3D(0.5, 0.25, 2)
Point3D(1/2, 1/4, 2)
>>> Point3D(0.5, 0.25, 3, evaluate=False)
Point3D(0.5, 0.25, 3)
static are_collinear(*points)[source]

Is a sequence of points collinear?

Test whether or not a set of points are collinear. Returns True if the set of points are collinear, or False otherwise.

Parameters:

points (sequence of Point) –

Returns:

are_collinear

Return type:

boolean

See also

sympy.geometry.line.Line3D

Examples

>>> from .. import Point3D, Matrix
>>> from ..abc import x
>>> p1, p2 = Point3D(0, 0, 0), Point3D(1, 1, 1)
>>> p3, p4, p5 = Point3D(2, 2, 2), Point3D(x, x, x), Point3D(1, 2, 6)
>>> Point3D.are_collinear(p1, p2, p3, p4)
True
>>> Point3D.are_collinear(p1, p2, p3, p5)
False
default_assumptions = {}
direction_cosine(point)[source]

Gives the direction cosine between 2 points

Parameters:

p (Point3D) –

Return type:

list

Examples

>>> from .. import Point3D
>>> p1 = Point3D(1, 2, 3)
>>> p1.direction_cosine(Point3D(2, 3, 5))
[sqrt(6)/6, sqrt(6)/6, sqrt(6)/3]
direction_ratio(point)[source]

Gives the direction ratio between 2 points

Parameters:

p (Point3D) –

Return type:

list

Examples

>>> from .. import Point3D
>>> p1 = Point3D(1, 2, 3)
>>> p1.direction_ratio(Point3D(2, 3, 5))
[1, 1, 2]
intersection(other)[source]

The intersection between this point and another point.

Parameters:

other (Point) –

Returns:

intersection

Return type:

list of Points

Notes

The return value will either be an empty list if there is no intersection, otherwise it will contain this point.

Examples

>>> from .. import Point3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point3D(0, 0, 0)]
scale(x=1, y=1, z=1, pt=None)[source]

Scale the coordinates of the Point by multiplying by x and y after subtracting pt – default is (0, 0) – and then adding pt back again (i.e. pt is the point of reference for the scaling).

See also

translate

Examples

>>> from .. import Point3D
>>> t = Point3D(1, 1, 1)
>>> t.scale(2)
Point3D(2, 1, 1)
>>> t.scale(2, 2)
Point3D(2, 2, 1)
transform(matrix)[source]

Return the point after applying the transformation described by the 4x4 Matrix, matrix.

See also

geometry.entity.rotate, geometry.entity.scale, geometry.entity.translate

translate(x=0, y=0, z=0)[source]

Shift the Point by adding x and y to the coordinates of the Point.

See also

rotate, scale

Examples

>>> from .. import Point3D
>>> t = Point3D(0, 1, 1)
>>> t.translate(2)
Point3D(2, 1, 1)
>>> t.translate(2, 2)
Point3D(2, 3, 1)
>>> t + Point3D(2, 2, 2)
Point3D(2, 3, 3)
property x

Returns the X coordinate of the Point.

Examples

>>> from .. import Point3D
>>> p = Point3D(0, 1, 3)
>>> p.x
0
property y

Returns the Y coordinate of the Point.

Examples

>>> from .. import Point3D
>>> p = Point3D(0, 1, 2)
>>> p.y
1
property z

Returns the Z coordinate of the Point.

Examples

>>> from .. import Point3D
>>> p = Point3D(0, 1, 1)
>>> p.z
1

modelparameters.sympy.geometry.polygon module

class modelparameters.sympy.geometry.polygon.Polygon(*args, **kwargs)[source]

Bases: GeometrySet

A two-dimensional polygon.

A simple polygon in space. Can be constructed from a sequence of points or from a center, radius, number of sides and rotation angle.

Parameters:

vertices (sequence of Points) –

area
angles
perimeter
vertices
centroid
sides
Raises:

GeometryError – If all parameters are not Points. If the Polygon has intersecting sides.

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment, Triangle

Notes

Polygons are treated as closed paths rather than 2D areas so some calculations can be be negative or positive (e.g., area) based on the orientation of the points.

Any consecutive identical points are reduced to a single point and any points collinear and between two points will be removed unless they are needed to define an explicit intersection (see examples).

A Triangle, Segment or Point will be returned when there are 3 or fewer points provided.

Examples

>>> from .. import Point, Polygon, pi
>>> p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
>>> Polygon(p1, p2, p3, p4)
Polygon(Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1))
>>> Polygon(p1, p2)
Segment2D(Point2D(0, 0), Point2D(1, 0))
>>> Polygon(p1, p2, p5)
Segment2D(Point2D(0, 0), Point2D(3, 0))

While the sides of a polygon are not allowed to cross implicitly, they can do so explicitly. For example, a polygon shaped like a Z with the top left connecting to the bottom right of the Z must have the point in the middle of the Z explicitly given:

>>> mid = Point(1, 1)
>>> Polygon((0, 2), (2, 2), mid, (0, 0), (2, 0), mid).area
0
>>> Polygon((0, 2), (2, 2), mid, (2, 0), (0, 0), mid).area
-2

When the the keyword n is used to define the number of sides of the Polygon then a RegularPolygon is created and the other arguments are interpreted as center, radius and rotation. The unrotated RegularPolygon will always have a vertex at Point(r, 0) where r is the radius of the circle that circumscribes the RegularPolygon. Its method spin can be used to increment that angle.

>>> p = Polygon((0,0), 1, n=3)
>>> p
RegularPolygon(Point2D(0, 0), 1, 3, 0)
>>> p.vertices[0]
Point2D(1, 0)
>>> p.args[0]
Point2D(0, 0)
>>> p.spin(pi/2)
>>> p.vertices[0]
Point2D(0, 1)
property angles

The internal angle at each vertex.

Returns:

angles – A dictionary where each key is a vertex and each value is the internal angle at that vertex. The vertices are represented as Points.

Return type:

dict

See also

sympy.geometry.point.Point, sympy.geometry.line.LinearEntity.angle_between

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.angles[p1]
pi/2
>>> poly.angles[p2]
acos(-4*sqrt(17)/17)
arbitrary_point(parameter='t')[source]

A parameterized point on the polygon.

The parameter, varying from 0 to 1, assigns points to the position on the perimeter that is that fraction of the total perimeter. So the point evaluated at t=1/2 would return the point from the first vertex that is 1/2 way around the polygon.

Parameters:

parameter (str, optional) – Default value is ‘t’.

Returns:

arbitrary_point

Return type:

Point

Raises:

ValueError – When parameter already appears in the Polygon’s definition.

See also

sympy.geometry.point.Point

Examples

>>> from .. import Polygon, S, Symbol
>>> t = Symbol('t', real=True)
>>> tri = Polygon((0, 0), (1, 0), (1, 1))
>>> p = tri.arbitrary_point('t')
>>> perimeter = tri.perimeter
>>> s1, s2 = [s.length for s in tri.sides[:2]]
>>> p.subs(t, (s1 + s2/2)/perimeter)
Point2D(1, 1/2)
property area

The area of the polygon.

Notes

The area calculation can be positive or negative based on the orientation of the points.

See also

sympy.geometry.ellipse.Ellipse.area

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.area
3
property bounds

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

property centroid

The centroid of the polygon.

Returns:

centroid

Return type:

Point

See also

sympy.geometry.point.Point, sympy.geometry.util.centroid

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.centroid
Point2D(31/18, 11/18)
default_assumptions = {}
distance(o)[source]

Returns the shortest distance between self and o.

If o is a point, then self does not need to be convex. If o is another polygon self and o must be complex.

Examples

>>> from .. import Point, Polygon, RegularPolygon
>>> p1, p2 = map(Point, [(0, 0), (7, 5)])
>>> poly = Polygon(*RegularPolygon(p1, 1, 3).vertices)
>>> poly.distance(p2)
sqrt(61)
encloses_point(p)[source]

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

Return type:

True, False or None

See also

sympy.geometry.point.Point, sympy.geometry.ellipse.Ellipse.encloses_point

Examples

>>> from .. import Polygon, Point
>>> from ..abc import t
>>> p = Polygon((0, 0), (4, 0), (4, 4))
>>> p.encloses_point(Point(2, 1))
True
>>> p.encloses_point(Point(2, 2))
False
>>> p.encloses_point(Point(5, 5))
False

References

[1] http://paulbourke.net/geometry/polygonmesh/#insidepoly

intersection(o)[source]

The intersection of polygon and geometry entity.

The intersection may be empty and can contain individual Points and complete Line Segments.

Parameters:

other (GeometryEntity) –

Returns:

intersection – The list of Segments and Points

Return type:

list

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment

Examples

>>> from .. import Point, Polygon, Line
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly1 = Polygon(p1, p2, p3, p4)
>>> p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
>>> poly2 = Polygon(p5, p6, p7)
>>> poly1.intersection(poly2)
[Point2D(1/3, 1), Point2D(2/3, 0), Point2D(9/5, 1/5), Point2D(7/3, 1)]
>>> poly1.intersection(Line(p1, p2))
[Segment2D(Point2D(0, 0), Point2D(1, 0))]
>>> poly1.intersection(p1)
[Point2D(0, 0)]
is_convex()[source]

Is the polygon convex?

A polygon is convex if all its interior angles are less than 180 degrees.

Returns:

is_convex – True if this polygon is convex, False otherwise.

Return type:

boolean

See also

sympy.geometry.util.convex_hull

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.is_convex()
True
property perimeter

The perimeter of the polygon.

Returns:

perimeter

Return type:

number or Basic instance

See also

sympy.geometry.line.Segment.length

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.perimeter
sqrt(17) + 7
plot_interval(parameter='t')[source]

The plot interval for the default geometric plot of the polygon.

Parameters:

parameter (str, optional) – Default value is ‘t’.

Returns:

plot_interval – [parameter, lower_bound, upper_bound]

Return type:

list (plot interval)

Examples

>>> from .. import Polygon
>>> p = Polygon((0, 0), (1, 0), (1, 1))
>>> p.plot_interval()
[t, 0, 1]
property sides

The line segments that form the sides of the polygon.

Returns:

sides – Each side is a Segment.

Return type:

list of sides

Notes

The Segments that represent the sides are an undirected line segment so cannot be used to tell the orientation of the polygon.

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.sides
[Segment2D(Point2D(0, 0), Point2D(1, 0)),
Segment2D(Point2D(1, 0), Point2D(5, 1)),
Segment2D(Point2D(0, 1), Point2D(5, 1)), Segment2D(Point2D(0, 0), Point2D(0, 1))]
property vertices

The vertices of the polygon.

Returns:

vertices

Return type:

list of Points

Notes

When iterating over the vertices, it is more efficient to index self rather than to request the vertices and index them. Only use the vertices when you want to process all of them at once. This is even more important with RegularPolygons that calculate each vertex.

See also

sympy.geometry.point.Point

Examples

>>> from .. import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.vertices
[Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1)]
>>> poly.vertices[0]
Point2D(0, 0)
class modelparameters.sympy.geometry.polygon.RegularPolygon(c, r, n, rot=0, **kwargs)[source]

Bases: Polygon

A regular polygon.

Such a polygon has all internal angles equal and all sides the same length.

Parameters:
  • center (Point) –

  • radius (number or Basic instance) – The distance from the center to a vertex

  • n (int) – The number of sides

vertices
center
radius
rotation
apothem
interior_angle
exterior_angle
circumcircle
incircle
angles
Raises:

GeometryError – If the center is not a Point, or the radius is not a number or Basic instance, or the number of sides, n, is less than three.

Notes

A RegularPolygon can be instantiated with Polygon with the kwarg n.

Regular polygons are instantiated with a center, radius, number of sides and a rotation angle. Whereas the arguments of a Polygon are vertices, the vertices of the RegularPolygon must be obtained with the vertices method.

See also

sympy.geometry.point.Point, Polygon

Examples

>>> from ..geometry import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r
RegularPolygon(Point2D(0, 0), 5, 3, 0)
>>> r.vertices[0]
Point2D(5, 0)
property angles

Returns a dictionary with keys, the vertices of the Polygon, and values, the interior angle at each vertex.

Examples

>>> from .. import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.angles
{Point2D(-5/2, -5*sqrt(3)/2): pi/3,
 Point2D(-5/2, 5*sqrt(3)/2): pi/3,
 Point2D(5, 0): pi/3}
property apothem

The inradius of the RegularPolygon.

The apothem/inradius is the radius of the inscribed circle.

Returns:

apothem

Return type:

number or instance of Basic

See also

sympy.geometry.line.Segment.length, sympy.geometry.ellipse.Circle.radius

Examples

>>> from .. import Symbol
>>> from ..geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.apothem
sqrt(2)*r/2
property area

Returns the area.

Examples

>>> from ..geometry import RegularPolygon
>>> square = RegularPolygon((0, 0), 1, 4)
>>> square.area
2
>>> _ == square.length**2
True
property args

Returns the center point, the radius, the number of sides, and the orientation angle.

Examples

>>> from .. import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.args
(Point2D(0, 0), 5, 3, 0)
property center

The center of the RegularPolygon

This is also the center of the circumscribing circle.

Returns:

center

Return type:

Point

See also

sympy.geometry.point.Point, sympy.geometry.ellipse.Ellipse.center

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point2D(0, 0)
property centroid

The center of the RegularPolygon

This is also the center of the circumscribing circle.

Returns:

center

Return type:

Point

See also

sympy.geometry.point.Point, sympy.geometry.ellipse.Ellipse.center

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point2D(0, 0)
property circumcenter

Alias for center.

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.circumcenter
Point2D(0, 0)
property circumcircle

The circumcircle of the RegularPolygon.

Returns:

circumcircle

Return type:

Circle

See also

circumcenter, sympy.geometry.ellipse.Circle

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.circumcircle
Circle(Point2D(0, 0), 4)
property circumradius

Alias for radius.

Examples

>>> from .. import Symbol
>>> from ..geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.circumradius
r
default_assumptions = {}
encloses_point(p)[source]

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

Notes

Being on the border of self is considered False.

The general Polygon.encloses_point method is called only if a point is not within or beyond the incircle or circumcircle, respectively.

Parameters:

p (Point) –

Returns:

encloses_point

Return type:

True, False or None

See also

sympy.geometry.ellipse.Ellipse.encloses_point

Examples

>>> from .. import RegularPolygon, S, Point, Symbol
>>> p = RegularPolygon((0, 0), 3, 4)
>>> p.encloses_point(Point(0, 0))
True
>>> r, R = p.inradius, p.circumradius
>>> p.encloses_point(Point((r + R)/2, 0))
True
>>> p.encloses_point(Point(R/2, R/2 + (R - r)/10))
False
>>> t = Symbol('t', real=True)
>>> p.encloses_point(p.arbitrary_point().subs(t, S.Half))
False
>>> p.encloses_point(Point(5, 5))
False
property exterior_angle

Measure of the exterior angles.

Returns:

exterior_angle

Return type:

number

See also

sympy.geometry.line.LinearEntity.angle_between

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.exterior_angle
pi/4
property incircle

The incircle of the RegularPolygon.

Returns:

incircle

Return type:

Circle

See also

inradius, sympy.geometry.ellipse.Circle

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 7)
>>> rp.incircle
Circle(Point2D(0, 0), 4*cos(pi/7))
property inradius

Alias for apothem.

Examples

>>> from .. import Symbol
>>> from ..geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.inradius
sqrt(2)*r/2
property interior_angle

Measure of the interior angles.

Returns:

interior_angle

Return type:

number

See also

sympy.geometry.line.LinearEntity.angle_between

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.interior_angle
3*pi/4
property length

Returns the length of the sides.

The half-length of the side and the apothem form two legs of a right triangle whose hypotenuse is the radius of the regular polygon.

Examples

>>> from ..geometry import RegularPolygon
>>> from .. import sqrt
>>> s = square_in_unit_circle = RegularPolygon((0, 0), 1, 4)
>>> s.length
sqrt(2)
>>> sqrt((_/2)**2 + s.apothem**2) == s.radius
True
property radius

Radius of the RegularPolygon

This is also the radius of the circumscribing circle.

Returns:

radius

Return type:

number or instance of Basic

See also

sympy.geometry.line.Segment.length, sympy.geometry.ellipse.Circle.radius

Examples

>>> from .. import Symbol
>>> from ..geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.radius
r
reflect(line)[source]

Override GeometryEntity.reflect since this is not made of only points.

>>> from .. import RegularPolygon, Line
>>> RegularPolygon((0, 0), 1, 4).reflect(Line((0, 1), slope=-2))
RegularPolygon(Point2D(4/5, 2/5), -1, 4, acos(3/5))
rotate(angle, pt=None)[source]

Override GeometryEntity.rotate to first rotate the RegularPolygon about its center.

>>> from .. import Point, RegularPolygon, Polygon, pi
>>> t = RegularPolygon(Point(1, 0), 1, 3)
>>> t.vertices[0] # vertex on x-axis
Point2D(2, 0)
>>> t.rotate(pi/2).vertices[0] # vertex on y axis now
Point2D(0, 2)

See also

rotation

spin

Rotates a RegularPolygon in place

property rotation

CCW angle by which the RegularPolygon is rotated

Returns:

rotation

Return type:

number or instance of Basic

Examples

>>> from .. import pi
>>> from ..geometry import RegularPolygon, Point
>>> RegularPolygon(Point(0, 0), 3, 4, pi).rotation
pi
scale(x=1, y=1, pt=None)[source]

Override GeometryEntity.scale since it is the radius that must be scaled (if x == y) or else a new Polygon must be returned.

>>> from .. import RegularPolygon

Symmetric scaling returns a RegularPolygon:

>>> RegularPolygon((0, 0), 1, 4).scale(2, 2)
RegularPolygon(Point2D(0, 0), 2, 4, 0)

Asymmetric scaling returns a kite as a Polygon:

>>> RegularPolygon((0, 0), 1, 4).scale(2, 1)
Polygon(Point2D(2, 0), Point2D(0, 1), Point2D(-2, 0), Point2D(0, -1))
spin(angle)[source]

Increment in place the virtual Polygon’s rotation by ccw angle.

See also: rotate method which moves the center.

>>> from .. import Polygon, Point, pi
>>> r = Polygon(Point(0,0), 1, n=3)
>>> r.vertices[0]
Point2D(1, 0)
>>> r.spin(pi/6)
>>> r.vertices[0]
Point2D(sqrt(3)/2, 1/2)

See also

rotation

rotate

Creates a copy of the RegularPolygon rotated about a Point

property vertices

The vertices of the RegularPolygon.

Returns:

vertices – Each vertex is a Point.

Return type:

list

See also

sympy.geometry.point.Point

Examples

>>> from ..geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.vertices
[Point2D(5, 0), Point2D(0, 5), Point2D(-5, 0), Point2D(0, -5)]
class modelparameters.sympy.geometry.polygon.Triangle(*args, **kwargs)[source]

Bases: Polygon

A polygon with three vertices and three sides.

Parameters:
  • points (sequence of Points) –

  • keyword (asa, sas, or sss to specify sides/angles of the triangle) –

vertices
altitudes
orthocenter
circumcenter
circumradius
circumcircle
inradius
incircle
medians
medial
nine_point_circle
Raises:

GeometryError – If the number of vertices is not equal to three, or one of the vertices is not a Point, or a valid keyword is not given.

See also

sympy.geometry.point.Point, Polygon

Examples

>>> from ..geometry import Triangle, Point
>>> Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
Triangle(Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))

Keywords sss, sas, or asa can be used to give the desired side lengths (in order) and interior angles (in degrees) that define the triangle:

>>> Triangle(sss=(3, 4, 5))
Triangle(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
>>> Triangle(asa=(30, 1, 30))
Triangle(Point2D(0, 0), Point2D(1, 0), Point2D(1/2, sqrt(3)/6))
>>> Triangle(sas=(1, 45, 2))
Triangle(Point2D(0, 0), Point2D(2, 0), Point2D(sqrt(2)/2, sqrt(2)/2))
property altitudes

The altitudes of the triangle.

An altitude of a triangle is a segment through a vertex, perpendicular to the opposite side, with length being the height of the vertex measured from the line containing the side.

Returns:

altitudes – The dictionary consists of keys which are vertices and values which are Segments.

Return type:

dict

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment.length

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.altitudes[p1]
Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))
bisectors()[source]

The angle bisectors of the triangle.

An angle bisector of a triangle is a straight line through a vertex which cuts the corresponding angle in half.

Returns:

bisectors – Each key is a vertex (Point) and each value is the corresponding bisector (Segment).

Return type:

dict

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment

Examples

>>> from ..geometry import Point, Triangle, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> from .. import sqrt
>>> t.bisectors()[p2] == Segment(Point(0, sqrt(2) - 1), Point(1, 0))
True
property circumcenter

The circumcenter of the triangle

The circumcenter is the center of the circumcircle.

Returns:

circumcenter

Return type:

Point

See also

sympy.geometry.point.Point

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcenter
Point2D(1/2, 1/2)
property circumcircle

The circle which passes through the three vertices of the triangle.

Returns:

circumcircle

Return type:

Circle

See also

sympy.geometry.ellipse.Circle

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcircle
Circle(Point2D(1/2, 1/2), sqrt(2)/2)
property circumradius

The radius of the circumcircle of the triangle.

Returns:

circumradius

Return type:

number of Basic instance

See also

sympy.geometry.ellipse.Circle.radius

Examples

>>> from .. import Symbol
>>> from ..geometry import Point, Triangle
>>> a = Symbol('a')
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, a)
>>> t = Triangle(p1, p2, p3)
>>> t.circumradius
sqrt(a**2/4 + 1/4)
default_assumptions = {}
property eulerline

The Euler line of the triangle.

The line which passes through circumcenter, centroid and orthocenter.

Returns:

eulerline – centers coincide)

Return type:

Line (or Point for equilateral triangles in which case all

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.eulerline
Line2D(Point2D(0, 0), Point2D(1/2, 1/2))
property incenter

The center of the incircle.

The incircle is the circle which lies inside the triangle and touches all three sides.

Returns:

incenter

Return type:

Point

See also

incircle, sympy.geometry.point.Point

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.incenter
Point2D(-sqrt(2)/2 + 1, -sqrt(2)/2 + 1)
property incircle

The incircle of the triangle.

The incircle is the circle which lies inside the triangle and touches all three sides.

Returns:

incircle

Return type:

Circle

See also

sympy.geometry.ellipse.Circle

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(2, 0), Point(0, 2)
>>> t = Triangle(p1, p2, p3)
>>> t.incircle
Circle(Point2D(-sqrt(2) + 2, -sqrt(2) + 2), -sqrt(2) + 2)
property inradius

The radius of the incircle.

Returns:

inradius

Return type:

number of Basic instance

See also

incircle, sympy.geometry.ellipse.Circle.radius

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(4, 0), Point(0, 3)
>>> t = Triangle(p1, p2, p3)
>>> t.inradius
1
is_equilateral()[source]

Are all the sides the same length?

Returns:

is_equilateral

Return type:

boolean

See also

sympy.geometry.entity.GeometryEntity.is_similar, RegularPolygon, is_isosceles, is_right, is_scalene

Examples

>>> from ..geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_equilateral()
False
>>> from .. import sqrt
>>> t2 = Triangle(Point(0, 0), Point(10, 0), Point(5, 5*sqrt(3)))
>>> t2.is_equilateral()
True
is_isosceles()[source]

Are two or more of the sides the same length?

Returns:

is_isosceles

Return type:

boolean

Examples

>>> from ..geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(2, 4))
>>> t1.is_isosceles()
True
is_right()[source]

Is the triangle right-angled.

Returns:

is_right

Return type:

boolean

See also

sympy.geometry.line.LinearEntity.is_perpendicular, is_equilateral, is_isosceles, is_scalene

Examples

>>> from ..geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_right()
True
is_scalene()[source]

Are all the sides of the triangle of different lengths?

Returns:

is_scalene

Return type:

boolean

Examples

>>> from ..geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(1, 4))
>>> t1.is_scalene()
True
is_similar(t2)[source]

Is another triangle similar to this one.

Two triangles are similar if one can be uniformly scaled to the other.

Parameters:

other (Triangle) –

Returns:

is_similar

Return type:

boolean

See also

sympy.geometry.entity.GeometryEntity.is_similar

Examples

>>> from ..geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -3))
>>> t1.is_similar(t2)
True
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -4))
>>> t1.is_similar(t2)
False
property medial

The medial triangle of the triangle.

The triangle which is formed from the midpoints of the three sides.

Returns:

medial

Return type:

Triangle

See also

sympy.geometry.line.Segment.midpoint

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medial
Triangle(Point2D(1/2, 0), Point2D(1/2, 1/2), Point2D(0, 1/2))
property medians

The medians of the triangle.

A median of a triangle is a straight line through a vertex and the midpoint of the opposite side, and divides the triangle into two equal areas.

Returns:

medians – Each key is a vertex (Point) and each value is the median (Segment) at that point.

Return type:

dict

See also

sympy.geometry.point.Point.midpoint, sympy.geometry.line.Segment.midpoint

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medians[p1]
Segment2D(Point2D(0, 0), Point2D(1/2, 1/2))
property nine_point_circle

The nine-point circle of the triangle.

Nine-point circle is the circumcircle of the medial triangle, which passes through the feet of altitudes and the middle points of segments connecting the vertices and the orthocenter.

Returns:

nine_point_circle

Return type:

Circle

See also

sympy.geometry.line.Segment.midpoint, sympy.geometry.polygon.Triangle.medial, sympy.geometry.polygon.Triangle.orthocenter

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.nine_point_circle
Circle(Point2D(1/4, 1/4), sqrt(2)/4)
property orthocenter

The orthocenter of the triangle.

The orthocenter is the intersection of the altitudes of a triangle. It may lie inside, outside or on the triangle.

Returns:

orthocenter

Return type:

Point

See also

sympy.geometry.point.Point

Examples

>>> from ..geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.orthocenter
Point2D(0, 0)
property vertices

The triangle’s vertices

Returns:

vertices – Each element in the tuple is a Point

Return type:

tuple

See also

sympy.geometry.point.Point

Examples

>>> from ..geometry import Triangle, Point
>>> t = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t.vertices
(Point2D(0, 0), Point2D(4, 0), Point2D(4, 3))
modelparameters.sympy.geometry.polygon.deg(r)[source]

Return the degree value for the given radians (pi = 180 degrees).

modelparameters.sympy.geometry.polygon.rad(d)[source]

Return the radian value for the given degrees (pi = 180 degrees).

modelparameters.sympy.geometry.util module

Utility functions for geometrical entities.

Contains

intersection convex_hull closest_points farthest_points are_coplanar are_similar

modelparameters.sympy.geometry.util.are_coplanar(*e)[source]

Returns True if the given entities are coplanar otherwise False

Parameters:

e (entities to be checked for being coplanar) –

Return type:

Boolean

Examples

>>> from .. import Point3D, Line3D
>>> from .util import are_coplanar
>>> a = Line3D(Point3D(5, 0, 0), Point3D(1, -1, 1))
>>> b = Line3D(Point3D(0, -2, 0), Point3D(3, 1, 1))
>>> c = Line3D(Point3D(0, -1, 0), Point3D(5, -1, 9))
>>> are_coplanar(a, b, c)
False
modelparameters.sympy.geometry.util.are_similar(e1, e2)[source]

Are two geometrical entities similar.

Can one geometrical entity be uniformly scaled to the other?

Parameters:
Returns:

are_similar

Return type:

boolean

Raises:

GeometryError – When e1 and e2 cannot be compared.

Notes

If the two objects are equal then they are similar.

See also

sympy.geometry.entity.GeometryEntity.is_similar

Examples

>>> from .. import Point, Circle, Triangle, are_similar
>>> c1, c2 = Circle(Point(0, 0), 4), Circle(Point(1, 4), 3)
>>> t1 = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
>>> t2 = Triangle(Point(0, 0), Point(2, 0), Point(0, 2))
>>> t3 = Triangle(Point(0, 0), Point(3, 0), Point(0, 1))
>>> are_similar(t1, t2)
True
>>> are_similar(t1, t3)
False
modelparameters.sympy.geometry.util.centroid(*args)[source]

Find the centroid (center of mass) of the collection containing only Points, Segments or Polygons. The centroid is the weighted average of the individual centroid where the weights are the lengths (of segments) or areas (of polygons). Overlapping regions will add to the weight of that region.

If there are no objects (or a mixture of objects) then None is returned.

See also

sympy.geometry.point.Point, sympy.geometry.line.Segment, sympy.geometry.polygon.Polygon

Examples

>>> from .. import Point, Segment, Polygon
>>> from .util import centroid
>>> p = Polygon((0, 0), (10, 0), (10, 10))
>>> q = p.translate(0, 20)
>>> p.centroid, q.centroid
(Point2D(20/3, 10/3), Point2D(20/3, 70/3))
>>> centroid(p, q)
Point2D(20/3, 40/3)
>>> p, q = Segment((0, 0), (2, 0)), Segment((0, 0), (2, 2))
>>> centroid(p, q)
Point2D(1, -sqrt(2) + 2)
>>> centroid(Point(0, 0), Point(2, 0))
Point2D(1, 0)

Stacking 3 polygons on top of each other effectively triples the weight of that polygon:

>>> p = Polygon((0, 0), (1, 0), (1, 1), (0, 1))
>>> q = Polygon((1, 0), (3, 0), (3, 1), (1, 1))
>>> centroid(p, q)
Point2D(3/2, 1/2)
>>> centroid(p, p, p, q) # centroid x-coord shifts left
Point2D(11/10, 1/2)

Stacking the squares vertically above and below p has the same effect:

>>> centroid(p, p.translate(0, 1), p.translate(0, -1), q)
Point2D(11/10, 1/2)
modelparameters.sympy.geometry.util.closest_points(*args)[source]

Return the subset of points from a set of points that were the closest to each other in the 2D plane.

Parameters:

args (a collection of Points on 2D plane.) –

Notes

This can only be performed on a set of points whose coordinates can be ordered on the number line. If there are no ties then a single pair of Points will be in the set.

References

[1] http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairPS.html

[2] Sweep line algorithm https://en.wikipedia.org/wiki/Sweep_line_algorithm

Examples

>>> from ..geometry import closest_points, Point2D, Triangle
>>> Triangle(sss=(3, 4, 5)).args
(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
>>> closest_points(*_)
{(Point2D(0, 0), Point2D(3, 0))}
modelparameters.sympy.geometry.util.convex_hull(*args, **kwargs)[source]

The convex hull surrounding the Points contained in the list of entities.

Parameters:

args (a collection of Points, Segments and/or Polygons) –

Returns:

convex_hull

Return type:

Polygon if polygon is True else as a tuple (U, L) where L and U are the lower and upper hulls, respectively.

Notes

This can only be performed on a set of points whose coordinates can be ordered on the number line.

References

[1] http://en.wikipedia.org/wiki/Graham_scan

[2] Andrew’s Monotone Chain Algorithm (A.M. Andrew, “Another Efficient Algorithm for Convex Hulls in Two Dimensions”, 1979) http://geomalgorithms.com/a10-_hull-1.html

See also

sympy.geometry.point.Point, sympy.geometry.polygon.Polygon

Examples

>>> from ..geometry import Point, convex_hull
>>> points = [(1, 1), (1, 2), (3, 1), (-5, 2), (15, 4)]
>>> convex_hull(*points)
Polygon(Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4))
>>> convex_hull(*points, **dict(polygon=False))
([Point2D(-5, 2), Point2D(15, 4)],
 [Point2D(-5, 2), Point2D(1, 1), Point2D(3, 1), Point2D(15, 4)])
modelparameters.sympy.geometry.util.farthest_points(*args)[source]

Return the subset of points from a set of points that were the furthest apart from each other in the 2D plane.

Parameters:

args (a collection of Points on 2D plane.) –

Notes

This can only be performed on a set of points whose coordinates can be ordered on the number line. If there are no ties then a single pair of Points will be in the set.

References

[1] http://code.activestate.com/recipes/117225-convex-hull-and-diameter-of-2d-point-sets/

[2] Rotating Callipers Technique https://en.wikipedia.org/wiki/Rotating_calipers

Examples

>>> from ..geometry import farthest_points, Point2D, Triangle
>>> Triangle(sss=(3, 4, 5)).args
(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
>>> farthest_points(*_)
{(Point2D(0, 0), Point2D(3, 4))}
modelparameters.sympy.geometry.util.idiff(eq, y, x, n=1)[source]

Return dy/dx assuming that eq == 0.

Parameters:
  • y (the dependent variable or a list of dependent variables (with y first)) –

  • x (the variable that the derivative is being taken with respect to) –

  • n (the order of the derivative (default is 1)) –

Examples

>>> from ..abc import x, y, a
>>> from .util import idiff
>>> circ = x**2 + y**2 - 4
>>> idiff(circ, y, x)
-x/y
>>> idiff(circ, y, x, 2).simplify()
-(x**2 + y**2)/y**3

Here, a is assumed to be independent of x:

>>> idiff(x + a + y, y, x)
-1

Now the x-dependence of a is made explicit by listing a after y in a list.

>>> idiff(x + a + y, [y, a], x)
-Derivative(a, x) - 1

See also

sympy.core.function.Derivative

represents unevaluated derivatives

sympy.core.function.diff

explicitly differentiates wrt symbols

modelparameters.sympy.geometry.util.intersection(*entities)[source]

The intersection of a collection of GeometryEntity instances.

Parameters:

entities (sequence of GeometryEntity) –

Returns:

intersection

Return type:

list of GeometryEntity

Raises:

NotImplementedError – When unable to calculate intersection.

Notes

The intersection of any geometrical entity with itself should return a list with one item: the entity in question. An intersection requires two or more entities. If only a single entity is given then the function will return an empty list. It is possible for intersection to miss intersections that one knows exists because the required quantities were not fully simplified internally. Reals should be converted to Rationals, e.g. Rational(str(real_num)) or else failures due to floating point issues may result.

See also

sympy.geometry.entity.GeometryEntity.intersection

Examples

>>> from ..geometry import Point, Line, Circle, intersection
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 5)
>>> l1, l2 = Line(p1, p2), Line(p3, p2)
>>> c = Circle(p2, 1)
>>> intersection(l1, p2)
[Point2D(1, 1)]
>>> intersection(l1, l2)
[Point2D(1, 1)]
>>> intersection(c, p2)
[]
>>> intersection(c, Point(1, 0))
[Point2D(1, 0)]
>>> intersection(c, l2)
[Point2D(-sqrt(5)/5 + 1, 2*sqrt(5)/5 + 1),
 Point2D(sqrt(5)/5 + 1, -2*sqrt(5)/5 + 1)]

Module contents

A geometry module for the SymPy library. This module contains all of the entities and functions needed to construct basic geometrical data and to perform simple informational queries.

Usage:

Examples