[Solved] Check whether Point lies strictly inside the triangle


There is lot approaches to check whether point lies inside triangle. The simplest ones, I think:

1) Check whether point is on the same side of all edges (find signs of cross products for edge vectors and vertex-point vectors AB x AP, BC x BP, CA x CP)

2) Represent AP vector in basis of AB and AC vectors – coefficients and their sum should be in range 0..1. Delphi code:

function PtInTriangle(ax, ay, bx, by, cx, cy, px, py: Integer): Boolean;
var
  xb, yb, xc, yc, xp, yp, d: Integer;
  bb, cc, oned: Double;
begin
  Result := False;
  xb := bx - ax;
  yb := by - ay;
  xc := cx - ax;
  yc := cy - ay;
  xp := px - ax;
  yp := py - ay;
  d := xb * yc - yb * xc;
  if d <> 0 then begin
    oned := 1 / d;
    bb := (xp * yc - xc * yp) * oned;
    cc := (xb * yp - xp * yb) * oned;
    Result := (bb > 0) and (cc > 0) and (cc + bb < 1);
  end;
end;

solved Check whether Point lies strictly inside the triangle