Java黑皮书课后题第4章:*4.3(几何:估算面积)应用4.1节图中以下地点的GPS位置:Georgia州的Atlanta……计算被这四个城市所围起来的区域面积
*4.3(幾何:估算面積)應用4.1節圖中以下地點的GPS位置:Georgia州的Atlanta、Florida州的Orlando、Georgia州的Savannah、North Carolina的Charlotte。計算被這四個城市所圍起來的區域面積
- 題目
- 題目概述
- 編程練習題2.19與4.2、4.1節圖
- 2.19公式:計算三角形面積的公式(處理后)
- 4.2公式
- 4.1節圖的概括
- 破題
- 程序
題目
題目概述
*4.3(幾何:估算面積)應用4.1節圖中以下地點的GPS位置:Georgia州的Atlanta、Florida州的Orlando、Georgia州的Savannah、North Carolina的Charlotte。計算被這四個城市所圍起來的區域面積
提示:使用編程練習題4.2中的公式來計算兩個城市之間的距離,將多邊形分為兩個三角形,使用編程練習題2.19中的公式計算三角形面積
編程練習題2.19與4.2、4.1節圖
點擊這里跳轉到我的2.19博文,或者復制url到瀏覽器即可:
https://blog.csdn.net/weixin_46356698/article/details/119791257
點擊這里跳轉到我的4.2博文,或復制url到瀏覽器:
https://blog.csdn.net/weixin_46356698/article/details/119823330
2.19公式:計算三角形面積的公式(處理后)
s = (side1 + side2 + side3) / 2
area = Math.pow(s*(s-side1)(s-side2)(s-side3), 0.5)
4.2公式
假設(x1,y1)和(x2, y2)是兩個點的地理經緯度,兩個點之間的最大圓距離可以用以下公式表示:d = 半徑 * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))
對上式進行處理:d = R * Math.acos(Math.sin(x1) * Math.sin(x2) + Math.cos(x1) * Math.cos(x2) * Math.cos(y1 - y2))
4.1節圖的概括
順時針從上往下:
夏洛特(記作a)(35.2270869, -80.8431267)(上方頂點)
薩凡納(記作b)(32.0835407, -81.0998342)(右)
奧蘭多(記作c)(28.5383355, -81.3792365)(下)
亞特蘭大(記作d)(33.7489954, -84.3879824)(左)
破題
程序
public class Test4_4 {public static void main(String[] args) {// 將四座城市數據賦值給對象double xa = 35.2270869, ya = -80.8431267, xb = 32.0835407, yb = -81.0998342;double xc = 28.5383355, yc = -81.3792365, xd = 33.7489954, yd = -84.3879824;// 設置常量final double R = 6371.01;// 對四座城市數據進行處理(Math.toRadians)double x1 = Math.toRadians(xa), x2 = Math.toRadians(xb), x3 = Math.toRadians(xc), x4 = Math.toRadians(xd);double y1 = Math.toRadians(ya), y2 = Math.toRadians(yb), y3 = Math.toRadians(yc), y4 = Math.toRadians(yd);// 計算各個邊長,以ab bc cd da以及bd記為長度double ab = R * Math.acos(Math.sin(x1) * Math.sin(x2) + Math.cos(x1) * Math.cos(x2) * Math.cos(y1 - y2));double bc = R * Math.acos(Math.sin(x2) * Math.sin(x3) + Math.cos(x2) * Math.cos(x3) * Math.cos(y2 - y3));double cd = R * Math.acos(Math.sin(x3) * Math.sin(x4) + Math.cos(x3) * Math.cos(x4) * Math.cos(y3 - y4));double da = R * Math.acos(Math.sin(x4) * Math.sin(x1) + Math.cos(x4) * Math.cos(x1) * Math.cos(y4 - y1));double bd = R * Math.acos(Math.sin(x2) * Math.sin(x4) + Math.cos(x2) * Math.cos(x4) * Math.cos(y2 - y4));// 先計算上半三角形abd面積,再計算三角形bcd面積double s1 = (ab + da + bd) / 2;double s2 = (bc + cd + bd) / 2;double area1 = Math.pow(s1 * (s1 - ab) * (s1 - da) * (s1 - bd), 0.5);double area2 = Math.pow(s2 * (s2 - bc) * (s2 - cd) * (s2 - bd), 0.5);// 輸出結果System.out.println("四邊形面積為:" + (area1 + area2));} }總結
以上是生活随笔為你收集整理的Java黑皮书课后题第4章:*4.3(几何:估算面积)应用4.1节图中以下地点的GPS位置:Georgia州的Atlanta……计算被这四个城市所围起来的区域面积的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第4章:*4.2(几
- 下一篇: Java黑皮书课后题第4章:*4.5(几