Delphi 判断点是否在区域内
function TfrmMain.IsInRect(points: TGpsPointManager; x, y: Double): Boolean; var iSum, iCount, iIndex: Integer; dLon1, dLon2, dLat1, dLat2, dLon: double; ALon, ALat: double; obj1, obj2: TGpsPoint; begin ALon := x; ALat := y; Result := False; iCount := points.Count; if iCount < 3 then begin Result := False; Exit; end; iSum := 0; for iIndex :=0 to iCount - 1 do begin if (iIndex = iCount - 1) then begin obj1 := points.Items[iIndex]; obj2 := points.Items[0]; end else begin obj1 := points.Items[iIndex]; obj2 := points.Items[iIndex + 1]; end; dLon1 := obj1.x; dLat1 := obj1.y; dLon2 := obj2.x; dLat2 := obj2.y; if ((ALat >= dLat1) and (ALat < dLat2)) or ((ALat>=dLat2) and (ALat < dLat1)) then begin if (abs(dLat1 - dLat2) > 0) then begin dLon := dLon1 - ((dLon1 -dLon2) * (dLat1 -ALat)) / (dLat1 - dLat2); if (dLon < ALon) then Inc(iSum); end; end; end; if (iSum mod 2 <> 0) then Result := True; end;
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号