Point in Polygon?
-
Is there any PointInPolygon function in C#, or more generally in .NET? I guess this free shapened button uses something I am searching for [Shapes and Regions], but it's using an assembly, so I cannot look how it's actually done. ;) There are intersection tests and stuff for rectangles and circles... but the Polygon class is only available for .NET 3.0 I would require it on .NET 2 and .NET CF 2 Does anyone have source, so I have not to do polygon triangulation and to test per triangle? Or can I use the PtInRegion method from good old GDI somehow, as I would do in VC? ;) thanks in advance, Roland
-
Is there any PointInPolygon function in C#, or more generally in .NET? I guess this free shapened button uses something I am searching for [Shapes and Regions], but it's using an assembly, so I cannot look how it's actually done. ;) There are intersection tests and stuff for rectangles and circles... but the Polygon class is only available for .NET 3.0 I would require it on .NET 2 and .NET CF 2 Does anyone have source, so I have not to do polygon triangulation and to test per triangle? Or can I use the PtInRegion method from good old GDI somehow, as I would do in VC? ;) thanks in advance, Roland
You can definately use p/invoke to call any windows API you like. I don't know of any libraries tho.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You can definately use p/invoke to call any windows API you like. I don't know of any libraries tho.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Invoking native API from C#? Mhm, I guess that's too much for my current c# skills. Especially since I would need a representation for the CRegion equivalent in C# so the api can work with it. Sounds not more easy than the triangulation approach, does it? Besides, why can't the Compact Framework simply offer the GraphicsPath class, so I could construct my polygon as Region? Grrr.... can I trick somehow with RegionData!? I guess not. :( Thanks so far anyhow!
-
Is there any PointInPolygon function in C#, or more generally in .NET? I guess this free shapened button uses something I am searching for [Shapes and Regions], but it's using an assembly, so I cannot look how it's actually done. ;) There are intersection tests and stuff for rectangles and circles... but the Polygon class is only available for .NET 3.0 I would require it on .NET 2 and .NET CF 2 Does anyone have source, so I have not to do polygon triangulation and to test per triangle? Or can I use the PtInRegion method from good old GDI somehow, as I would do in VC? ;) thanks in advance, Roland
It is easy to get the answer for a Region:
Region r = new Region(new Rectangle(0, 0, 100, 100)); Point p = new Point(99,10); bool b = r.IsVisible(p);
If you region is not simple one you have to use GraphicsPath to build the region:GraphicsPath path = new GraphicsPath(); path.AddRectangle(new Rectangle(0, 4, 2, 5)); path.AddEllipse (new Rectangle(4, 2, 7, 10)); //...... Region region = new Region(path); path.Dispose();
-
It is easy to get the answer for a Region:
Region r = new Region(new Rectangle(0, 0, 100, 100)); Point p = new Point(99,10); bool b = r.IsVisible(p);
If you region is not simple one you have to use GraphicsPath to build the region:GraphicsPath path = new GraphicsPath(); path.AddRectangle(new Rectangle(0, 4, 2, 5)); path.AddEllipse (new Rectangle(4, 2, 7, 10)); //...... Region region = new Region(path); path.Dispose();
As I wrote in my first post, and 5 minutes before yours: I must also work with compact framework, and there is no graphicspath available. :( But thanks anyhow! :)