geo2d.geometry.Segment

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

An extension on Line.

This class emposes the length property on a Line. A Segment is a finite Line.

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}

See arg1.

Raises :

ValueError :

If length is less than or equal to 0.

See also

Line, Ray, Vector

Attributes

bounding_box [BoundingBox] get the BoundingBox of self.
length [scalar] Get the length of the Segment.
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.’
get_point_on_self([frac]) Get a point on this Segment based on frac.
has(point) Check if point is part of self.
intersection(obj) Tries to find the Point of intersection.
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.Segment(arg1, arg2)[source]

An extension on Line.

This class emposes the length property on a Line. A Segment is a finite Line.

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}

See arg1.

Raises :

ValueError :

If length is less than or equal to 0.

See also

Line, Ray, Vector

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

Get the points that define the Line by index.

Parameters :

idx : scalar

The index for Point.

Returns :

ret : point

Selected Point by index.

__len__()

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

bounding_box[source]

[BoundingBox] get the BoundingBox of self.

get_point_on_self(frac=None)[source]

Get a point on this Segment based on frac.

If no argument is given then the Point on the Segment will be placed randomly.

Parameters :

frac : float, optional

If frac is given then the new Point‘s position will be relative to the length of the Segment and to the first Point (self.p1). frac can be only in the interval (0, 1).

Returns :

out : point

The new Point‘s position on the Segment.

Raises :

ValueError :

If frac is outside the open interval (0, 1) then a ValueError is raised.

has(point)[source]

Check if point is part of self.

Parameters :

point : point-like

The point to check.

Returns :

ret : {True, False}

If the point is on the Ray then return True, else False.

intersection(obj)[source]

Tries to find the Point of intersection.

The difference between this and the Line intersection method is that this has also the constrain that if the Point of intersection is on the line then it also must be within the bounds of the Segment.

Parameters :

obj : geometric object

Returns :

out : {gometrical object, None}

GeometricObject if intersection is possible, else the cases from Line.intersection.

static is_line_like(obj)

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}

length[source]

[scalar] Get the length of the Segment.

I.e. the distance from self.p1 to self.p2.

p1

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

p2

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

parallel_to(obj)

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)

Find out if provided Line is perpendicular to self.

Returns :ret : {True, False}
phi

[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

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

Next topic

geo2d.geometry.Polygon

This Page