I want the user to define a polygon by using his mouse and clicks to define the points. The second task is once i have a set of defined polygons i want to check if some randomly generated points lie within any of those polygons.
I am working on C# .net platform. Thanks.
This is not a simple task. For instance, you should analyze and sort the set of points as Convex or Concave Hull. You can use the following links as resources:
http://ubicomp.algoritmi.uminho.pt/local/concavehull.html
http://marknelson.us/2007/08/22/convex/
Is there an efficient algorithm to generate a 2D concave hull?
http://courses.csail.mit.edu/6.854/06/scribe/s26-randomIC.pdf
http://softsurfer.com/Archive/algorithm_0109/algorithm_0109.htm
Old thread, but straight forward solution. This is actually pretty simple if you make full use of the Graphics and Drawing2D namespaces.
GraphicsPath.AddLines( Point[] )
Graphics.DrawPath( Drawing2D.GraphicsPath )
Graphics.FillPath( Drawing2D.GraphicsPath )
So you'd simply create a new path, then call AddLines passing your array of points, and then call CloseFigure.
If you want to stroke it with a pen, use DrawPath. If you want to fill it with a brush, use FillPath.
Hit test for any points inside the polygon is simple as well, you would use Drawing.Region( Drawing2D.GraphicsPath ) and any overload of Region.IsVisible that allows you to specify a position and graphics object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.