怎样确定一个点(TPoint) 是否在某个任意区域(一系列点组成的封闭区域)范围内?(100分)

  • 主题发起人 southbird
  • 开始时间
S

southbird

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样确定一个点(TPoint) 是否在某个任意区域(一系列点组成的封闭区域)范围内?
请大家讨论一下!有什么高效的方法?
 
BOOL PtInRegion(

HRGN hrgn, // handle of region
int X, // x-coordinate of point
int Y // y-coordinate of point
);
 
to: datou

如何将一系列点组成的封闭区域(array of TPoint)与region建立关系?
 
uses Types;
function PtInRect(const Rect: TRect; const P: TPoint): Boolean;
 
creatergn等有一组API
 
PtInRect 很容易实现,TRect是矩形区域,和任意区域差别很大,我要的是一系列点组成的
任意区域范围内!

下面是我以前实现的函数,拿出来抛砖引玉:
{判断屏幕上的点是否在某控件上方}
function PointInControl(point:Tpoint;Control:TControl):Boolean;
begin
result := false;
if ((point.x>Control.Left) and (point.x<Control.Left+Control.Width) and
(point.y>Control.Top) and (point.y<Control.top+Control.height)) then
result := true;
end;

{判断屏幕上的点是否在某矩形区域内}
function PointInRect(point:Tpoint;Rect:TRect):Boolean;
begin
result := false;
if (point.x>=Rect.Left) and (point.x<=Rect.Right) and
(point.y>=Rect.Top) and (point.y<=Rect.Bottom) then
result := true
else
if (Rect.Left=Rect.Right) and (Rect.Left=point.x) then
result := true
else
if (Rect.Top=Rect.Bottom) and (Rect.Top=point.y) then
result := true;

end;
 
实现?老凶,PtInRegion,PTinrect是API,你调用就行了,不用自己实现.
你是功能实际就是用CreatePolygonRgn可实现。你自己创建那个polygonrgn就行了
还有一族函数呢,去看看HELP吧20个左右,都是干这个的
 
查查MSDN,看来是以下两个函数的调有就可搞定了!
HRGN CreatePolygonRgn(
CONST POINT *lppt, // array of points
int cPoints, // number of points in array
int fnPolyFillMode // polygon-filling mode
);

BOOL PtInRegion(
HRGN hrgn, // handle to region
int X, // x-coordinate of point
int Y // y-coordinate of point
);
以前没用过这类函数,看来这两个函数刚好是我想要的,
多谢 datou, menxin 提点,送分了!


 
多人接受答案了。
 
顶部