# point in a polygon

Hi guys,
I would like to do algorithm for point in polygon in my program.

here is my program like this. i have a grid with min(0) and max(6) values along X-axis & Z-axis.i didived into cells , each cell is size of 1 by 1. now i taken one polygon(Hexagon(2,0)(4,0)(6,3)(4,6)(2,6)(0,3)) i gone through winding number algorithm from this link

here i am sending each grid vertex and checking with polygon points by using algorithm
but some how i am missing some points.
i want to render the polygon shape by using TRIANGLES so i want to collect the triangle for the polygon from grid.
if u guys are know what i am doing wrong or any better algorithm give me links

``````// tests for point containment within vecset
// does this by counting segment crossings
// to right of point odd = inside even = outside
static int point_inside(float x, float y, VecSet *vs)
{
int i, xp, yp, count;
float y1, y2, x1, x2;

count = 0;
// for each line segment (assumes first point duplicated last)
for(i = 0, xp=0, yp=1; i < vs->size; i++, xp+=2, yp+=2)
{
if(i == vs->size-1)
{
if(*(vs->data+yp) > *(vs->data+1))
{
x1 = *(vs->data);
x2 = *(vs->data+xp);
y1 = *(vs->data+1);
y2 = *(vs->data+yp);
}
else
{
x2 = *(vs->data);
x1 = *(vs->data+xp);
y2 = *(vs->data+1);
y1 = *(vs->data+yp);
}
}
else
{
if(*(vs->data+yp) > *(vs->data+yp+2))
{
x1 = *(vs->data+xp+2);
x2 = *(vs->data+xp);
y1 = *(vs->data+yp+2);
y2 = *(vs->data+yp);
}
else
{
x2 = *(vs->data+xp+2);
x1 = *(vs->data+xp);
y2 = *(vs->data+yp+2);
y1 = *(vs->data+yp);
}
}
// check vertical bounds with point then possible right side containment
if(y >= y1 && y < y2 && (x < x1 &#0124;&#0124; x < x2 ) )
{
// check for left hand side of line
if( x < x1 + (x2 - x1) * ( (y - y1)/(y2 - y1) ) )
{
count = !count;
}
}
}

return count;
}
``````

its working fine,Thank you for the Great Help.