Thread: Polygon

  1. #1
    Mr Ed
    Guest

    Polygon

    I have an array of points which makes up a polygon, i want to find out weather a point lies within the polyon area.
    Is there a build in function for polygons.

    (pss I don't need to draw on screen.)

    I am using Visual C++ 6

  2. #2
    Dorian
    Guest
    I highly doubt that. Try searching the internet, Im sure its out there somewhere

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    It's not a standard function, I think... But the problem is not too hard. Search for "polygon interior". I found this (by Randolph Franklin).

    Code:
    int pnpoly(int npol, float *xp, float *yp, float x, float y)
    {
       int i, j, c = 0;
       for(i = 0, j = npol-1; i < npol; j = i++) 
       {
          if((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) && 
                (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
                      c = !c;
       }
       return c;
    }
    alex

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    There are a couple of win32 API GDI functions that you could use CreatePolygonRgn() to create a region from your points and PtInRegion() to find out if a specific point is in a region.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polygon
    By Ducky in forum Windows Programming
    Replies: 7
    Last Post: 09-01-2008, 05:53 AM
  2. Point in polygon test - spherical coords
    By bhdz in forum C Programming
    Replies: 1
    Last Post: 11-07-2007, 01:25 PM
  3. help how to make polygon
    By gamett711221 in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2005, 08:33 PM
  4. my polygon class
    By ichijoji in forum Game Programming
    Replies: 5
    Last Post: 08-02-2004, 08:42 AM
  5. IDEA: Polygon unions and intersections
    By Magos in forum Contests Board
    Replies: 3
    Last Post: 05-21-2003, 07:16 PM