Last active
March 10, 2017 18:41
-
-
Save rockarts/43acd0c382a571c2965d9e58cdca5211 to your computer and use it in GitHub Desktop.
Polygon Map Test Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Border of Polygon | |
| -115.103760,50.958427,0.0 | |
| -115.982666,51.103522,0.0 | |
| -116.290283,51.323747,0.0 | |
| -116.323242,51.563412,0.0 | |
| -115.982666,51.638476,0.0 | |
| -115.576172,51.549751,0.0 | |
| -114.895020,51.337476,0.0 | |
| -114.763184,51.013755,0.0 | |
| -115.081787,50.958427,0.0 | |
| Inside Polygon | |
| -114.927979,51.096623,0.0 | |
| -116.147461,51.467697,0.0 | |
| -116.037598,51.261915,0.0 | |
| -115.762939,51.158677,0.0 | |
| -115.477295,51.131108,0.0 | |
| -115.202637,51.330612,0.0 | |
| -115.960693,51.577070,0.0 | |
| Border of Square | |
| -115.795898,51.412912,0.0 | |
| -115.136719,51.426614,0.0 | |
| -115.092773,50.750359,0.0 | |
| -115.751953,50.764259,0.0 | |
| -115.806885,51.406059,0.0 | |
| Inside Square | |
| -115.708008,51.344339,0.0 | |
| -115.290527,51.330612,0.0 | |
| -115.213623,50.819818,0.0 | |
| -115.653076,50.854509,0.0 | |
| public bool IsPointInPolygon( Point p, Point[] polygon ) | |
| { | |
| double minX = polygon[ 0 ].X; | |
| double maxX = polygon[ 0 ].X; | |
| double minY = polygon[ 0 ].Y; | |
| double maxY = polygon[ 0 ].Y; | |
| for ( int i = 1 ; i < polygon.Length ; i++ ) | |
| { | |
| Point q = polygon[ i ]; | |
| minX = Math.Min( q.X, minX ); | |
| maxX = Math.Max( q.X, maxX ); | |
| minY = Math.Min( q.Y, minY ); | |
| maxY = Math.Max( q.Y, maxY ); | |
| } | |
| if ( p.X < minX || p.X > maxX || p.Y < minY || p.Y > maxY ) | |
| { | |
| return false; | |
| } | |
| // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html | |
| bool inside = false; | |
| for ( int i = 0, j = polygon.Length - 1 ; i < polygon.Length ; j = i++ ) | |
| { | |
| if ( ( polygon[ i ].Y > p.Y ) != ( polygon[ j ].Y > p.Y ) && | |
| p.X < ( polygon[ j ].X - polygon[ i ].X ) * ( p.Y - polygon[ i ].Y ) / ( polygon[ j ].Y - polygon[ i ].Y ) + polygon[ i ].X ) | |
| { | |
| inside = !inside; | |
| } | |
| } | |
| return inside; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment