MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _is_point_on_segment

Function _is_point_on_segment

geometry/jarvis_march.py:58–69  ·  view source on GitHub ↗

Check if a point lies on the line segment between p1 and p2.

(p1: Point, p2: Point, point: Point)

Source from the content-addressed store, hash-verified

56
57
58def _is_point_on_segment(p1: Point, p2: Point, point: Point) -> bool:
59 """Check if a point lies on the line segment between p1 and p2."""
60 # Check if point is collinear with segment endpoints
61 cross = (point.y - p1.y) * (p2.x - p1.x) - (point.x - p1.x) * (p2.y - p1.y)
62
63 if abs(cross) > 1e-9:
64 return False
65
66 # Check if point is within the bounding box of the segment
67 return min(p1.x, p2.x) <= point.x <= max(p1.x, p2.x) and min(
68 p1.y, p2.y
69 ) <= point.y <= max(p1.y, p2.y)
70
71
72def _find_leftmost_point(points: list[Point]) -> int:

Callers 2

_add_point_to_hullFunction · 0.85
jarvis_marchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected