Is there a (relatively) easy way to tell if a tile lies inside a really irregular shaped area?
Is there a (relatively) easy way to tell if a tile lies inside a really irregular shaped area?
Never ever approach a computer saying or even thinking "I will just do this quickly".
Google is your friend. Just don't ask me to explain it.
My head hurts now and I think I need to go lie down.
Edit: Faster more accurate version for those who might have a use for it.
Simba Code:{*******************************************************************************
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;
Last edited by Bixby Sayz; 08-06-2011 at 04:19 AM.
Never ever approach a computer saying or even thinking "I will just do this quickly".
PointInAbstractBox in Math.scar of SRL
E: InAbstractBox
Simba Code: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;
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.
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.
Never ever approach a computer saying or even thinking "I will just do this quickly".
If it's not definable as a polygon, then you'll need every point inside the shape and use TPAInATPA. Use SaveScreenShot and open the image up in paint, shade in the map or whatever completely black, then make the shape you want white. Use FindColors with FilterPointsPie (with the radius/center of MM) to get a list of points that are in the unshaded region. It may be tricky getting the points to be same if they would if they were on the regular client, maybe add some preset offsets to the exported coordinates before they are debugged.
There are currently 1 users browsing this thread. (0 members and 1 guests)