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

Function on_segment

geometry/segment_intersection.py:51–63  ·  view source on GitHub ↗

Check whether *point*, known to be collinear with the segment, lies on it. >>> on_segment(Point(0, 0), Point(4, 4), Point(2, 2)) True >>> on_segment(Point(0, 0), Point(4, 4), Point(5, 5)) False >>> on_segment(Point(0, 0), Point(4, 0), Point(2, 0)) True

(seg_start: Point, seg_end: Point, point: Point)

Source from the content-addressed store, hash-verified

49
50
51def on_segment(seg_start: Point, seg_end: Point, point: Point) -> bool:
52 """Check whether *point*, known to be collinear with the segment, lies on it.
53
54 >>> on_segment(Point(0, 0), Point(4, 4), Point(2, 2))
55 True
56 >>> on_segment(Point(0, 0), Point(4, 4), Point(5, 5))
57 False
58 >>> on_segment(Point(0, 0), Point(4, 0), Point(2, 0))
59 True
60 """
61 return min(seg_start.x, seg_end.x) <= point.x <= max(
62 seg_start.x, seg_end.x
63 ) and min(seg_start.y, seg_end.y) <= point.y <= max(seg_start.y, seg_end.y)
64
65
66def segments_intersect(p1: Point, p2: Point, p3: Point, p4: Point) -> bool:

Callers 1

segments_intersectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected