获得图形区域的麻烦

时间:2014-10-28 05:57:49

标签: java

    import java.util.Scanner;

    public class Hw4Problem1 {
        public static void main(String[] args) {

            Scanner input = new Scanner(System.in);



            double X1 = 35.2270869;
            double Y1 = -80.8431267;
            double X2 = 32.0835407;
            double Y2 = -81.0998342;
            double X3 = 28.5383355;
            double Y3 = -81.3792365;
            double X4 = 33.7489954;
            double Y4 = -84.3879824;

            //Radius*************************]
            double radius= 6731.01;

            // distance=(radius)arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos( y1−y2))
            double charlotteToSavannah = (radius)* Math.acos(Math.sin(X1) * Math.sin(X2)+ Math.cos(X1) * Math.cos(X2)
                    * Math.cos(Y1 - Y2));

            double savannahToAtlanta =  (radius)
                    * Math.acos(Math.sin(X2) * Math.sin(X4)
                    + Math.cos(X2) * Math.cos(X4)
                    * Math.cos(Y2 - Y4));

            // Get distance
            // distance=(radius)arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos( y1−y2))
            double atlantaToCharlotte= (radius)
                    * Math.acos(Math.sin(X4) * Math.sin(X1)
                    + Math.cos(X4) * Math.cos(X1)
                    * Math.cos(Y4 - Y1));


            // ******************************************************************************2

            double savannahToOrlando = (radius)
                    * Math.acos(Math.sin(X2) * Math.sin(X3)
                    + Math.cos(X2) * Math.cos(X3)
                    * Math.cos(Y2 - Y3));


            double orlandoToAtlanta = (radius)
                    * Math.acos(Math.sin(X3) * Math.sin(X4)
                    + Math.cos(X3) * Math.cos(X4)
                    * Math.cos(Y3 - Y4));

            double atlantaToSavannah = 
                    (radius)
                    * Math.acos(Math.sin(X4) * Math.sin(X2)
                    + Math.cos(X4) * Math.cos(X2)
                    * Math.cos(Y4 - Y2));
            // System.out.println("distance: "+distance03);

            double rodistance1 = (charlotteToSavannah);
            double rodistance2 = (savannahToAtlanta);
            double rodistance3 = (atlantaToCharlotte);
            double rodistance01 = (savannahToOrlando);
            double rodistance02 = (orlandoToAtlanta);
            double rodistance03 = (atlantaToSavannah);

            double s1 = (rodistance1 + rodistance2 + rodistance3) / 2;

            double s2 = (rodistance01 + rodistance02 + rodistance03) / 2;

            //=√ s(s−side 1)(s−side 2)(s−side3)
            double area1 = Math.sqrt(s1 * (s1 - rodistance1) * (s1 - rodistance2)
                    * (s1 - rodistance3));
            double area2 = Math.sqrt(s2 * (s2 - rodistance01) * (s2 - rodistance02)
                    * (s2 - rodistance03));

            double totalArea = (area1 + area2);

            System.out.println("The area is: " + totalArea);



        }

    }

计算由这些城市创建的多边形所包围的土地面积。

Radius:  6,371.01 km
s= (side 1+side 2+side3)/2
area_of_triangle=√ s(s−side 1)(s−side 2)(s−side3)

我遇到了这个程序的问题我正在给出错误的答案,我得到了7.048521505923942E7 将比例更改为3并且舍入为17516629.000 它应该是:117863.342 我已经尝试了不同的方法,我仍然得到相同的答案。

0 个答案:

没有答案