geo2d.geometry.Point

class geo2d.geometry.Point(*args)[source]

An abstract mathematical point.

It can be built by passing no parameters to the constructor, this way having the origin coordinates (0, 0), or by passing a Point, a tuple or a list of length two or even two scalar values.

Parameters :

*args : {two scalars, point-like}, optional

Point-like means that it can be either of tuple or list of length 2 (see ~`Point.is_point_like`).

Raises :

TypeError :

If the arguments are not the correct type (Point, list, tuple -of length 2- or two values) a TypeError is raised.

Attributes

x [scalar] Get the x coordinate.
y [scalar] Get the y coordinate.

Methods

__contains__(x) Searches for x in “itself”.
__eq__(point) Equality (==) operator for two points.
__getitem__(idx) Return values as a list for easier acces.
__len__() The length of a Point object is 2.
__lt__(point) Less than (<) operator for two points.
belongs_to(obj) Check if the Point is part of a GeometricObject.
distance_to(obj) Calculate the distance to another GeometricObject.
intersection(obj) Return points of intersection if any.
is_left(obj) Determine if self is left|on|right of an infinite Line or
is_point_like(obj) See if obj is of Point-like.
move(x, y) The difference between this and translate is that this
rotate(theta[, point, angle]) Rotate self by angle theta.
translate(dx, dy) See GeometricObject.translate.

Detailed description

class geo2d.geometry.Point(*args)[source]

An abstract mathematical point.

It can be built by passing no parameters to the constructor, this way having the origin coordinates (0, 0), or by passing a Point, a tuple or a list of length two or even two scalar values.

Parameters :

*args : {two scalars, point-like}, optional

Point-like means that it can be either of tuple or list of length 2 (see ~`Point.is_point_like`).

Raises :

TypeError :

If the arguments are not the correct type (Point, list, tuple -of length 2- or two values) a TypeError is raised.

__contains__(x)

Searches for x in “itself”. If we’re talking about a Point or a Vector then this searches within their components (x, y). For everything else it searches within the list of points (vertices).

Parameters :

x : {point, scalar}

The object to search for.

Returns :

out : {True, False}

True if we find x in self, else False.

__eq__(point)[source]

Equality (==) operator for two points.

Parameters :

point : {point-like}

The point to test against.

Returns :

res : {True, False}

If the x and y components of the points are equal then return True, else False.

Raises :

TypeError :

In case something other than Point-like is given.

__getitem__(idx)[source]

Return values as a list for easier acces.

__len__()[source]

The length of a Point object is 2.

__lt__(point)[source]

Less than (<) operator for two points.

Parameters :

point : {point-like}

The point to test against.

Returns :

res : {True, False}

This operator returns True if:

  1. self.y < point.y
  2. in the borderline case self.y == point.y then if self.x < point.x

Otherwise it returns False.

belongs_to(obj)[source]

Check if the Point is part of a GeometricObject.

This method is actually using the method defined on the passed obj.

Returns :out : {True, False}
distance_to(obj)[source]

Calculate the distance to another GeometricObject.

For now it can only calculate the distance to Line, Ray, Segment and Point.

Parameters :

obj : geometric object

The object for which to calculate the distance to.

Returns :

out : (float, point)

Floating point number representing the distance from this Point to the provided object and the Point of intersection.

intersection(obj)

Return points of intersection if any.

This method just calls the intersection method on the other objects that have it implemented.

Parameters :

obj : geometric object

obj is any object that has intersection implemented.

Returns :

ret : {point, None}

The point of intersection if any, if not, just None.

is_left(obj)[source]

Determine if self is left|on|right of an infinite Line or Point.

Parameters :

obj : {point-like, line-like}

The GeometricObject to test against.

Returns :

out : {scalar, None}

>0 if self is left of Line, =0 if self is on of Line, <0 if self is right of Line,

Raises :

ValueError :

In case something else than a Line-like or Point-like is given.

static is_point_like(obj)[source]

See if obj is of Point-like.

Point-like means Point or a list or tuple of length 2.

Parameters :

obj : geometric object

Returns :

out : {True, False}

True if obj is Point-like, else False.

move(x, y)[source]

The difference between this and translate is that this function moves self to the given coordinates instead.

rotate(theta, point=None, angle='radians')[source]

Rotate self by angle theta.

Parameters :

theta : scalar

Angle to rotate by. Default in radians (see angle).

point : {None, point-like}, optional

Pivot point to rotate against (instead of origin). If not given, the point will be rotated against origin.

angle : {‘radians’, ‘degrees’}, optional

How is theta passed? in radians or degrees.

translate(dx, dy)[source]

See GeometricObject.translate.

x[source]

[scalar] Get the x coordinate.

y[source]

[scalar] Get the y coordinate.

[Arnon1983]Arnon et al., A Linear Time Algorithm for the Minimum Area Rectangle Enclosing a Convex Polygon” (1983), Computer Science Technical Reports. Paper 382
[WPolygon]http://en.wikipedia.org/wiki/Polygon

Previous topic

geo2d.geometry.GeometricObject

Next topic

geo2d.geometry.Vector

This Page