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

Function _cross_product

geometry/jarvis_march.py:44–55  ·  view source on GitHub ↗

Calculate the cross product of vectors OA and OB. Returns: > 0: Counter-clockwise turn (left turn) = 0: Collinear < 0: Clockwise turn (right turn)

(origin: Point, point_a: Point, point_b: Point)

Source from the content-addressed store, hash-verified

42
43
44def _cross_product(origin: Point, point_a: Point, point_b: Point) -> float:
45 """
46 Calculate the cross product of vectors OA and OB.
47
48 Returns:
49 > 0: Counter-clockwise turn (left turn)
50 = 0: Collinear
51 < 0: Clockwise turn (right turn)
52 """
53 return (point_a.x - origin.x) * (point_b.y - origin.y) - (point_a.y - origin.y) * (
54 point_b.x - origin.x
55 )
56
57
58def _is_point_on_segment(p1: Point, p2: Point, point: Point) -> bool:

Callers 2

_find_next_hull_pointFunction · 0.85
_is_valid_polygonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected