triangle pointintersection

Solutions on MaxInterview for triangle pointintersection by the best coders in the world

showing results for - "triangle pointintersection"
María Paula
31 Sep 2019
1function sign(p1, p2, p3) {
2  return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
3}
4
5function PointInTriangle(pt, v1, v2, v3) {
6  let d1, d2, d3;
7  let has_neg, has_pos;
8
9  d1 = sign(pt, v1, v2);
10  d2 = sign(pt, v2, v3);
11  d3 = sign(pt, v3, v1);
12
13  has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
14  has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
15
16  return !(has_neg && has_pos);
17}