Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Point in Polygon?

Point in Polygon?

Scheduled Pinned Locked Moved C#
csharpcomgraphicsalgorithmsquestion
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Rolando
    wrote on last edited by
    #1

    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

    C A 2 Replies Last reply
    0
    • D Don Rolando

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      D 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        D Offline
        D Offline
        Don Rolando
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • D Don Rolando

          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

          A Offline
          A Offline
          AikinX
          wrote on last edited by
          #4

          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();

          D 1 Reply Last reply
          0
          • A AikinX

            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();

            D Offline
            D Offline
            Don Rolando
            wrote on last edited by
            #5

            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! :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups