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

Function _det

divide_and_conquer/convex_hull.py:188–220  ·  view source on GitHub ↗

Computes the sign perpendicular distance of a 2d point c from a line segment ab. The sign indicates the direction of c relative to ab. A Positive value means c is above ab (to the left), while a negative value means c is below ab (to the right). 0 means all three points are on a str

(a: Point, b: Point, c: Point)

Source from the content-addressed store, hash-verified

186
187
188def _det(a: Point, b: Point, c: Point) -> float:
189 """
190 Computes the sign perpendicular distance of a 2d point c from a line segment
191 ab. The sign indicates the direction of c relative to ab.
192 A Positive value means c is above ab (to the left), while a negative value
193 means c is below ab (to the right). 0 means all three points are on a straight line.
194
195 As a side note, 0.5 * abs|det| is the area of triangle abc
196
197 Parameters
198 ----------
199 a: point, the point on the left end of line segment ab
200 b: point, the point on the right end of line segment ab
201 c: point, the point for which the direction and location is desired.
202
203 Returns
204 --------
205 det: float, abs(det) is the distance of c from ab. The sign
206 indicates which side of line segment ab c is. det is computed as
207 (a_xb_y + c_xa_y + b_xc_y) - (a_yb_x + c_ya_x + b_yc_x)
208
209 Examples
210 ----------
211 >>> _det(Point(1, 1), Point(1, 2), Point(1, 5))
212 0.0
213 >>> _det(Point(0, 0), Point(10, 0), Point(0, 10))
214 100.0
215 >>> _det(Point(0, 0), Point(10, 0), Point(0, -10))
216 -100.0
217 """
218
219 det = (a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
220 return det
221
222
223def convex_hull_bf(points: list[Point]) -> list[Point]:

Callers 4

convex_hull_bfFunction · 0.85
convex_hull_recursiveFunction · 0.85
_construct_hullFunction · 0.85
convex_hull_melkmanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected