T
ThomasW
Hi all,
I'm not a very experienced C programmer and probably miss something
very basic, so please forgive me.
I modified a function that tests whether a point lies within a polygon
(from the comp.graphics.algorithms FAQ at http://www.cgafaq.info/wiki/Point_in_polygon).
Instead of two one-dimensional arrays I wanted to use one two-
dimensional array as argument. But I can't figure out how to call it
properly. Can someone help me?
Thanks a lot, and here is the code:
#include <stdio.h>
int pnpoly(int npol, long int *p[2], long int x, long int y)
{
int i, j, c = 0;
for (i = 0, j = npol-1; i < npol; j = i++) {
if ((((p[1]<=y) && (y<p[j][1])) ||
((p[j][1]<=y) && (y<p[1]))) &&
(x < (p[j][0] - p[0]) * (y - p[1]) / (p[j][1] - p[1])
+ p[0]))
c = !c;
}
return c;
}
int main()
{
long int path[4][2]={{0,0},{100,0},{100,100},{0,100}};
//what do I have to write instead of path[0]
//to get the correct pointer type?
printf("%d\n",pnpoly(4,path[0],50,50));
return 0;
}
I'm not a very experienced C programmer and probably miss something
very basic, so please forgive me.
I modified a function that tests whether a point lies within a polygon
(from the comp.graphics.algorithms FAQ at http://www.cgafaq.info/wiki/Point_in_polygon).
Instead of two one-dimensional arrays I wanted to use one two-
dimensional array as argument. But I can't figure out how to call it
properly. Can someone help me?
Thanks a lot, and here is the code:
#include <stdio.h>
int pnpoly(int npol, long int *p[2], long int x, long int y)
{
int i, j, c = 0;
for (i = 0, j = npol-1; i < npol; j = i++) {
if ((((p[1]<=y) && (y<p[j][1])) ||
((p[j][1]<=y) && (y<p[1]))) &&
(x < (p[j][0] - p[0]) * (y - p[1]) / (p[j][1] - p[1])
+ p[0]))
c = !c;
}
return c;
}
int main()
{
long int path[4][2]={{0,0},{100,0},{100,100},{0,100}};
//what do I have to write instead of path[0]
//to get the correct pointer type?
printf("%d\n",pnpoly(4,path[0],50,50));
return 0;
}