CJC Delphi 技巧馆's Archiver

cjc Posted at 2012-1-16 00:30

Is point in polygon (PointInPoly, 判断一个点是否在多边形内)

Is point in polygon (PointInPoly, 判断一个点是否在多边形内)

// Based on http://paulbourke.net/geometry/insidepoly/
// C++ : http://alienryderflex.com/polygon/

type point = record
              x,y : double;
             end;

type polygon = array of point;

var firstx : double = -1;
    firsty : double = -1;
    poly   : polygon;

function PointInPoly(p : point;poly : polygon) : Boolean;
var i,j : integer;
Begin
result := false;
j := High(poly);
For i := Low(poly) to High(poly) do begin
  if (
   ( ((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and (p.y < poly[i].y)) ) and
   (p.x < ((poly[j].x - poly[i].x) * (p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))
  ) then result := not result;
  j := i
end;
End;

Page: [1]
CJC好玩背单词最新版本 - 是目前最好的背单词软件,游戏好玩,功能强大,词库众多,还有真人语音,免费下载,免费试用 !

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.