libpysal.cg.get_segment_point_dist¶
- libpysal.cg.get_segment_point_dist(seg, pt)[source]¶
Returns (1) the distance between a line segment and point and (2) the distance along the segment to the closest location on the segment from the point as a ratio of the length of the segment.
- Parameters:¶
- seg : libpysal.cg.LineSegment¶
A line segment to compute distance from.
- pt : libpysal.cg.Point¶
A point to compute distance from.
- Returns:¶
dist (float) – The distance between
segandpt.ratio (float) – The distance along
segto the closest location onsegfromptas a ratio of the length ofseg.
Examples
>>> seg = LineSegment(Point((0, 0)), Point((10, 0))) >>> pt = Point((5, 5)) >>> get_segment_point_dist(seg, pt) (5.0, 0.5)>>> pt2 = Point((0, 0)) >>> get_segment_point_dist(seg, pt2) (0.0, 0.0)