libpysal.cg.LineSegment¶
- class libpysal.cg.LineSegment(start_pt, end_pt)[source]¶
Geometric representation of line segment objects.
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6)))Create a line segment from two endpoints.
- Parameters:¶
- start_pt : libpysal.cg.Point¶
The point where the segment begins.
- end_pt : libpysal.cg.Point¶
The point where the segment ends.
Methods
get_swap()Returns a
LineSegmentobject which has its endpoints swapped.intersect(other)Test whether segment intersects with other segment (
True) or not (False).is_ccw(pt)Returns whether a point is counterclockwise of the segment (
True) or not (False).is_cw(pt)Returns whether a point is clockwise of the segment (
True) or not (False).sw_ccw(pt)Sedgewick test for
ptbeing ccw of segment.Attributes
Returns the minimum bounding box of a
LineSegmentobject.Returns the length of a
LineSegmentobject.Returns a
Lineobject of the line on which the segment lies.Helper method.
Helper method.
- property bounding_box[source]¶
Returns the minimum bounding box of a
LineSegmentobject.Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6))) >>> ls.bounding_box.left 1.0>>> ls.bounding_box.lower 2.0>>> ls.bounding_box.right 5.0>>> ls.bounding_box.upper 6.0
- get_swap()[source]¶
Returns a
LineSegmentobject which has its endpoints swapped.Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6))) >>> swap = ls.get_swap() >>> swap.p1[0] 5.0>>> swap.p1[1] 6.0>>> swap.p2[0] 1.0>>> swap.p2[1] 2.0
- intersect(other)[source]¶
Test whether segment intersects with other segment (
True) or not (False). Handles endpoints of segments being on other segment.- Parameters:¶
- other : libpysal.cg.LineSegment¶
Another line segment to check against.
Examples
>>> ls = LineSegment(Point((5, 0)), Point((10, 0))) >>> ls1 = LineSegment(Point((5, 0)), Point((10, 1))) >>> ls.intersect(ls1) True>>> ls2 = LineSegment(Point((5, 1)), Point((10, 1))) >>> ls.intersect(ls2) False>>> ls2 = LineSegment(Point((7, -1)), Point((7, 2))) >>> ls.intersect(ls2) True
- is_ccw(pt)[source]¶
Returns whether a point is counterclockwise of the segment (
True) or not (False). Exclusive.- Parameters:¶
- pt : libpysal.cg.Point¶
A point lying ccw or cw of a segment.
Examples
>>> ls = LineSegment(Point((0, 0)), Point((5, 0))) >>> ls.is_ccw(Point((2, 2))) True>>> ls.is_ccw(Point((2, -2))) False
- is_cw(pt)[source]¶
Returns whether a point is clockwise of the segment (
True) or not (False). Exclusive.- Parameters:¶
- pt : libpysal.cg.Point¶
A point lying ccw or cw of a segment.
Examples
>>> ls = LineSegment(Point((0, 0)), Point((5, 0))) >>> ls.is_cw(Point((2, 2))) False>>> ls.is_cw(Point((2, -2))) True
- property len : float[source]¶
Returns the length of a
LineSegmentobject.Examples
>>> ls = LineSegment(Point((2, 2)), Point((5, 2))) >>> ls.len 3.0
- property line[source]¶
Returns a
Lineobject of the line on which the segment lies.Examples
>>> ls = LineSegment(Point((2, 2)), Point((3, 3))) >>> l = ls.line >>> l.m 1.0>>> l.b 0.0
- property p1[source]¶
Helper method. Do not call directly.
Returns the
p1attribute of the line segment.Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6))) >>> r = ls._get_p1() >>> r == Point((1, 2)) True
- property p2[source]¶
Helper method. Do not call directly.
Returns the
p2attribute of the line segment.Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6))) >>> r = ls._get_p2() >>> r == Point((5, 6)) True
- sw_ccw(pt)[source]¶
Sedgewick test for
ptbeing ccw of segment.- Returns:¶
is_ccw –
1if turn fromself.p1toself.p2toptis ccw.-1if turn fromself.p1toself.p2toptis cw.-1if the points are collinear andself.p1is in the middle.1if the points are collinear andself.p2is in the middle.0if the points are collinear andptis in the middle.- Return type:¶