libpysal.cg.
LineSegment
(start_pt, end_pt)[source]¶Geometric representation of line segment objects.
Point where segment begins
Point where segment ends
p1
PointHELPER METHOD.
p2
PointHELPER METHOD.
bounding_box
tupleReturns the minimum bounding box of a LineSegment object.
len
floatReturns the length of a LineSegment object.
line
LineReturns a Line object of the line which the segment lies on.
__init__
(self, start_pt, end_pt)[source]¶Creates a LineSegment object.
__init__(Point, Point) -> LineSegment
Test tag: <tc>#is#LineSegment.__init__</tc> Test tag: <tc>#tests#LineSegment.__init__</tc>
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6)))
Methods
|
Creates a LineSegment object. |
|
Returns a LineSegment object which has its endpoints swapped. |
|
Test whether segment intersects with other segment |
|
Returns whether a point is counterclockwise of the segment. |
|
Returns whether a point is clockwise of the segment. |
|
Sedgewick test for pt being ccw of segment |
Attributes
Returns the minimum bounding box of a LineSegment object. |
|
Returns the length of a LineSegment object. |
|
Returns a Line object of the line which the segment lies on. |
|
HELPER METHOD. |
|
HELPER METHOD. |
bounding_box
¶Returns the minimum bounding box of a LineSegment object.
Test tag: <tc>#is#LineSegment.bounding_box</tc> Test tag: <tc>#tests#LineSegment.bounding_box</tc>
bounding_box -> Rectangle
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
(self)[source]¶Returns a LineSegment object which has its endpoints swapped.
get_swap() -> LineSegment
Test tag: <tc>#is#LineSegment.get_swap</tc> Test tag: <tc>#tests#LineSegment.get_swap</tc>
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
(self, other)[source]¶Test whether segment intersects with other segment
Handles endpoints of segments being on other segment
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
(self, pt)[source]¶Returns whether a point is counterclockwise of the segment. Exclusive.
is_ccw(Point) -> bool
Test tag: <tc>#is#LineSegment.is_ccw</tc> Test tag: <tc>#tests#LineSegment.is_ccw</tc>
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
(self, pt)[source]¶Returns whether a point is clockwise of the segment. Exclusive.
is_cw(Point) -> bool
Test tag: <tc>#is#LineSegment.is_cw</tc> Test tag: <tc>#tests#LineSegment.is_cw</tc>
Examples
>>> ls = LineSegment(Point((0, 0)), Point((5, 0)))
>>> ls.is_cw(Point((2, 2)))
False
>>> ls.is_cw(Point((2, -2)))
True
len
¶Returns the length of a LineSegment object.
Test tag: <tc>#is#LineSegment.len</tc> Test tag: <tc>#tests#LineSegment.len</tc>
len() -> number
Examples
>>> ls = LineSegment(Point((2, 2)), Point((5, 2)))
>>> ls.len
3.0
line
¶Returns a Line object of the line which the segment lies on.
Test tag: <tc>#is#LineSegment.line</tc> Test tag: <tc>#tests#LineSegment.line</tc>
line() -> Line
Examples
>>> ls = LineSegment(Point((2, 2)), Point((3, 3)))
>>> l = ls.line
>>> l.m
1.0
>>> l.b
0.0
p1
¶HELPER METHOD. DO NOT CALL.
Returns the p1 attribute of the line segment.
_get_p1() -> Point
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6)))
>>> r = ls._get_p1()
>>> r == Point((1, 2))
True
p2
¶HELPER METHOD. DO NOT CALL.
Returns the p2 attribute of the line segment.
_get_p2() -> Point
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6)))
>>> r = ls._get_p2()
>>> r == Point((5, 6))
True
sw_ccw
(self, pt)[source]¶Sedgewick test for pt being ccw of segment