Bixby Sayz
2011-08-03 21:28:25
Is there a (relatively) easy way to tell if a tile lies inside a really irregular shaped area?
2011-08-03 21:28:25
2011-08-03 21:50:34
2011-08-03 22:47:43
{*******************************************************************************
function IsPointInPolygon(const Pt: TPoint; Polygon: TPointArray): boolean;
By: Lord Soth (DaniWeb Forums)
[url]http://www.daniweb.com/software-development/pascal-and-delphi/code/216805[/url]
Description: Returns true if point lies inside or on the border of polygon.
Modified By: Bixby Sayz
Note: Based on [url]http://paulbourke.net/geometry/insidepoly/[/url]
*******************************************************************************}
function IsPointInPolygon(const Pt: TPoint; Polygon: TPointArray): boolean;
var
I, J: integer;
begin
result := FALSE;
J := High(Polygon);
for I := Low(Polygon) to High(Polygon) do
begin
if (
(
((Polygon[I].Y <= Pt.Y) and (Pt.Y < Polygon[J].Y))
or
((Polygon[J].Y <= Pt.Y) and (Pt.Y < Polygon[I].Y))
)
and
(Pt.X < ((Polygon[J].X - Polygon[I].X) * (Pt.Y - Polygon[I].Y) / (Polygon[J].Y - Polygon[I].Y) + Polygon[I].X))
) then
result := not result;
J := I;
end;
end;
2011-08-03 22:48:33
function InAbstractBox(x1, y1, x2, y2, x3, y3, x4, y4: Integer; x, y: Integer):
Boolean;
var
U, D, R, L: Boolean;
UB, DB, LB, RB, UM, DM, LM, RM: Extended;
begin
UM := (-y1 - -y2) div (x1 - x2);
DM := (-y4 - -y3) div (x4 - x3);
if x1 - x4 <> 0 then
begin
LM := (-y1 - -y4) div (x1 - x4);
end else
begin
LM := Pi;
end;
if x2 - x3 <> 0 then
begin
RM := (-y2 - -y3) div (x2 - x3);
end else
begin
RM := Pi;
end;
UB := -(UM * x1) + -y1;
RB := -(RM * x2) + -y2;
DB := -(DM * x3) + -y3;
LB := -(LM * x4) + -y4;
if (UM * x + UB >= -y) then U := True;
if (DM * x + DB <= -y) then D := True;
if (RM <> Pi) and (RM >= 0) and (RM * x + RB <= -y) then R := True;
if (RM <> Pi) and (RM < 0) and (RM * x + RB >= -y) then R := True;
if (RM = Pi) and (x < x2) then R := True;
if (LM <> Pi) and (LM >= 0) and (LM * x + LB >= -y) then L := True;
if (LM <> Pi) and (LM < 0) and (LM * x + LB <= -y) then L := True;
if (LM = Pi) and (x > x1) then L := True;
if U and D and L and R then Result := True;
end;
2011-08-03 22:54:36
2011-08-04 07:14:02
From: TomTuff
PointInAbstractBox in Math.scar of SRL
From: IceFire908
If it's more irregular than something that can be defined as a polygon you could use something like InTPA, and if you're lazy you could always use a screen image and draw in exactly what you need with paint and write a script to export/debug the points into an array.
2011-08-04 14:10:37
From: Bixby Sayz
Had a look at that. Shape is more irregular than that. As always spent a couple hours pouring through the includes before asking.
Thats what I thought of originally. But reading the description it shoulds like it only returns a match if the point is exactly contained in the TPA. I want to know if the point is inside the shape defined by the TPA.
Wasn't sure how to go about the export/load points and was sure I'd screw it up. The function above seems to work, so I'm going to write a test script and see if truly does want I want.