Java语言程序设计(基础篇)第十版 4.3(几何:估算面积)

本文通过使用Java编程语言,计算了基于经纬度坐标的城市之间的距离,并进一步计算了一个由四个城市构成的四边形的面积。涉及到的主要城市包括亚特兰大、奥兰多、萨凡纳和夏洛特。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


public class J4_3 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		double atlantaLatitude = 33.7490;
		double atlantaLongitude = 84.3880;
		
		double x1 =Math.toRadians(atlantaLatitude);
		double y1 =Math.toRadians(atlantaLongitude);
		
		double orlandoLatitude = 28.5383;
		double orlandoLongitude = 81.3792;
		
		double x2 =Math.toRadians(orlandoLatitude);
		double y2 =Math.toRadians(orlandoLongitude);
		
		double savannahLatitude = 32.0809;
		double savannahLongitude = 81.0912;
		
		double x3 = Math.toRadians(savannahLatitude);
		double y3 = Math.toRadians(savannahLongitude);
		
		double charlotteLatitude = 35.2271;
		double charlotteLongitude = 80.8431;
		
		double x4 = Math.toRadians(charlotteLatitude);
		double y4 = Math.toRadians(charlotteLongitude);
		
		double r = 6371.01;
		
		double arccosA = Math.sin(x1)*Math.sin(x2)+
						 Math.cos(x1)*Math.cos(x2)*Math.cos(y1-y2);
		
		double A = r * Math.acos(arccosA);//the distance is from Atlanta to Orlando 
		
		double arccosB = Math.sin(x2) *Math.sin(x3)+
						 Math.cos(x2) *Math.cos(x3)*Math.cos(y2-y3);
		
		double B = r * Math.acos(arccosB);//the distance is from Orlando to Savannah
		
		double arccosC = Math.sin(x3) *	Math.sin(x4)+
						 Math.cos(x3) *Math.cos(x4)*Math.cos(y3-y4);
		
		double C = r * Math.acos(arccosC);//the distance is from Savannah to Charlotte
		
		double arccosD = Math.sin(x1) * Math.sin(x4)+
						 Math.cos(x1) *Math.cos(x4)*Math.cos(y1-y4);
		
		double D = r * Math.acos(arccosD);//the distance is from Atlanta to Charlotte
		
		double arccosML = Math.sin(x2) * Math.sin(x4)+
								  Math.cos(x2) * Math.cos(x4) * Math.cos(y2-y4);
		// The quadrilateral middle line;
		
		double ML = r * Math.acos(arccosML);
		
		double S1 = (A +D+ML)/2;
		double S1_1 = S1* (S1-A)*(S1-D)*(S1-ML);
		double area1 =  Math.sqrt(S1_1);
		
		double S2 = (B+C+ML)/2;
		double S2_1 =S2 *(S2-B)*(S2-C)*(S2-ML);
		double area2 = Math.sqrt(S2_1);
		
		double area = area1 +area2 ;
		System.out.println("The area is : " + area);
		
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值