IsPointInPolygon2D

= Implementations =
This implementation is adapted from the original found here. Please include the copyright comments below when using this code. See original page for indepth discussion of usage.
== Copyright ==
/*//-- LSL Port 2009 Void Singer --//*/
/*//-- Copyright (c) 1970-2003, Wm. Randolph Franklin	--//*/
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimers.
2. Redistributions in binary form must reproduce the above copyright notice
 in the documentation and/or other materials provided with the distribution.
3. The name of W. Randolph Franklin may not be used to endorse or promote
 products derived from this Software without specific prior written permission
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. 
*/
== Code ==
It should be noted that this vector version is typically faster (fewer function calls), and will actually use less memory (due to the overhead of list entries). It is therefore preferable to try and re-write your script to use vectors in favour of using the float-pair version unless you have no choice.
Vector version:
integer isPointInPolygon2D( list vLstPolygon, vector vPosTesting ){
	integer vBooInPlygn;
	integer vIntCounter = [] != vLstPolygon;
	vector vPosVertexA = llList2Vector( vLstPolygon, vIntCounter );
	vector vPosVertexB;
	
	while (vIntCounter){
		vPosVertexB = vPosVertexA;
		vPosVertexA = llList2Vector( vLstPolygon, ++vIntCounter );
		
		if ((vPosVertexA.y > vPosTesting.y) ^ (vPosVertexB.y > vPosTesting.y)){
			if (vPosTesting.x < (vPosVertexB.x - vPosVertexA.x) * (vPosTesting.y - vPosVertexA.y) /
			 (vPosVertexB.y - vPosVertexA.y) + vPosVertexA.x ){
				vBooInPlygn = !vBooInPlygn;
			}
		}
	}
	return vBooInPlygn;
}
Float Pair Version:
integer isPointInPolygon2D_XY( list vLstPolygonXY, float vFltTesting_X, float vFltTesting_Y ){
	integer vBooInPlygnXY;
	integer vIntCounterXY = ([] != vLstPolygonXY);
	float vFltVertexA_X = llList2Float( vLstPolygonXY, -2 );
	float vFltVertexA_Y = llList2Float( vLstPolygonXY, -1 );
	float vFltVertexB_X;
	float vFltVertexB_Y;
	
	while (vIntCounterXY){
		vFltVertexB_X = vFltVertexA_X;
		vFltVertexB_Y = vFltVertexA_Y;
		vFltVertexA_X = llList2Float( vLstPolygonXY, vIntCounterXY++ );
		vFltVertexA_Y = llList2Float( vLstPolygonXY, vIntCounterXY++ );
		
		if ((vFltVertexA_Y > vFltTesting_Y) ^ (vFltVertexB_Y > vFltTesting_Y)){
			if (vFltTesting_X < (vFltVertexB_X - vFltVertexA_X) * (vFltTesting_Y - vFltVertexA_Y) /
			 (vFltVertexB_Y - vFltVertexA_Y) + vFltVertexA_X ){
				vBooInPlygnXY = !vBooInPlygnXY;
			}
		}
	}
	return vBooInPlygnXY;
}