第四章第三题(几何:估算面积)(Geography: estimate areas)

第四章第三题(几何:估算面积)(Geography: estimate areas)

  • *4.3(几何:估算面积)应用4.1节图中以下地点的GPS位置:Georgia州的Atlanta、Florida州的Orlando、Georgia州的Savannah、North Carolina州的Charlotte。计算被这四个城市所围起来的区域的面积。(提示:使用编程练习题4.2中的公式来计算两个城市之间的距离。将多边形分为两个三角形,使用编程练习题2.19中的公式计算三角形面积。)
    *4.3(Geography: estimate areas) Use the GPS locations for Atlanta, Georgia; Orlando, Florida; Savannah, Georgia; and Charlotte, North Carolina in the figure in Section 4.1 to compute the estimated area enclosed by these four cities. (Hint: Use the formula in Programming Exercise 4.2 to compute the distance between two cities. Divide the polygon into two triangles and use the formula in Programming Exercise 2.19 to compute the area of a triangle.)
  • 参考代码:
package chapter04;

public class Code_03 {
    public static void main(String[] args) {
        final double d1, d2, d3, d4, d5, A1, A2;
        final double HalfSumLengthSide1, HalfSumLengthSide2;
        final double x1, y1, x2, y2, x3, y3, x4, y4;
        final double x1Radian,y1Radian,x2Radian,y2Radian;
        final double x3Radian,y3Radian,x4Radian,y4Radian;
        final double EARTH_AVERAGE_RADIUS = 6371.01;

        x1 = 35.2270869;
        y1 = -80.8431267;
        x1Radian = Math.toRadians(x1);
        y1Radian = Math.toRadians(y1);

        x2 = 33.7489954;
        y2 = -84.3879824;
        x2Radian = Math.toRadians(x2);
        y2Radian = Math.toRadians(y2);

        x3 = 32.0835407;
        y3 = -81.0998342;
        x3Radian = Math.toRadians(x3);
        y3Radian = Math.toRadians(y3);

        x4 = 28.5383355;
        y4 = -81.3792365;
        x4Radian = Math.toRadians(x4);
        y4Radian = Math.toRadians(y4);

        d1 = EARTH_AVERAGE_RADIUS * Math.acos(Math.sin(x1Radian) * Math.sin(x2Radian)
                + Math.cos(x1Radian) * Math.cos(x2Radian) * Math.cos(y1Radian - y2Radian));

        d2 = EARTH_AVERAGE_RADIUS * Math.acos(Math.sin(x1Radian) * Math.sin(x3Radian)
                + Math.cos(x1Radian) * Math.cos(x3Radian) * Math.cos(y1Radian - y3Radian));

        d3 = EARTH_AVERAGE_RADIUS * Math.acos(Math.sin(x4Radian) * Math.sin(x2Radian)
                + Math.cos(x4Radian) * Math.cos(x2Radian) * Math.cos(y4Radian - y2Radian));

        d4 = EARTH_AVERAGE_RADIUS * Math.acos(Math.sin(x3Radian) * Math.sin(x4Radian)
                + Math.cos(x3Radian) * Math.cos(x4Radian) * Math.cos(y3Radian - y4Radian));

        d5 = EARTH_AVERAGE_RADIUS * Math.acos(Math.sin(x3Radian) * Math.sin(x2Radian)
                + Math.cos(x3Radian) * Math.cos(x2Radian) * Math.cos(y3Radian - y2Radian));

        HalfSumLengthSide1 = (d1 + d2 + d5) / 2;
        HalfSumLengthSide2 = (d3 + d4 + d5) / 2;

        A1 = Math.pow(HalfSumLengthSide1 * (HalfSumLengthSide1 - d1)
                * (HalfSumLengthSide1 - d2) * (HalfSumLengthSide1 - d5), 0.5);

        A2 = Math.pow(HalfSumLengthSide2 * (HalfSumLengthSide2 - d3)
                * (HalfSumLengthSide2 - d4) * (HalfSumLengthSide2 - d5), 0.5);

        System.out.println("The estimated area enclosed by these four cities is " + (A1 + A2));
    }
}

  • 结果显示:
The estimated area enclosed by these four cities is 117863.34165942381

Process finished with exit code 0

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值