Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. public bool IsInPolygon(Polygon polygon, Location CurrentPosition)
  2. {
  3.             LineEntity F1 = new LineEntity(polygon.Positions[0], polygon.Positions[1]);
  4.             LineEntity F2 = new LineEntity(polygon.Positions[1], polygon.Positions[2]);
  5.             LineEntity F3 = new LineEntity(polygon.Positions[2], polygon.Positions[3]);
  6.             LineEntity F4 = new LineEntity(polygon.Positions[3], polygon.Positions[0]);
  7.  
  8.             // The end of first ray
  9.             Position B = new Position(CurrentPosition.Longitude + 34.282828, CurrentPosition.Latitude + 83.181772626);
  10.             // The end of second ray
  11.             Position C = new Position(CurrentPosition.Longitude + 23.2828828, CurrentPosition.Latitude + 12.001827);
  12.  
  13.             LineEntity AB = new LineEntity(CurrentPosition, B);
  14.             LineEntity AC = new LineEntity(CurrentPosition, C);
  15.  
  16.  
  17.             int ABCounter = 0;
  18.             if (lineInteractor.IfIntersect(AB, F1))
  19.                 ABCounter++;
  20.             if (lineInteractor.IfIntersect(AB, F2))
  21.                 ABCounter++;
  22.             if (lineInteractor.IfIntersect(AB, F3))
  23.                 ABCounter++;
  24.             if (lineInteractor.IfIntersect(AB, F4))
  25.                 ABCounter++;
  26.  
  27.             int ACCounter = 0;
  28.             if (lineInteractor.IfIntersect(AC, F1))
  29.                 ACCounter++;
  30.             if (lineInteractor.IfIntersect(AC, F2))
  31.                 ACCounter++;
  32.             if (lineInteractor.IfIntersect(AC, F3))
  33.                 ACCounter++;
  34.             if (lineInteractor.IfIntersect(AC, F4))
  35.                 ACCounter++;
  36.  
  37.             if (ABCounter % 2 == 1 && ACCounter % 2 == 1)
  38.                 return true;
  39.             return false;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement