Available: Friday September 16
Due: Monday September 26, noon
This assignment is to be done in TEAMS OF TWO PEOPLE. The assignment should be submitted only once by a member of your team, but please ensure that the identification material contains the information for both team members. Follow the instructions in the lab manual for submitting assignments. It is okay to work with someone from the other lecture section, but please ensure you identify the section for each person of your team.
Your algorithms should be developed using the format used in class, and it is not permitted to use structures such as branches and loops that have not yet been covered in the lectures. Your algorithm traces should use the format shown in class; a separate table is to be used for each call to each algorithm.
Angles can be measured in degrees and minutes of arc. A degree is partitioned into 60 minutes of arc.
When measuring latitude (lat) and longitude (lon) to provide coordinates on the Earth, the co-ordinates can be in the following ranges:
latitude: -90 degrees ≤ lat ≤ +90 degrees
longitude: -180 degrees < lon ≤ +180 degrees
The zero latitude line is the Earth’s equator. Positive latitudes extend north from the equator up to the North Pole, while negative latitudes extend south from the equator to the South Pole. If the latitude is ± 90 (i.e. at one of the poles), the longitude is undefined.
The zero longitude line is defined as passing through the observatory in
For example, according to NASA’s web site, the values for
latitude: +45 degrees, 25 minutes
longitude: -75 degrees, 40 minutes
Angles can also be measured in decimal degrees. For example, an angle of -45.5 degrees is equivalent to an angle of -45 degrees and 30 minutes.
Design an algorithm that will convert an angle specified in degrees and minutes of arc, to an angle measured in decimal degrees. Angles may be any positive or negative value.
GIVENS:
Degrees
(degrees part of angle)
Minutes
(minutes part of angle)
RESULTS:
DecimalDegrees
(angle in decimal degrees)
HEADER:
DecimalDegrees ← DMStoDecimal( Degrees, Minutes )
ASSUMPTIONS:
BODY:
1. DecimalDegrees ← Degrees + Minutes / 60 × Sgn( Degrees)
Design an algorithm that will convert an angle measured in decimal degrees to an angle measured in radians. Note that π radians are equivalent to 180.0 degrees. Angles may be any positive or negative value.
GIVENS:
AngleInDegrees
(angle in decimal degrees)
RESULTS:
AngleInRadians
(angle in radians)
HEADER:
AngleInRadians ← DegreesToRadians( AngleInDegrees )
BODY:
1. AngleInRadians ← 3.1415926535 / 180 × AngleInDegrees
Suppose that one has the longitude and latitude for two locations, and we would like to calculate the distance one would travel between the two points. This is not as straightforward as you might imagine because the distance is not in a straight line. Instead, one would travel along a great circle defined by the curve of the Earth’s surface and passing through the two locations. Therefore, the actual distance to travel is the distance along the segment of such a great circle.
If the coordinates for location 1 are (θ1, φ1) and the coordinates for location 2 are (θ2, φ2), then the distance from location 1 to location 2 is:
r × arccos( sin(θ1)sin(θ2) + cos(θ 1)cos(θ2)cos(φ2−φ1))
where:
Design an algorithm that will calculate the distance between two cities, given the longitude and latitude values measured in degrees and minutes.
Your algorithm should make use of your algorithms in parts 1 and 2.
GIVENS:
Lat1Deg (latitude
of location 1, degrees part)
Lat1Min
(latitude of location 1, minutes part)
Lon1Deg (longitude
of location 1, degrees part)
Lon1Min
(longitude of location 1, minutes part)
Lat2Deg (latitude
of location 2, degrees part)
Lat2Min
(latitude of location 2, minutes part)
Lon2Deg (longitude
of location 2, degrees part)
Lon2Min
(longitude of location 2, minutes part)
RESULTS:
DistanceInKm (distance
between points on Earth's surface, in kilometres)
HEADER:
DistanceInKm ← GreatCircleDistance(
Lat1Deg, Lat1Min, Lon1Deg, Lon1Min, Lat2Deg, Lat2Min, Lon2Deg, Lon2Min )
INTERMEDIATES:
EarthRadius (radius
of the earth, in kilometres)
Lat1DD (latitude
of location 1, in decimal degrees)
Lon1DD
(longitude of location 1, in decimal degrees)
Lat2DD (latitude
of location 2, in decimal degrees)
Lon2 DD
(longitude of location 2, in decimal degrees)
Lat1
(latitude of location 1, in radians)
Lon1
(longitude of location 1, in radians)
Lat2
(latitude of location 2, in radians)
Lon2
(longitude of location 2, in radians)
BODY:
1.
EarthRadius ← 6378.7
2. Lat1DD ← DMStoDecimal( Lat1Deg,
Lat1Min )
3. Lon1DD ← DMStoDecimal(Lon1Deg,
Lat1Min )
4. Lat2DD ← DMStoDecimal( Lat2Deg,
Lat2Min )
5.
Lon2DD ←
DMStoDecimal(Lon2Deg, Lat2Min )
6. Lat1 ← DegreesToRadians( Lat1DD)
7. Lon1 ← DegreesToRadians(Lon1DD)
8. Lat2 ← DegreesToRadians ( Lat2DD)
9. Lon2 ←
DegreesToRadians (Lon2DD)
10.
DistanceInKm ← EarthRadius × arccos( sin(Lat1) × sin(Lat2) +
cos(Lat1) × cos(Lat2) × cos(Lon2- Lon1))
Trace your algorithm for question 3 on the following givens:
Three decimal places are sufficient for real values.
Table 1 |
||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statement |
|
|
Lat1Deg |
Lat1Min |
Lon1Deg |
Lon1Min |
Lat2Deg |
Lat2Min |
Lon2Deg |
Lon2Min |
EarthRadius |
Lat1DD |
Lon1DD |
Lat2DD |
Lon2DD |
Lat1 |
Lon1 |
Lat2 |
Lon2 |
DistanceInKm |
|
initial
values |
|
45 |
25 |
-75 |
40 |
49 |
15 |
-123 |
10 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
1 |
EarthRadius ← 6378.7 |
|
|
|
|
|
|
|
|
|
6378.7 |
|
|
|
|
|
|
|
|
|
2 |
call: Lat1DD ← DMStoDecimal( Lat1Deg, Lat1Min ) |
see Table
2 |
|
|
|
|
|
|
|
|
|
45.417 |
|
|
|
|
|
|
|
|
3 |
call: Lon1DD ← DMStoDecimal(Lon1Deg, Lat1Min ) |
see Table
3 |
|
|
|
|
|
|
|
|
|
|
-75.67 |
|
|
|
|
|
|
|
4 |
call: Lat2DD ← DMStoDecimal( Lat2Deg, Lat2Min ) |
see Table
4 |
|
|
|
|
|
|
|
|
|
|
|
49.25 |
|
|
|
|
|
|
5 |
call: Lon2DD ← DMStoDecimal(Lon2Deg, Lat2Min ) |
see Table
5 |
|
|
|
|
|
|
|
|
|
|
|
|
-123 |
|
|
|
|
|
6 |
call: Lat1 ← DegreesToRadians( Lat1DD) |
see Table
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
0.793 |
|
|
|
|
7 |
call: Lon1 ← DegreesToRadians(Lon1DD) |
see Table
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-1.321 |
|
|
|
8 |
call: Lat2 ← DegreesToRadians ( Lat2DD) |
see Table
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0.860 |
|
|
9 |
call: Lon2 ← DegreesToRadians (Lon2DD) |
see Table
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-2.150 |
|
10 |
DistanceInKm ← EarthRadius × arccos( sin(Lat1) ×
sin(Lat2) + cos(Lat1) × cos(Lat2) × cos(Lon2- Lon1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3549.645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 2 |
|
|
Lat1DD |
|
Lat1Deg |
Lat1Min |
|
|
|
|
|
|
|
|
|
|
||||
statement |
|
Degrees |
Minutes |
DecimalDegrees |
|
|
45.417 |
|
45 |
25 |
|
|
|
|
|
|
|
|
|
|
|
initial
values |
45 |
25 |
? |
|
|
DecimalDegrees |
|
Degrees |
Minutes |
|
|
|
|
|
|
|
|
|
|
1 |
DecimalDegrees ← Degrees + Minutes / 60 × Sgn(
Degrees) |
|
|
45.417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 3 |
|
|
Lon1DD |
|
Lon1Deg |
Lon1Min |
|
|
|
|
|
|
|
|
|
|
||||
statement |
|
Degrees |
Minutes |
DecimalDegrees |
|
|
-75.667 |
|
-75 |
40 |
|
|
|
|
|
|
|
|
|
|
|
initial
values |
-75 |
40 |
? |
|
|
DecimalDegrees |
|
Degrees |
Minutes |
|
|
|
|
|
|
|
|
|
|
1 |
DecimalDegrees ← Degrees + Minutes / 60 × Sgn( Degrees) |
|
|
-75.667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 4 |
|
|
Lat2DD |
|
Lat2Deg |
Lat2Min |
|
|
|
|
|
|
|
|
|
|
||||
statement |
|
Degrees |
Minutes |
DecimalDegrees |
|
|
49.250 |
|
49 |
15 |
|
|
|
|
|
|
|
|
|
|
|
initial
values |
49 |
15 |
? |
|
|
DecimalDegrees |
|
Degrees |
Minutes |
|
|
|
|
|
|
|
|
|
|
1 |
DecimalDegrees ← Degrees + Minutes / 60 × Sgn(
Degrees) |
|
|
49.250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 5 |
|
|
Lon2DD |
|
Lon2Deg |
Lon2Min |
|
|
|
|
|
|
|
|
|
|
||||
statement |
|
Degrees |
Minutes |
DecimalDegrees |
|
|
-123.167 |
|
-123 |
10 |
|
|
|
|
|
|
|
|
|
|
|
initial
values |
-123 |
10 |
|
|
|
DecimalDegrees |
|
Degrees |
Minutes |
|
|
|
|
|
|
|
|
|
|
1 |
DecimalDegrees ← Degrees + Minutes / 60 × Sgn(
Degrees) |
|
|
-123.167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 6 |
|
|
|
Lat1 |
|
Lat1DD |
|
|
|
|
|
|
|
|
|
|
|
|||
statement |
|
AngleInDegrees |
AngleInRadians |
|
|
|
0.793 |
|
45.417 |
|
|
|
|
|
|
|
|
|
|
|
|
initial
values |
45.417 |
? |
|
|
|
AngleInRadians |
|
AngleInDegrees |
|
|
|
|
|
|
|
|
|
|
|
1 |
AngleInRadians ← 3.1415926535 / 180 × AngleInDegrees |
|
0.793 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 7 |
|
|
|
Lon1 |
|
Lon1DD |
|
|
|
|
|
|
|
|
|
|