libpysal.cg.LineSegment¶
-
class
libpysal.cg.
LineSegment
(start_pt, end_pt)[source]¶ Geometric representation of line segment objects.
- Parameters
- start_pt
libpysal.cg.Point
The point where the segment begins.
- end_pt
libpysal.cg.Point
The point where the segment ends.
- start_pt
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6)))
- Attributes
p1
libpysal.cg.Point
HELPER METHOD. DO NOT CALL.
p2
Point
HELPER METHOD. DO NOT CALL.
bounding_box
libpysal.cg.Rectangle
Returns the minimum bounding box of a
LineSegment
object.len
python:float
Returns the length of a
LineSegment
object.line
libpysal.cg.Line
Returns a
Line
object of the line on which the segment lies.
-
__init__
(self, start_pt, end_pt)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(self, start_pt, end_pt)Initialize self.
get_swap
(self)Returns a
LineSegment
object which has its endpoints swapped.intersect
(self, other)Test whether segment intersects with other segment (
True
) or not (False
).is_ccw
(self, pt)Returns whether a point is counterclockwise of the segment (
True
) or not (False
).is_cw
(self, pt)Returns whether a point is clockwise of the segment (
True
) or not (False
).sw_ccw
(self, pt)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 on which the segment lies.HELPER METHOD.DO NOT CALL. Returns the
p1
attribute of the line segment..HELPER METHOD.DO NOT CALL. Returns the
p2
attribute of the line segment..-
property
bounding_box
¶ Returns the minimum bounding box of a
LineSegment
object.- Returns
- self._bounding_box
libpysal.cg.Rectangle
The bounding box of the line segment.
- self._bounding_box
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.- Returns
- line_seg
libpysal.cg.LineSegment
The
LineSegment
object which has its endpoints swapped.
- line_seg
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) → bool[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.
- other
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) → bool[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.
- pt
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) → bool[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.
- pt
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
¶ Returns the length of a
LineSegment
object.Examples
>>> ls = LineSegment(Point((2, 2)), Point((5, 2))) >>> ls.len 3.0
-
property
line
¶ Returns a
Line
object of the line on which the segment lies.- Returns
- self._line
libpysal.cg.Line
The
Line
object of the line on which the segment lies.
- self._line
Examples
>>> ls = LineSegment(Point((2, 2)), Point((3, 3))) >>> l = ls.line >>> l.m 1.0
>>> l.b 0.0
-
property
p1
¶ HELPER METHOD. DO NOT CALL. Returns the
p1
attribute of the line segment.- Returns
- self._p1
libpysal.cg.Point
The
_p1
attribute.
- self._p1
Examples
>>> ls = LineSegment(Point((1, 2)), Point((5, 6))) >>> r = ls._get_p1() >>> r == Point((1, 2)) True
-
property
p2
¶ HELPER METHOD. DO NOT CALL. Returns the
p2
attribute of the line segment.- Returns
- self._p2
libpysal.cg.Point
The
_p2
attribute.
- self._p2
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.- Returns
- is_ccwbool
1
if turn fromself.p1
toself.p2
topt
is ccw.-1
if turn fromself.p1
toself.p2
topt
is cw.-1
if the points are collinear andself.p1
is in the middle.1
if the points are collinear andself.p2
is in the middle.0
if the points are collinear andpt
is in the middle.