Point Within Triangle

Published by Theldoria in

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

Watch a quick demo on how Edabit works.