2D line

class Line2(line)[source]

Class to represent 2D lines

The internal representation is in homogeneous format

\[ax + by + c = 0\]
classmethod General(m, c)[source]

Create line from general line

Parameters
  • m (float) – line gradient

  • c (float) – line intercept

Returns

a 2D line

Return type

a Line2 instance

Creates a line from the parameters of the general line \(y = mx + c\).

Note

A vertical line cannot be represented.

classmethod Join(p1, p2)[source]

Create 2D line from two points

Parameters
  • p1 (array_like(2) or array_like(3)) – point on the line

  • p2 (array_like(2) or array_like(3)) – another point on the line

The points can be given in Euclidean or homogeneous form.

Return type

Self

classmethod TwoPoints(p1, p2)[source]
Return type

Self

contains(p, tol=20)[source]

Test if point is in line

Parameters
  • p1 (array_like(2) or array_like(3)) – point to test

  • tol (float) – tolerance in units of eps, defaults to 20

Returns

True if point lies in the line

Return type

bool

contains_polygon_point()[source]
distance_line_line()[source]
distance_line_point()[source]
general()[source]

Parameters of general line

Returns

parameters of general line (m, c)

Return type

ndarray(2)

Return the parameters of a general line \(y = mx + c\).

intersect(other, tol=20)[source]

Intersection with line

Parameters
  • other (Line2) – another 2D line

  • tol (float) – tolerance in units of eps, defaults to 20

Returns

intersection point in homogeneous form

Return type

ndarray(3)

If the lines are parallel then the third element of the returned homogeneous point will be zero (an ideal point).

intersect_polygon___line()[source]
intersect_segment(p1, p2, tol=20)[source]

Test for line intersecting line segment

Parameters
  • p1 (array_like(2) or array_like(3)) – start of line segment

  • p2 (array_like(2) or array_like(3)) – end of line segment

  • tol (float) – tolerance in units of eps, defaults to 20

Returns

True if they intersect

Return type

bool

Tests whether the line intersects the line segment defined by endpoints p1 and p2 which are given in Euclidean or homogeneous form.

plot(**kwargs)[source]

Plot the line using matplotlib

Parameters

kwargs – arguments passed to Matplotlib pyplot.plot

Return type

None

points_join()[source]