I have a my rectangle. The application generates another rectangle. It can be more smaller or larger than my rectangle. How can I tell when its rect near of the mine using their X, Y, Weight and Hight?? I do not want to know if is into my rectangle.
我有一个矩形。应用程序生成另一个矩形。它可以比我的矩形更小或更大。如何使用X,Y,重量和高度来判断它在矿井附近的位置?我不想知道是否进入我的矩形。
3 个解决方案
#1
0
Draw 1 or more non-visible shapes that are relative to your rectangle's position that fit your definition of "near", then check to see if these shape(s) intersect with the application-generated rectangle in question.
绘制一个或多个相对于矩形位置的不可见形状,使其符合“near”的定义,然后检查这些形状是否与应用程序生成的矩形相交。
For example, one way you might implement this is drawing a non-visible rectangle that surrounds your rectangle, then checking to see if the surrounding rectangle intersects with the application-generated rectangle.
例如,您可以实现此方法的一种方法是绘制一个围绕矩形的不可见矩形,然后检查周围的矩形是否与应用程序生成的矩形相交。
#2
0
I found the solution! I have calculated the middle point of my rectangle. If the rectangle generated have into the point, is near!
我找到了解决方案!我计算了矩形的中点。如果生成的矩形有点,就近了!
#3
-1
You can use the Math formula to calculate the distance between two points like this:
您可以使用Math公式计算两点之间的距离,如下所示:
double getDistance(int x, int y, int x2, int y2) {
double distance;
distance = Math.sqrt( Math.pow( Math.abs(x2 - x) , 2 ) + Math.pow( Math.abs(y2 - y) , 2 ) );
return distance;
}
#1
0
Draw 1 or more non-visible shapes that are relative to your rectangle's position that fit your definition of "near", then check to see if these shape(s) intersect with the application-generated rectangle in question.
绘制一个或多个相对于矩形位置的不可见形状,使其符合“near”的定义,然后检查这些形状是否与应用程序生成的矩形相交。
For example, one way you might implement this is drawing a non-visible rectangle that surrounds your rectangle, then checking to see if the surrounding rectangle intersects with the application-generated rectangle.
例如,您可以实现此方法的一种方法是绘制一个围绕矩形的不可见矩形,然后检查周围的矩形是否与应用程序生成的矩形相交。
#2
0
I found the solution! I have calculated the middle point of my rectangle. If the rectangle generated have into the point, is near!
我找到了解决方案!我计算了矩形的中点。如果生成的矩形有点,就近了!
#3
-1
You can use the Math formula to calculate the distance between two points like this:
您可以使用Math公式计算两点之间的距离,如下所示:
double getDistance(int x, int y, int x2, int y2) {
double distance;
distance = Math.sqrt( Math.pow( Math.abs(x2 - x) , 2 ) + Math.pow( Math.abs(y2 - y) , 2 ) );
return distance;
}