Code and KML for partial UK polygon.
coordinate cutdownpoly[17] =
{ // Latitude,Longtitude
53.166F,-2.166F, // 0 15K N Stoke-On-Trent (datum)
53.166F,-0.1F, // 1 30K W Skegness (125K east of datum)
52.833F,-0.1F, // 2 5Km N Spalding
52.7F,0.333F, // 3 5Km SW Kings Lynn
52.87F,0.7F, // 4
52.833F,1.25F, // 5
52.666F,1.5F, // 6
52.416F,1.5F, // 7
52.083F,1.166F, // 8 Westerfield N of Ipswitch
51.666F,0.3F, // 9 5Km N of Brentwood
51.666F,-0.666F, // 10 10K NW High Wycombe
51.166F,-0.666F, // 11 Godalming
51.166F,-2.166F, // 12 Warminster
52.333F,-2.166F, // 13
52.333F,-1.666F, // 14
52.666F,-1.666F, // 15
52.666F,-2.166F, // 16
};
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
<name>Small UK</name>
<Style>
<LineStyle>
<color>ff0000ff</color>
</LineStyle>
</Style>
<LineString>
<altitudeMode>absolute</altitudeMode>
<coordinates>
-2.166,53.166
-0.1,53.166
-0.1,52.833
0.333,52.7
0.7,52.87
1.25,52.833
1.5,52.666
1.5,52.416
1.166,52.083
0.3,51.666
-0.666,51.666
-0.666,51.166
-2.166,51.166
-2.166,52.333
-1.666,52.333
-1.666,52.666
-2.166,52.666
</coordinates>
</LineString>
</Placemark>
</kml>
A C function to test if a point (x, y) is inside a polygon (poly, points). Returns 0 if outside, !0 if inside the polygon. poly points to an array of x, y coordinates of the polygon. points is the number of points in the array.
int pointinpoly(float *poly, int points, float x, float y) { float *p = poly; float *l = &poly[points * 2 - 2]; int c = 0; for(; points; points--, l = p, p += 2) { if(y < p[1] && y < l[1]) continue; if(y >= p[1] && y >= l[1]) continue; if(x < p[0] + (l[0] - p[0]) * (y - p[1]) / (l[1] - p[1])) continue; c = !c; } return(c); }