|
6 | 6 | distance between two cities. Divide the polygon into two triangles and use the |
7 | 7 | formula in Programming Exercise 2.19 to compute the area of a triangle.) |
8 | 8 | */ |
| 9 | +/* |
| 10 | + * To change this license header, choose License Headers in Project Properties. |
| 11 | + * To change this template file, choose Tools | Templates |
| 12 | + * and open the template in the editor. |
| 13 | + */ |
| 14 | +packageChapter_04; |
| 15 | +importjava.util.Scanner; |
| 16 | +/** |
| 17 | + * |
| 18 | + * @author ManuelJose |
| 19 | + */ |
| 20 | +publicclassEx04_03 { |
| 21 | +//Geography: estimate areas |
| 22 | +publicstaticvoidmain(String[]args) { |
| 23 | +//Atlanta: 40.41044,-99.40505000000002 |
| 24 | +//Orlando: 28.5383355,-81.37923649999999 |
| 25 | +//Savannah: 32.0835407,-81.09983419999998 |
| 26 | +//Charlotte: 35.2270869,-80.84312669999997 |
| 27 | +doublex0 =40.41044; |
| 28 | +doubley0 = -99.40505000000002; |
| 29 | +doublex1 =28.5383355; |
| 30 | +doubley1 = -81.37923649999999; |
| 31 | +doublex2 =32.0835407; |
| 32 | +doubley2 = -81.09983419999998; |
| 33 | +doublex3 =35.2270869; |
| 34 | +doubley3 = -80.84312669999997; |
| 35 | + |
| 36 | +doubled1 =6371.01 *Math.acos(Math.sin(x0)*Math.sin(x1)+Math.cos(x0)*Math.cos(x1)*Math.cos(y0-y1)); |
| 37 | +doubled2 =6371.01 *Math.acos(Math.sin(x1)*Math.sin(x2)+Math.cos(x1)*Math.cos(x2)*Math.cos(y1-y2)); |
| 38 | +doubled3 =6371.01 *Math.acos(Math.sin(x0)*Math.sin(x2)+Math.cos(x0)*Math.cos(x2)*Math.cos(y0-y2)); |
| 39 | +doubled4 =6371.01 *Math.acos(Math.sin(x2)*Math.sin(x3)+Math.cos(x2)*Math.cos(x3)*Math.cos(y2-y3)); |
| 40 | +doubled5 =6371.01 *Math.acos(Math.sin(x3)*Math.sin(x0)+Math.cos(x3)*Math.cos(x0)*Math.cos(y3-y0)); |
| 41 | + |
| 42 | +doubles1 = (d1 +d2 +d3) /2; |
| 43 | +doublearea1 =Math.sqrt(s1 * (s1-d1)*(s1-d2)*(s1-d3)); |
| 44 | + |
| 45 | +doubles2 = (d3 +d4 +d5) /2; |
| 46 | +doublearea2 =Math.sqrt(s2 * (s2-d5)*(s2-d4)*(s2-d3)); |
| 47 | +System.out.printf("Area total: %.2f km^2\n",area1+area2); |
| 48 | + |
| 49 | + } |
| 50 | +} |