使用IntersectRect函数,判断控件是否在选择区域中。

处理控件多选问题

多选框可以使用

TrackRubberBand(this,point) ;

判断控件是否在选择区域中

 if (IntersectRect(&rcTmp, &rcBmp, &rcTarget)) 

有交集返回值是非0,没有交集返回0,

在Java判断两条线段是否相交可以使用向量叉积的性质。基本思想是判断两条线段所构成的矩形是否相交,如果矩形相交,再判断它们在相交矩形内的投影是否也相交。以下是一个简单的判断逻辑: 1. 首先计算两条线段AB和CD的四个端点坐标。 2. 判断AB是否与CD所在的矩形相交,可以通过比较AB两端点的横纵坐标是否分别处于CD两端点横纵坐标形成的矩形内。同样的方法也可以用来判断CD是否与AB所在的矩形相交。 3. 如果两个矩形相交,进一步判断AB和CD是否在矩形相交区域也相交。这可以通过计算向量叉积来判断。向量叉积的符号可以表示向量的方向,如果线段的两个端点分别与另一线段的两个端点构成的向量叉积符号相同,则说明两线段不相交。 4. 如果以上条件都满足,则说明AB和CD相交。 需要注意的是,如果线段共线,这种情况需要单独处理,因为共线时可能部分重合或者完全不相交。 以下是相应的Java代码示例: ```java public class LineSegment { public Point start; public Point end; public LineSegment(Point start, Point end) { this.start = start; this.end = end; } public boolean isIntersect(LineSegment other) { // 检查两个矩形是否相交 if (!this.intersectRect(other)) return false; // 计算叉积 int crossProduct1 = crossProduct(this.start, this.end, other.start); int crossProduct2 = crossProduct(this.start, this.end, other.end); int crossProduct3 = crossProduct(other.start, other.end, this.start); int crossProduct4 = crossProduct(other.start, other.end, this.end); // 如果叉积的符号不全相同,则线段相交 if (crossProduct1 * crossProduct2 < 0 && crossProduct3 * crossProduct4 < 0) { return true; } return false; } // 计算向量叉积 private int crossProduct(Point p1, Point p2, Point p3) { int dx1 = p2.x - p1.x; int dy1 = p2.y - p1.y; int dx2 = p3.x - p1.x; int dy2 = p3.y - p1.y; return dx1 * dy2 - dy1 * dx2; } // 判断两个线段是否处于同一个矩形内 private boolean intersectRect(LineSegment other) { int minX = Math.min(this.start.x, this.end.x); int maxX = Math.max(this.start.x, this.end.x); int minY = Math.min(this.start.y, this.end.y); int maxY = Math.max(this.start.y, this.end.y); int otherMinX = Math.min(other.start.x, other.end.x); int otherMaxX = Math.max(other.start.x, other.end.x); int otherMinY = Math.min(other.start.y, other.end.y); int otherMaxY = Math.max(other.start.y, other.end.y); return !(maxX < otherMinX || minX > otherMaxX || maxY < otherMinY || minY > otherMaxY); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白的编程日志

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值