Answer the question
In order to leave comments, you need to log in
Is the cycle correct for points in an area?
x:=StrToFloat(Edit1.Text);
y:=StrToFloat(Edit2.Text);
if ((x=0) and (y=-1)) or ((x=1) and (y=-1))
then
Label1.Caption:=' точка лежит в заштрихованной области'
else if ((x=-1) or (y=-2)) or ((x=2) or (y=-2)) or ((x-y)=0) or ((x+y)=4)
or ((x=2) and (y=-1))
then
Label1.Caption:=' точка лежит на границе заштрихованной области '
else Label1.Caption:=' точка за пределами заштрихованной области '
Answer the question
In order to leave comments, you need to log in
Check first whether the point is in the triangle. Then into a rectangle.
Or you can try using Windows features
function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;
var
rgn: HRGN;
begin
rgn := CreatePolygonRgn(Polygon[0], Length(Polygon), WINDING);
Result := PtInRegion(rgn, Point.X, Point.Y);
DeleteObject(rgn);
end;
Использование
var Points: array of TPoint;
Points := [TPoint.Create(-1, 0), TPoint.Create(0, 0), ...];
if PointInPolygon(TPoint.Create(0, 0), Points) then <точка входит в область>
First, there is no cycle here.
Secondly, the check of finding a point inside the area is implemented incorrectly. Even from general considerations, it is clear that checking whether a point falls into an area cannot be performed by checking whether the coordinates of the point are equal to anything. There should be a check for more or less.
I did not check the long condition for checking if it hit the border, laziness. But something in it is suspiciously few logical AND (and). It is most likely incorrect.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question