ITI 1220 Fall 2005 - Assignment 2

Available: Friday September 16
Due: Monday September 26, noon

Instructions

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.

Marking Scheme (total 100 marks)

  • Regulations and Standards: 10 marks
  • Question 1: 15 marks
  • Question 2: 15 marks
  • Question 3: 30 marks
  • Question 4: 30 marks

Background Information

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 Greenwich, England, which is just east of London. Positive longitudes are east of Greenwich around to the 180 degree line near the middle of the Pacific Ocean. Negative longitudes are west from Greenwich.

For example, according to NASA’s web site, the values for Ottawa are:

latitude: +45 degrees, 25 minutes

longitude: -75 degrees, 40 minutes

Question 1 (15 marks)

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:

  • Minutes is greater than or equal to 0
  • If Degrees is zero, so is Minutes.

BODY:

1.   DecimalDegrees ← Degrees + Minutes / 60 × Sgn( Degrees) 

Question 2 (15 marks)

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

Question 3 (30 marks)

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:

  • r is the radius of the earth, in the units for which you wish to calculate the distance. Measured in kilometres, r = 6378.7
  • θ is the latitude measured in radians
  • φ is the longitude measured in radians

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))

Question 4 (30 marks)

Trace your algorithm for question 3 on the following givens:

Ottawa:  latitude = +45 degrees, 25 minutes, longitude = -75 degrees, 40 minutes

Vancouver:  latitude = +49 degrees, 15 minutes; longitude = -123 degrees, 10 minutes

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

 

 

 

 

 

 

 

 

 

 

 

statement

 

AngleInDegrees

AngleInRadians

 

 

 

-1.321

 

-75.667

 

 

 

 

 

 

 

 

 

 

 

 

initial values

-75.667

?

 

 

 

AngleInRadians

 

AngleInDegrees

 

 

 

 

 

 

 

 

 

 

 

1

AngleInRadians ← 3.1415926535 / 180 × AngleInDegrees

 

-1.321

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table 8

 

 

 

Lat2

 

Lat2DD

 

 

 

 

 

 

 

 

 

 

 

statement

 

AngleInDegrees

AngleInRadians

 

 

 

0.860

 

49.250

 

 

 

 

 

 

 

 

 

 

 

 

initial values

49.250

?

 

 

 

AngleInRadians

 

AngleInDegrees

 

 

 

 

 

 

 

 

 

 

 

1

AngleInRadians ← 3.1415926535 / 180 × AngleInDegrees

 

0.860

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table 9

 

 

 

Lon2

 

Lon2DD

 

 

 

 

 

 

 

 

 

 

 

statement

 

AngleInDegrees

AngleInRadians

 

 

 

-2.150

 

-123.167

 

 

 

 

 

 

 

 

 

 

 

 

initial values

-123.167

?

 

 

 

AngleInRadians

 

AngleInDegrees

 

 

 

 

 

 

 

 

 

 

 

1

AngleInRadians ← 3.1415926535 / 180 × AngleInDegrees

 

-2.150