← Back to challenges

Point Within Triangle

PythonHardalgebramathvalidation

Instructions

Create a function that takes four tuples. The first three are (x, y) coordinates of three corners of a triangle. Return True if the fourth tuple — the (x, y) coordinates of a test point — lies within the triangle, False if it doesn't.

Examples

within_triangle((1, 4), (5, 6), (6, 1), (4, 5)) ➞ True

within_triangle((1, 4), (5, 6), (6, 1), (3, 2)) ➞ False

within_triangle((-6, 2), (-2, -2), (8, 4), (4, 2)) ➞ True

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.