can somebody provide an formula for calculation if a point ( record of 2 real) is over a polygon (defined by an array of ral values)

below is the code I using now, failure is a divison by 0

function IsPointInPolygon(p : FPoint; poly : TFPolygon) : Boolean;var i,j : integer;Begin result := false; j := High(poly); For i := Low(poly) to High(poly) do begin if (( ((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and (p.y < poly[i].y)) ) and (p.x < ((poly[j].x - poly[i].x) * (p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))) then result := not result; j := iend;end;

function IsPointInPolygon(p : FPoint; poly : TFPolygon) : Boolean;
var i,j : integer;
Begin
result := false;
j := High(poly);
For i := Low(poly) to High(poly) do begin
if (poly[j].y - poly[i].y) + poly[i].x) <> 0 then
if (( ((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and (p.y < poly[i].y)) ) and
(p.x < ((poly[j].x - poly[i].x) * (p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))) then result := not result;
j := i
end;
end;

0

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

this only works for integer values

(if you do real x 1000 you could it very accurate ...)

what is the type of FPoint and TFPolygon ?

it would need converting to TPoint and array of TPoint if not compatible

Open in new window