输入的三个角的顶点坐标计算三个角值(非弧度)

/**
 * 要求根据用户输入的三个角的顶点坐标计算三个角值(非弧度)
 * 1、两点之间的公式:Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2));
 * 2、可以通过以下公式计算角度(弧度):
 *     A = acos((a*a-b*b-c*c) / (-2 * b * c))
 *     A = acos((b*b-a*a-c*c) / (-2 * a * c))
 *     A = acos((c*c-b*b-a*a) / (-2 * b * c))
 * @author Monster丶ZF
 * @version1.8
 * @data 2019年4月18日
 * @remakeTODO
 */
public class CalcAnglesDemo {
	public static void main(String[] args) {
		  //1.设置三个顶点的坐标
		 int x1 = 100, y1 = 150;
		 int x2 = 255, y2 = 66;
		 int x3 = 360,y3 =220;
		//2.根据公式计算每条边的边长
		 double a = Math.sqrt(Math.pow(x2 - x3, 2) + Math.pow(y2 - y3, 2));
		 double b = Math.sqrt(Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2));
		 double c = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
		//3.根据公式计算三个角的弧度
		 double radianA = Math.acos((a*a-b*b-c*c) / (-2 * b * c));
		 double radianB = Math.acos((b*b-a*a-c*c) / (-2 * a * c));
		 double radianC = Math.acos((c*c-b*b-a*a) / (-2 * b * c));
		  //4.将弧度转化为度
		double degreeA = Math.toDegrees(radianA);
		double degreeB = Math.toDegrees(radianB);
		double degreeC = Math.toDegrees(radianC);
		 //System.out.println("A角:" + degreeA + "\t" + "B角:" + degreeB + "\t" + "C角:" + degreeC);
         String str = String.format("A角:%.2f  B角:%.2f  C角:%.2f", degreeA,degreeB,degreeC);
         System.out.println(str);
         
      // System.out.println(Math.exp(2));
      // System.out.println(Math.log(Math.E));
	}
	
}

猜你喜欢

转载自blog.csdn.net/w15977858408/article/details/89385472