以图片左上角为(0,0),以区域A(x,y,width,height)为中心,A矩形的中心位置为(x0,y0),B(x,y,width,height)为界面中圆上“上下左右”四个方向的一个位置,B矩形中心位置为(x1,y1)。
A在B内
B.x < A.x 且 A.x+A.width < B.x + B.width
B.y < A.y 且 A.y + A.height < B.y + B.height

其他四个方位角度的计算
alpha= Arcsin(abs(y1-y0)/sqrt((y1-y0)2+(x1-x0)2))*180/Pi
最后得到的角度theta值是根据alpha以及x1-x0,y1-y0的符号不同用下表中的条件加以判断
21

用代码表示:

/**
 * 判断一个图片的两个区域的位置关系
 * @param q1 图片中区域1
 * @param q2 图片中区域2
 * @param direction 12345对应上下左右中
 * @return 是否在指定的位置上
 */
private boolean judgeDirection(ImageRect q2, ImageRect q1, String direction)
{
	boolean value = false;
	int idirection = Integer.parseInt(direction);
	String[] q1_dot = q1.getRegion_dot().split(",");
	String[] q2_dot = q2.getRegion_dot().split(",");
	double x0 = Double.parseDouble(q1_dot[0]);
	double y0 = Double.parseDouble(q1_dot[1]);
	double x1 = Double.parseDouble(q2_dot[0]);
	double y1 = Double.parseDouble(q2_dot[1]);
	double alpha = Math.asin(Math.abs(y1 - y0) / Math.sqrt((Math.pow((y1 - y0), 2) + Math.pow((x1 - x0), 2)))) * 180 / Math.PI;
	double theta = alpha;
	if ((x1 - x0) > 0 && (y1 - y0) <= 0)
	{
		theta = alpha;
	}
	else if ((x1 - x0) <= 0 && (y1 - y0) < 0)
	{
		theta = 180 - alpha;
	}
	else if ((x1 - x0) < 0 && (y1 - y0) >= 0)
	{
		theta = 180 + alpha;
	}
	else if ((x1 - x0) >= 0 && (y1 - y0) > 0)
	{
		theta = 360 - alpha;
	}
	switch (idirection)
	{
		case 1:
			value = 45 <= theta && theta <= 135;
			break;
		case 2:
			value = 225 <= theta && theta <= 315;
			break;
		case 3:
			value = 135 < theta && theta < 225;
			break;
		case 4:
			value = (0 < theta && theta < 45) || (315 < theta && theta < 360);
			break;
		case 5:
			value = q2.getX() < q1.getX() && (q1.getX() + q1.getRegion_width()) < (q2.getX() + q2.getRegion_width()) && q2.getY() < q1.getY() && (q1.getY() + q1.getRegion_height()) < (q2.getY() + q2.getRegion_height());
			break;
	}
	return value;
}