Points

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

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.

Raises

TypeError : When instantiating with anything but a Point or sequence

ValueError : when instantiating with a sequence with length < 2 or

when trying to reduce dimensions if keyword \(on_morph='error'\) is set.

Examples

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

See also

sympy.geometry.line.Segment

Connects two Points

Attributes

length

origin: A \(Point\) representing the origin of the

appropriately-dimensioned space.

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

A set of points

Returns

boolean

Raises

ValueError : if less than 3 unique points are given

Examples

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

Raises

ValueError when both vectors are zero.

Examples

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

The Euclidean distance between self and another GeometricEntity.

Returns

distance : number or symbolic expression.

Raises

TypeError : if other is not recognized as a GeometricEntity or is a

GeometricEntity for which distance is not defined.

Examples

>>> from sympy.geometry import Point, Line
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> l = Line((3, 1), (2, 2))
>>> p1.distance(p2)
5
>>> p1.distance(l)
sqrt(2)

The computed distance may be symbolic, too:

>>> from sympy.abc import x, y
>>> p3 = Point(x, y)
>>> p3.distance((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 : Point

Examples

>>> from sympy 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 : GeometryEntity or sequence of coordinates

Returns

intersection : 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 sympy import Point
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point2D(0, 0)]
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 : boolean

Examples

>>> from sympy import Point
>>> from sympy.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 : boolean

Examples

>>> from sympy 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 sympy import Point
>>> p = Point(0, 1)
>>> p.length
0
midpoint(p)[source]

The midpoint between self and point p.

Parameters

p : Point

Returns

midpoint : Point

Examples

>>> from sympy.geometry import Point
>>> p1, p2 = Point(1, 1), Point(13, 5)
>>> p1.midpoint(p2)
Point2D(7, 3)
n(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 : Point

Examples

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

a : Point

b : Point

Returns

p : Point

Examples

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

Examples

>>> from sympy.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 sympy.geometry.point.Point2D(*args, _nocheck=False, **kwargs)[source]

A point in a 2-dimensional Euclidean space.

Parameters

coords : sequence of 2 coordinate values.

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.

Examples

>>> from sympy.geometry import Point2D
>>> from sympy.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)

See also

sympy.geometry.line.Segment

Connects two Points

Attributes

x

y

length

property bounds

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

property coordinates

Returns the two coordinates of the Point.

Examples

>>> from sympy import Point2D
>>> p = Point2D(0, 1)
>>> p.coordinates
(0, 1)
rotate(angle, pt=None)[source]

Rotate angle radians counterclockwise about Point pt.

Examples

>>> from sympy import Point2D, pi
>>> t = Point2D(1, 0)
>>> t.rotate(pi/2)
Point2D(0, 1)
>>> t.rotate(pi/2, (2, 0))
Point2D(2, -1)

See also

translate, scale

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

Examples

>>> from sympy import Point2D
>>> t = Point2D(1, 1)
>>> t.scale(2)
Point2D(2, 1)
>>> t.scale(2, 2)
Point2D(2, 2)

See also

rotate, translate

transform(matrix)[source]

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

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

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

Examples

>>> from sympy 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 sympy import Point2D
>>> p = Point2D(0, 1)
>>> p.x
0
property y

Returns the Y coordinate of the Point.

Examples

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

A point in a 3-dimensional Euclidean space.

Parameters

coords : sequence of 3 coordinate values.

Raises

TypeError

When trying to add or subtract points with different dimensions. When \(intersection\) is called with object other than a Point.

Examples

>>> from sympy import Point3D
>>> from sympy.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)

Attributes

x

y

z

length

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

Examples

>>> from sympy import Point3D
>>> from sympy.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
property coordinates

Returns the three coordinates of the Point.

Examples

>>> from sympy import Point3D
>>> p = Point3D(0, 1, 2)
>>> p.coordinates
(0, 1, 2)
direction_cosine(point)[source]

Gives the direction cosine between 2 points

Parameters

p : Point3D

Returns

list

Examples

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

Returns

list

Examples

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

Parameters

other : GeometryEntity or sequence of coordinates

Returns

intersection : 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 sympy 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).

Examples

>>> from sympy import Point3D
>>> t = Point3D(1, 1, 1)
>>> t.scale(2)
Point3D(2, 1, 1)
>>> t.scale(2, 2)
Point3D(2, 2, 1)

See also

translate

transform(matrix)[source]

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

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

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

Examples

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

See also

scale

property x

Returns the X coordinate of the Point.

Examples

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

Returns the Y coordinate of the Point.

Examples

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

Returns the Z coordinate of the Point.

Examples

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