BdLm
asked on
calcualte if a Point is over a Polygon area
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
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 := i
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you would need an algorithm to dissect the polygon into triangles and then see if the point is in a triangle
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Geert I habe real number and values are from 100 ....1E-9, hard to scale
@TKorhan I did the same code as a workaround by myself, is it still the creect math solution ?
@TKorhan I did the same code as a workaround by myself, is it still the creect math solution ?
Yes, off couse. It is correct math solution...
not with a convex polygon ...
if it works with this shape, it should work with mostly all ...
convex.bmp
convex.bmp
ASKER
btw, whose solution is faster? have use this function 10E5 times .....