I didn't add the drawing reference. Not my day. Thank you Richard. It works
User 11889214
Posts
-
Check if xy point is within a polygon Console App -
Check if xy point is within a polygon Console AppI have create a Win form app and create Polygons as follows: private List> Polygons = new List>(); I store this polygons with Xml.Serialization, into a MySQL database as string and Deserialize it with my console app into a list of polygons again. In my console app, which eventually is going to run from Raspberry Pi, I'm getting data from USB, which consist of floating X and floating Y coordinates. Now I want to know how do I check if this point is within one of the polygons. I've tried it first with WinForms app and it works great. public static bool IsPointInPolygon(IList polygon, PointF testPoint) { try { bool result = false; int j = polygon.Count() - 1; for (int i = 0; i < polygon.Count(); i++) { if (polygon[i].Y < testPoint.Y && polygon[j].Y >= testPoint.Y || polygon[j].Y < testPoint.Y && polygon[i].Y >= testPoint.Y) { if (polygon[i].X + (testPoint.Y - polygon[i].Y) / (polygon[j].Y - polygon[i].Y) * (polygon[j].X - polygon[i].X) < testPoint.X) { result = !result; } } j = i; } return result; } catch (Exception ex) { MessageBox.Show("error - " + ex.ToString()); return false; } I don't want to draw something, I know it's a console app, just getting a bool or int value back from the Test. Any suggestions or help please?