00001 #include <grass/gis.h>
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 static int mystats(double,double,double,double,double *,double *);
00019
00020
00037 int G_pole_in_polygon(double *x,double *y, int n)
00038 {
00039 int i;
00040 double len, area, total_len, total_area;
00041
00042 if (n <= 1)
00043 return 0;
00044
00045 mystats (x[n-1],y[n-1],x[0],y[0],&total_len, &total_area);
00046 for (i = 1; i < n; i++)
00047 {
00048 mystats (x[i-1],y[i-1],x[i],y[i],&len, &area);
00049 total_len += len;
00050 total_area += area;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060 if (total_len < 1.0 && total_len > -1.0)
00061 return 0;
00062
00063 return total_area >= 0.0 ? 1 : -1;
00064 }
00065
00066 static int mystats(
00067 double x0,double y0,double x1,double y1,double *len,double *area)
00068 {
00069 if (x1 > x0)
00070 while (x1-x0 > 180)
00071 x0 += 360;
00072 else if (x0 > x1)
00073 while (x0-x1 > 180)
00074 x0 -= 360;
00075
00076 *len = x0 - x1;
00077
00078 if (x0 > x1)
00079 *area = (x0-x1) * (y0+y1)/2.0;
00080 else
00081 *area = (x1-x0) * (y1+y0)/2.0;
00082
00083 return 0;
00084 }