Java Reference
In-Depth Information
*4.2
( Geometry: great circle distance ) The great circle distance is the distance between
two points on the surface of a sphere. Let ( x 1, y 1) and ( x 2, y 2) be the geographi-
cal latitude and longitude of two points. The great circle distance between the two
points can be computed using the following formula:
VideoNote
Compute great circle distance
d
=
radius
*
arccos(sin( x 1 )
*
sin( x 2 )
+
cos( x 1 )
*
cos( x 2 )
*
cos( y 1
-
y 2 ))
Write a program that prompts the user to enter the latitude and longitude of two
points on the earth in degrees and displays its great circle distance. The average
earth radius is 6,371.01 km. Note that you need to convert the degrees into radians
using the Math.toRadians method since the Java trigonometric methods use
radians. The latitude and longitude degrees in the formula are for north and west.
Use negative to indicate south and east degrees. Here is a sample run:
Enter point 1 (latitude and longitude) in degrees: 39.55, -116.25
Enter point 2 (latitude and longitude) in degrees: 41.5, 87.37
The distance between the two points is 10691.79183231593 km
*4.3
( Geography: estimate areas ) Find the GPS locations for Atlanta, Georgia;
Orlando, Florida; Savannah, Georgia; and Charlotte, North Carolina from
www.gps-data-team.com/map/ and 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.)
4.4
( Geometry: area of a hexagon ) The area of a hexagon can be computed using the
following formula ( s is the length of a side):
s 2
6
*
Area
=
6
4
*
tan
¢
Write a program that prompts the user to enter the side of a hexagon and displays
its area. Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.59
*4.5
( Geometry: area of a regular polygon ) A regular polygon is an n -sided polygon in
which all sides are of the same length and all angles have the same degree (i.e., the
polygon is both equilateral and equiangular). The formula for computing the area
of a regular polygon is
s 2
*
n
=
Area
n
4
*
tan
¢
 
Search WWH ::




Custom Search