MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / consecutive_orientation

Method consecutive_orientation

geometry/graham_scan.py:91–110  ·  view source on GitHub ↗

Calculate the cross product of vectors (self -> point_a) and (point_a -> point_b). Returns: - Positive value: counter-clockwise turn - Negative value: clockwise turn - Zero: collinear points >>> Point(0, 0).consecutive_orientation(Point(1, 0

(self, point_a: Point, point_b: Point)

Source from the content-addressed store, hash-verified

89 return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5
90
91 def consecutive_orientation(self, point_a: Point, point_b: Point) -> float:
92 """
93 Calculate the cross product of vectors (self -> point_a) and
94 (point_a -> point_b).
95
96 Returns:
97 - Positive value: counter-clockwise turn
98 - Negative value: clockwise turn
99 - Zero: collinear points
100
101 >>> Point(0, 0).consecutive_orientation(Point(1, 0), Point(1, 1))
102 1.0
103 >>> Point(0, 0).consecutive_orientation(Point(1, 0), Point(1, -1))
104 -1.0
105 >>> Point(0, 0).consecutive_orientation(Point(1, 0), Point(2, 0))
106 0.0
107 """
108 return (point_a.x - self.x) * (point_b.y - point_a.y) - (point_a.y - self.y) * (
109 point_b.x - point_a.x
110 )
111
112
113def graham_scan(points: Sequence[Point]) -> list[Point]:

Callers 3

compare_pointsFunction · 0.80
graham_scanFunction · 0.80

Calls

no outgoing calls

Tested by 1