# Problems with the polygon knit winding algorithm

I am trying to implement the winding number and the ray conversion algorithm for the problem from point to polygon. I'm following this implementation idea here for the winding number: http://geomalgorithms.com/a03-_inclusion.html#wn_PnPoly (). My code produces correct results for lightning something, but I can not understand why exactly the code does not work for the winding something. I checked the code and something many, many times, but I still do not understand why the problem with `printf ("winding number 1.5, 3.0. 0 real,% d n real", pipWindingNumber (1.5, 3.0));` Persists (real and current should be the same).

Fragment in C

``````#include
#include

sides const int = 4;
float X = {3.0, 7.0, 7.0, 2.0};
float Y = {4.0, 4.0, 2.0, 2.0};

bool pipRayCasting (float x, float y)
{
int i;
int j = sides - 1;

bool pip = false;

for (i = 0; i <sides; i ++) {
Yes, and[i] < y && Y[j] >= y || Y[j] < y && Y[i] >= y) && (X[i] <= x || X[j] <= x)) {
pip ^ = (X[i] + (and - Y[i]) / (Y[j] - Y[i]) * (X[j] - X[i]) <x);
}

j = i;
}

pip return
}

int pipWindingLineSide (float xl0, float yl0, float xl1, float yl1, float xp, float and p)
{
return ((xl1 - xl0) * (yp - yl0) - (xp - xl0) * (yl1 - yl0));
}

bool pipWindingNumber (float x, float y)
{
int i;
winding int = 0;

for (i = 0; i <sides; i ++) {
Yes, and[i] <= y) {
if (Y[i + 1] >    Y) {
yes (pipWindingLineSide (X[i], Y[i], X[i + 1], Y[i + 1], x, y)> 0) {
++ winding;
}
}
} else {
Yes, and[i + 1] <= y) {
yes (pipWindingLineSide (X[i], Y[i], X[i + 1], Y[i + 1], x, y) < 0) {
--winding;
}
}
}
}

return winding == 0 ? false : true;
}

int main()
{
/* printf("point above line? %dn", pipWindingLineSide(1.0, 1.0, 2.0, 2.0, 1.0, 3.0) > 0); * /
/ * printf ("point below the line?% d  n", pipWindingLineSide (1.0, 1.0, 2.0, 2.0, 3.0, 1.0) <0); * /
/ * printf ("point on line?% d  n", pipWindingLineSide (1.0, 1.0, 2.0, 2.0, 3.0, 3.0) == 0); * /
printf ("ray casting 3.0, 2.5, Real 1, real% d  n", pipRayCasting (3.0, 2.5));
printf ("ray casting 1.5, 3.0. 0 real,% d  n" real, pipRayCasting (1.5, 3.0));
printf ("ray casting 5.0, 4.5. 0 real,% d  n" real, pipRayCasting (5.0, 4.5));
printf ("ray casting 6.0, 3.5 Real 1, real% d  n", pipRayCasting (6.0, 3.5));
printf ("winding number 3.0, 2.5.Real 1,% d  n" real, pipWindingNumber (3.0, 2.5));
printf ("winding number 1.5, 3.0. 0 real,% d  n real", pipWindingNumber (1.5, 3.0));
printf ("real winding number 5.0, 4.5. 0,% d  n" real, pipWindingNumber (5.0, 4.5));
printf ("winding number 6.0, 3.5.Real 1,% d  n" real, pipWindingNumber (6.0, 3.5));
}
``````