两个Rect(rect1,rect2),有没有一种快速的方法判断rect2是否在rect1之内?(40分)

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

sxwy

Unregistered / Unconfirmed
GUEST, unregistred user!
Var Tmprect1,Tmprect2:TRect;
begin
// Rect1定义
Tmprect1.Left := 0;
Tmprect1.Top := 0;
Tmprect1.Right := 100;
Tmprect1.Bottom:=100;

// Rect2定义
Tmprect2.Left := 80;
Tmprect2.Top := 90;
Tmprect2.Right := 180;
Tmprect2.Bottom := 190;

从以上看来,TMPRECT2肯定在TMPRECT1的范围之内,因为TMPRECT2.LEFT=80(在TMPRECT1的宽度之内)
但用程序如何判断呢.大家帮一下忙,谢.
 
parent属性?
 
怎么实现呢.
 
听不明白你说的是什么
BEGIN
 
return (rect1.left <= rect2.left) and (rect1.top <= rect2.top) and (rect1.right >= rect2.right) and (rect1.bottom >= rect2.bottom);
返回 rect2 是否在 rect1 内,很简单啊,没有更简单的拉
 
要可靠一点的呀.最好是API好一点.
万一没有API也只好这样了.
 
if ptInRect(tmprect2, tmprect1.topleft) or ptInRect(temprect2,tmprect1.bottomRight) then
showmessage('包括在内了');
 
多谢,我试试.
 
判断顶点坐标可以实现的...
 
Var Tmprect1,Tmprect2,Tmprect3:TRect;
begin
// Rect1定义
Tmprect1.Left := 0;
Tmprect1.Top := 0;
Tmprect1.Right := 100;
Tmprect1.Bottom:=100;

// Rect2定义
Tmprect2.Left := 80;
Tmprect2.Top := 90;
Tmprect2.Right := 180;
Tmprect2.Bottom := 190;
if IntersectRect(Tmprect3,Tmprect1,Tmprect2) then begin
showmessage('两个区域相交');//IntersectRect函数为自代函数,可以判断两个矩形是否相交,相交返回True并返回相交区域TRect,否返回Flase;
end
else
showmessage('两个区域不相交');//
end;
 
多人接受答案了。
 
后退
顶部