как узнать принадлежит ли точка к треугольнику (находится ли она в нем) или нет!
Зарание спасибо!!
program point_in_treug;
const _eps = 1E-7;
type TPoint = record
x,y : real;
end;
var a,b,c,p : TPoint;
s,s1,s2,s3 : real;
function sq_treug(a,b,c : TPoint) : real;
begin
sq_treug := (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) / 2;
end;
begin
read(a.x,a.y);
read(b.x,b.y);
read(c.x,c.y);
read(p.x,p.y);
s := abs (sq_treug(a,b,c));
s1 := abs (sq_treug(a,b,p));
s2 := abs (sq_treug(a,p,c));
s3 := abs (sq_treug(p,b,c));
if abs (s - s1 - s2 - s3) < _eps then writeln('point is inside the triangle')
else writeln('point is outside the triangle');
end.
program point_in_treug;
const _eps = 1E-7;
type TPoint = record
x,y : real;
end;
var a,b,c,p : TPoint;
s,s1,s2,s3 : real;
function sq_treug(a,b,c : TPoint) : real;
begin
sq_treug := (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) / 2;
end;
begin
read(a.x,a.y);
read(b.x,b.y);
read(c.x,c.y);
read(p.x,p.y);
s := abs (sq_treug(a,b,c));
s1 := abs (sq_treug(a,b,p));
s2 := abs (sq_treug(a,p,c));
s3 := abs (sq_treug(p,b,c));
if abs (s - s1 - s2 - s3) < _eps then writeln('point is inside the triangle')
else writeln('point is outside the triangle');
end.