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)
| 186 | |
| 187 | |
| 188 | def _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 | |
| 223 | def convex_hull_bf(points: list[Point]) -> list[Point]: |
no outgoing calls
no test coverage detected