i took a whole new aproach and its very simple. it isnt working though.
var
points:TPointArray;
np:TPoint;
function OrganiseTriPoints(p1,p2,p3:tpoint):TPointArray;
var x1,x2,x3,y1,y2,y3,pt1,pt2,pt3,yrange:integer;
begin
yrange := max(p1.y,max(p2.y,p3.y))-min(p1.y,min(p2.y,p3.y));
pt1 := p1.x*yrange+p1.y;
pt2 := p2.x*yrange+p2.y;
pt3 := p3.x*yrange+p3.y;
//check for the upperleftmost point
if min(pt1,min(pt2,pt3)) = pt1 then
begin
x1 := p1.x;
y1 := p1.y;
end;
if min(pt1,min(pt2,pt3)) = pt2 then
begin
x1 := p2.x;
y1 := p2.y;
end;
if min(pt1,min(pt2,pt3)) = pt3 then
begin
x1 := p3.x;
y1 := p3.y;
end;
//check for the bottomrightmost point
if max(pt1,max(pt2,pt3)) = pt1 then
begin
x3 := p1.x;
y3 := p1.y;
end;
if max(pt1,max(pt2,pt3)) = pt2 then
begin
x3 := p2.x;
y3 := p2.y;
end;
if max(pt1,max(pt2,pt3)) = pt3 then
begin
x3 := p3.x;
y3 := p3.y;
end;
//find the middlemost point
if ((pt1 < pt2) and (pt1 > pt3)) or ((pt1 > pt2) and (pt1 < pt3)) then
begin
x2 := p2.x;
y2 := p2.y;
end;
if ((pt2 < pt1) and (pt2 > pt3)) or ((pt2 > pt1) and (pt2 < pt3)) then
begin
x2 := p2.x;
y2 := p2.y;
end;
if ((pt3 < pt2) and (pt3 > pt1)) or ((pt3 > pt2) and (pt3 < pt1)) then
begin
x2 := p3.x;
y2 := p3.y;
end;
result := [point(x1,y1),point(x2,y2),point(x3,y3)]
end;
function areatri(p1,p2,p3:TPoint):extended; //gets the area of a triangle
var tpa:TPointArray;w,h:extended;
begin
tpa := OrganiseTriPoints(p1,p2,p3);
w := tpa[2].x-tpa[0].x;
h := max(tpa[0].y,max(tpa[1].y,tpa[2].y))-min(tpa[0].y,min(tpa[1].y,tpa[2].y));
result := w*h*0.5
end;
function IsInTri(p,p1,p2,p3:TPoint):boolean;
var sum:extended;
begin //This will split the triangle into 3 smaller ones and get the total area.
//If the area is more than the base triangle then point is outside.
sum := areatri(p,p1,p2)+areatri(p,p2,p3)+areatri(p,p3,p1);
result := (abs(sum - areatri(p1,p2,p3))<1);
end;
//main
begin
points := [point(0,767),point(512,0),point(1023,767)]
points := OrganiseTriPoints(points[0],points[1],points[2]);
np := point(RandomRange(points[0].x,points[2].x),RandomRange(max(points[0].y,max(points[1].y,points[2].y))-min(points[0].y,min(points[1].y,points[2].y)),min(points[0].y,min(points[1].y,points[2].y))));
writeln(np);
writeln(IsInTri(np,points[0],points[1],points[2]));
end.
is that considered clean? i don't know how to use case statements in simba yet so dont count that.