Return the cross product of vectors (pivot->query) and (pivot->target). The sign of the result encodes the orientation of the ordered triple (pivot, target, query): - Negative -> counter-clockwise (left turn) - Positive -> clockwise (right turn) - Zero -> colline
(pivot: Point, target: Point, query: Point)
| 28 | |
| 29 | |
| 30 | def direction(pivot: Point, target: Point, query: Point) -> float: |
| 31 | """Return the cross product of vectors (pivot->query) and (pivot->target). |
| 32 | |
| 33 | The sign of the result encodes the orientation of the ordered triple |
| 34 | (pivot, target, query): |
| 35 | - Negative -> counter-clockwise (left turn) |
| 36 | - Positive -> clockwise (right turn) |
| 37 | - Zero -> collinear |
| 38 | |
| 39 | >>> direction(Point(0, 0), Point(1, 0), Point(0, 1)) |
| 40 | -1 |
| 41 | >>> direction(Point(0, 0), Point(0, 1), Point(1, 0)) |
| 42 | 1 |
| 43 | >>> direction(Point(0, 0), Point(1, 1), Point(2, 2)) |
| 44 | 0 |
| 45 | """ |
| 46 | return (query.x - pivot.x) * (target.y - pivot.y) - (target.x - pivot.x) * ( |
| 47 | query.y - pivot.y |
| 48 | ) |
| 49 | |
| 50 | |
| 51 | def on_segment(seg_start: Point, seg_end: Point, point: Point) -> bool: |
no outgoing calls
no test coverage detected