求多边形的面积
const MaxPointNum = 65535;
type
PXY = ^TXY;
TXY = record // 点的数据结构
x, y: single;
end;
XYArray = array[0..MaxPointNum] of TXY;
PXYArray = ^XYArray; // 线/面的数据结构
// 积分方法求多边形/面状图形的面积
// 多边形坐标在 xys 中,点数在 nn 中
function AreaOfPolygon(xys: PXYArray; nn: integer):single;
var ii:integer;
ss: single;
begin
ss := 0;
for ii := 0 to nn-2 do
ss := ss + (xys^[ii].y+xys^[ii+1].y) * (xys^[ii].x-xys^[ii+1].x) / 2;
result := abs(ss);
end;
// 判别点(x,y)是否落在多边形内
// 多边形坐标在 xys 中,点数在 nn 中
function isPtInRegion(x, y: single; xys: PXYArray; nn: integer): boolean;
var ii, ncross : integer;
yt, x0, y0, x1, y1, x2, y2 : single;
begin
ncross := 0;
x0 := x; y0 := y;
for ii := 0 to nn-2 do begin
x1 := xys^[ii].X; y1 := xys^[ii].Y;
x2 := xys^[ii+1].X; y2 := xys^[ii+1].Y;
if((x0>=x1) and (x0=x2) and (x00) and ((ncross mod 2) = 1)) then Result := True
else Result := FALSE;
end;