geo2d.geometry.Line

class geo2d.geometry.Line(arg1, arg2)[source]

An abstract mathematical Line.

It is defined by either two points or by a Point and a Vector.

Parameters :

arg1 : point-like

The passed in parameters can be either two points or a Point and a Vector. For more on Point-like see the Point class.

arg2 : {point-like, vector}

If a Vector is given as arg2 instead of a Point-like, then p2 will be calculated for t = 1 in the vectorial definition of the line (see notes).

See also

Point, Vector

Notes

A line can be defined in three ways, but we use here only the vectorial definition for which we need a Point and a Vector. If two points are given the Vector \(\boldsymbol{\mathtt{p_1p_2}}\) will be calculated and then we can define the Line as:

\[\boldsymbol{r} = \boldsymbol{r_0} + t \cdot \boldsymbol{\mathtt{p_1p_2}}\]

Here \(t\) is a parameter.

Attributes

p1 [point] Get the 1st Point that defines the Line.
p2 [point] Get the 2nd Point that defines the Line.
phi [scalar] Get self.v.phi. Convenience method.
v [vector] Get the Vector pointing from self.p1 to`self.p2`.

Methods

__contains__(x) Searches for x in “itself”.
__getitem__(idx) Get the points that define the Line by index.
__len__() The Line is made of 2 points so it’s length is 2.’
has(point) Inspect if point (Point-like) is part of this Line.
intersection(obj) Find if self is intersecting the provided object.
is_line_like(obj) Check if an object is in the form of Line-like for fast
parallel_to(obj) Find out if provided Vector or Line-like is
perpendicular_to(obj) Find out if provided Line is perpendicular to self.
rotate(theta[, point, angle]) Rotate self around pivot point.
translate(dx, dy) Translate self by given amounts on x and y.

Detailed description

class geo2d.geometry.Line(arg1, arg2)[source]

An abstract mathematical Line.

It is defined by either two points or by a Point and a Vector.

Parameters :

arg1 : point-like

The passed in parameters can be either two points or a Point and a Vector. For more on Point-like see the Point class.

arg2 : {point-like, vector}

If a Vector is given as arg2 instead of a Point-like, then p2 will be calculated for t = 1 in the vectorial definition of the line (see notes).

See also

Point, Vector

Notes

A line can be defined in three ways, but we use here only the vectorial definition for which we need a Point and a Vector. If two points are given the Vector \(\boldsymbol{\mathtt{p_1p_2}}\) will be calculated and then we can define the Line as:

\[\boldsymbol{r} = \boldsymbol{r_0} + t \cdot \boldsymbol{\mathtt{p_1p_2}}\]

Here \(t\) is a parameter.

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

__getitem__(idx)[source]

Get the points that define the Line by index.

Parameters :

idx : scalar

The index for Point.

Returns :

ret : point

Selected Point by index.

__len__()[source]

The Line is made of 2 points so it’s length is 2.’

has(point)[source]

Inspect if point (Point-like) is part of this Line.

Parameters :

point : point-like

The Point to test if it’s part of this Line.

Returns :

ret : {True, False}

If it’s part of this Line then return True, else False.

intersection(obj)[source]

Find if self is intersecting the provided object.

If an intersection is found, the Point of intersection is returned, except for a few special cases. For further explanation see the notes.

Parameters :

obj : geometric object

Returns :

out : {geometric object, tuple}

If they intersect then return the Point where this happened, else return None (except for Line and Polygon: see notes).

Raises :

TypeError :

If argument is not geometric object then a TypeError is raised.

Notes

  • Line: in case obj is Line-like and self then self and the Line defined by obj are checked for colinearity also in which case utils.inf is returned.
  • Polygon: in the case of intersection with a Polygon a tuple of tuples is returned. The nested tuple is made up by the index of the intersected side and intersection point (e.g. ((intersection_point1, 1), ( intersection_point2, 4)) where 1 is the first intersected side of the Polygon and 4 is the second one). If the Line doesn’t intersect any sides then None is returned as in the usual case.
static is_line_like(obj)[source]

Check if an object is in the form of Line-like for fast computations (not necessary to build lines).

Parameters :

obj : anything

obj is checked if is of type Line (i.e. not Ray nor Segment) or if this is not true then of the form: ((0, 1), (3, 2)) or [[0, 2], [3, 2]] or even combinations of these.

Returns :

res : {True, False}

p1[source]

[point] Get the 1st Point that defines the Line.

p2[source]

[point] Get the 2nd Point that defines the Line.

parallel_to(obj)[source]

Find out if provided Vector or Line-like is parllel to self.

Parameters :

obj : {vector, line-like}

The Vector or Line-like to compare parallelism with.

Returns :

ret : {True, False}

If self and Line are parallel then retrun True, else False.

perpendicular_to(obj)[source]

Find out if provided Line is perpendicular to self.

Returns :ret : {True, False}
phi[source]

[scalar] Get self.v.phi. Convenience method.

rotate(theta, point=None, angle='degrees')

Rotate self around pivot point.

Parameters :

theta : scalar

The angle to be rotated by.

point : {point-like}, optional

If given this will be used as the rotation pivot.

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

This tells the function how theta is passed: as degrees or as radians. Default is degrees.

translate(dx, dy)

Translate self by given amounts on x and y.

Parameters :

dx, dy : scalar

Amount to translate (relative movement).

v[source]

[vector] Get the Vector pointing from self.p1 to`self.p2`.

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

Next topic

geo2d.geometry.Ray

This Page