Results 1 to 7 of 7

Thread: Check if tile inside irregular area

  1. #1
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default Check if tile inside irregular 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".

  2. #2
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    If you know your exact location you could check between distances.

  3. #3
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    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".

  4. #4
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    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;

  5. #5
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  6. #6
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by TomTuff View Post
    PointInAbstractBox in Math.scar of SRL
    Had a look at that. Shape is more irregular than that. As always spent a couple hours pouring through the includes before asking.

    Quote Originally Posted by IceFire908 View Post
    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.
    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".

  7. #7
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    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.
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •