Points

class diofant.geometry.point.Point[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.

length
origin

appropriately-dimensioned space.

Type

A \(Point\) representing the origin of the

Raises

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

See also

diofant.geometry.line.Segment

Connects two Points

Examples

>>> Point(1, 2, 3)
Point3D(1, 2, 3)
>>> Point([1, 2])
Point2D(1, 2)
>>> Point(0, x)
Point2D(0, x)

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

>>> Point(0.5, 0.25)
Point2D(1/2, 1/4)
>>> print(Point(0.5, 0.25, evaluate=False))
Point2D(0.5, 0.25)
ambient_dimension

The dimension of the ambient space the point is in. I.e., if the point is in R^n, the ambient dimension will be n

distance(p)[source]

The Euclidean distance from self to point p.

Parameters

p (Point)

Returns

distance (number or symbolic expression.)

Examples

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

Return dot product of self with another Point.

equals(other)[source]

Returns whether the coordinates of self and other agree.

evalf(dps=15, **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 decimal precision dps.

Returns

point (Point)

Examples

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

The intersection between this point and another point.

Parameters

other (Point)

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

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

is_collinear (boolean)

Notes

Slope is preserved everywhere on a line, so the slope between any two points on the line should be the same. Take the first two points, p1 and p2, and create a translated point v1 with p1 as the origin. Now for every other point we create a translated point, vi with p1 also as the origin. Note that these translations preserve slope since everything is consistently translated to a new origin of p1. Since slope is preserved then we have the following equality:

  • v1_slope = vi_slope

  • v1.y/v1.x = vi.y/vi.x (due to translation)

  • v1.y*vi.x = vi.y*v1.x

  • v1.y*vi.x - vi.y*v1.x = 0 (*)

Hence, if we have a vi such that the equality in (*) is False then the points are not collinear. We do this test for every point in the list, and if all pass then they are collinear.

Examples

>>> 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_scalar_multiple(other)[source]

Returns whether \(self\) and \(other\) are scalar multiples of each other.

is_zero

True if every coordinate is zero, otherwise False.

length

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

Examples

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

The midpoint between self and point p.

Parameters

p (Point)

Returns

midpoint (Point)

Examples

>>> p1, p2 = Point(1, 1), Point(13, 5)
>>> p1.midpoint(p2)
Point2D(7, 3)
n(dps=15, **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 decimal precision dps.

Returns

point (Point)

Examples

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

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

class diofant.geometry.point.Point2D[source]

A point in a 2-dimensional Euclidean space.

Parameters

coords (sequence of 2 coordinate values.)

x
y
diofant.geometry.Point.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

diofant.geometry.line.Segment

Connects two Points

Examples

>>> 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)
>>> print(Point2D(0.5, 0.25, evaluate=False))
Point2D(0.5, 0.25)
bounds

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

is_concyclic()[source]

Is a sequence of points concyclic?

Test whether or not a sequence of points are concyclic (i.e., they lie on a circle).

Parameters

points (sequence of Points)

Returns

is_concyclic (boolean) – True if points are concyclic, False otherwise.

Notes

No points are not considered to be concyclic. One or two points are definitely concyclic and three points are conyclic iff they are not collinear.

For more than three points, create a circle from the first three points. If the circle cannot be created (i.e., they are collinear) then all of the points cannot be concyclic. If the circle is created successfully then simply check the remaining points for containment in the circle.

Examples

>>> p1, p2 = Point(-1, 0), Point(1, 0)
>>> p3, p4 = Point(0, 1), Point(-1, 2)
>>> Point.is_concyclic(p1, p2, p3)
True
>>> Point.is_concyclic(p1, p2, p3, p4)
False
rotate(angle, pt=None)[source]

Rotate angle radians counterclockwise about Point pt.

See also

rotate(), scale()

Examples

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

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

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

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

Returns the X coordinate of the Point.

Examples

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

Returns the Y coordinate of the Point.

Examples

>>> p = Point2D(0, 1)
>>> p.y
1
class diofant.geometry.point.Point3D[source]

A point in a 3-dimensional Euclidean space.

Parameters

coords (sequence of 3 coordinate values.)

x
y
z
diofant.geometry.Point.length
Raises

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

Notes

Currently only 2-dimensional and 3-dimensional points are supported.

Examples

>>> 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)
>>> print(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 (boolean)

Examples

>>> 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
static are_coplanar(*points)[source]

This function tests whether passed points are coplanar or not. It uses the fact that the triple scalar product of three vectors vanishes if the vectors are coplanar. Which means that the volume of the solid described by them will have to be zero for coplanarity.

Parameters

A set of points 3D points

Returns

boolean

Examples

>>> 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
direction_cosine(point)[source]

Gives the direction cosine between 2 points

Parameters

p (Point3D)

Returns

list

Examples

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

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

The intersection between this point and another point.

Parameters

other (Point)

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

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

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

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

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

Examples

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

Returns the X coordinate of the Point.

Examples

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

Returns the Y coordinate of the Point.

Examples

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

Returns the Z coordinate of the Point.

Examples

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