当已经知道所有三个边的长度时,Heron公式将给出三角形的面积。
假设我们有以下三个三角形的边-
s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479;
现在,使用苍鹭公式来找到面积-
area = (s1+s2+s3)/2.0d; resArea = Math.sqrt(area* (area - s1) * (area - s2) * (area - s3));
public class Demo { public static void main(String[] args) { //三角形的边 double s1, s2, s3; double area, resArea; // three三角形的边 s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479; area = (s1+s2+s3)/2.0d; resArea = Math.sqrt(area* (area - s1) * (area - s2) * (area - s3)); System.out.println("Area of Triangle = " + resArea); } }
Area of Triangle = 7689459.767977145