paparazzi-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Paparazzi-devel] Point in polygon / point on line problem


From: nisma
Subject: [Paparazzi-devel] Point in polygon / point on line problem
Date: Wed, 13 Jul 2005 06:42:30 -0400

Hi to all, 
maybe this fragment of code is what you need.

   typedef struct {int x, y;} point;

   int
   isOnLine( point l0, point l1, point p )
   // return -/0/+ if a point (p) is left/On/right of an infinite line (l0,l1)
   { return 0-((l1.x-l0.x)*(p.y-l0.y)-(p.x-l0.x)*(l1.y-l0.y)); }

   //===================================================================

   int
   inPolygon(point p, point* v, int n)
   //    p = a point,
   //    v[] = vertex points of a polygon v[n+1] with v[n]=v[0]
   //    return:  the winding number (=0 if p is outside v[])
   int
   {
       int    cn = 0,i;
       for(i=0;i<n;i++) 
           if(v[i].y<=p.y){if(v[i+1].y>p.y)if(isOnLine(v[i],v[i+1],p)<0)++cn;
           }else{if(v[i+1].y<=p.y)if(isOnLine(v[i],v[i+1],p)>0)--cn;}
       return cn;
   }


Cheers
Chris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]