android 计算点是否在扇形区域

1. 三个点:圆心A,半径r,度数0的点B,任意点C.

先计算∠BAC的度数(弧度)。

 

public double calculatorDegree(float x1, float y1, float x2, float y2, float x3, float y3) {
		double radian = 0;

		double ab = getDistance(x1, y1, x2, y2);
		double ac = getDistance(x1, y1, x3, y3);
		double bc = getDistance(x2, y2, x3, y3);

		double value = (ab * ab + ac * ac - (bc * bc)) / (2 * ab * ac);

		radian = Math.acos(value);

		return radian;
	}

	public double getDistance(float x1, float y1, float x2, float y2) {
		double distance = 0;
		distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
		return distance;
	}

 

2. 根据弧度计算度数并且计算AC距离。

 

float x = event.getX();
		float y = event.getY();
		double radian = calculatorDegree(width / 2, height / 2, width / 2 + radius, height / 2, x, y);
		double degree =  (180 / Math.PI * radian);
		double distance = getDistance(width / 2, height / 2, x, y);

 3,根据度数和距离计算。

使用度数前先判断是否用补角。

 

计算扇型弧线起始点坐标:

 (float) (center_X + r * Math.cos(startAngle * Math.PI / 180)),(float) (center_Y + r * Math.sin(startAngle * Math.PI / 180))

 

 

你可能感兴趣的:(andorid)