Skip to content

Instantly share code, notes, and snippets.

@blackymetal
Created July 24, 2014 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackymetal/61ae2de98f9d3bf6a754 to your computer and use it in GitHub Desktop.
Save blackymetal/61ae2de98f9d3bf6a754 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy);
float buffx[3];
float buffy[3];
main()
{
buffx[0] = 1.0; buffy[0] = 1.0;
buffx[1] = 2.0; buffy[1] = 1.0;
buffx[2] = 2.0; buffy[2] = 2.0;
buffx[3] = 1.0; buffy[3] = 2.0;
int result = pnpoly(3, buffx, buffy, 0, 0);
printf("%d", result);
}
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment