Question

In: Computer Science

find the distance between two latitudes and longitudes while also dealing with unit conversions As pseudocode:...

find the distance between two latitudes and longitudes while also dealing with unit conversions

  1. As pseudocode: showing a single correct solution path, expressed in natural language, ignoring programming syntax, but providing enough detail, hierarchy and order so that a peer can easily understand the steps.
    The pseudocode must include a desk-check, that is to say, it must be traced by hand using ‘real’ numbers, showing the values/calculations of all of the intermediate steps, and then indicating the ‘algorithm-calculated’ final result.

Solutions

Expert Solution

We first derive the relevant formula, then give the algorithmic explanation for said formula and then lastly do a desk-check of the values.

The formula for the haversine of an angle is given as:

.

Now, let the central angle between the radius of the earth and the distance between any two given points be d. Then,

Where: r is the radius of the Earth (6371 km), d is the physical distance between the two points under consideration, is latitude of the two points and is longitude of the two points respectively.

Now, we take h = haversine(d/r). Then:

(we take haversine = hsine for brevity in the derivation below)  

Then,

Which gives us:

Now, algorithmically (we assume that the internal sin() and cos() functions take radians in arguments):

  1. Take lat_a, long_a, lat_b and long_b as inputs - here, lat_a and long_a are the latitude and longitude of a point "a" and lat_b and long_b are the latitude and longitude of another point "b".
  2. Take pi = 3.141257.   
  3. Calculate delta_lat and delta_long as shown:
    1. Calculate delta_lat = (lat_b - lat_a) * pi /180 (in radians)
    2. Calculate delta_long = (long_b - long_a) * pi /180 (in radians)
  4. Convert the input latitudes to radians:
    1. lat_a = (lat_a) * pi / 180
    2. lat_b = (lat_b) * pi / 180
  5. We calculate h = sqrt(sin(delta_lat/2)2 + cos(lat_a) * cos(lat_b) * sin(delta_long/2)2)
  6. We calculate d = 2 * 6371 * sin-1(h).

Desk-check:

  1. Given: London (51.5007° N, 0.1246° W) and New York (40.6892° N, 74.0445° W).
  2. Then, lat_a = 51.5007, long_a = 0.1246, lat_b = 40.6892, long_b = 74.0445.
  3. delta_lat = (40.6892 - 51.5007) * 3.141257 / 180 = -0.1886 radian
  4. delta_long = (74.0445 - 0.1246) * 3.141257 / 180 = 1.29 radian.
  5. lat_a = (51.5007 * 3.141257) / 180 = 0.899 radian
  6. lat_b = (40.6892 * 3.141257) / 180 = 0.71 radian.
  7. Then, h = = 0.4236
  8. Then, d = 2 * 6371 * 0.4236 = 5397.5112 km (approximately)

The actual distance between the points is:

Thus our final result is very close to the actual distance between these two points, with some error induced due to rounding.

(If you liked this answer, feel free to give it a thumbs up. Thank you so much!)


Related Solutions

Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2...
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2 of the same length n. What is the complexity of your algorithm?
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2...
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2 of the same length n. What is the complexity of your algorithm?
The cubit is an ancient unit of length based on the distance between the elbow and...
The cubit is an ancient unit of length based on the distance between the elbow and the tip of the middle finger of the measurer. Assume that the distance ranged from 43 to 53 cm, and suppose that ancient drawings indicate that a cylindrical pillar was to have a length of 5.0 cubits and a diameter of 1.0 cubits. For the stated range, what are the lower values for (a) the cylinder's length in meters, (b) the cylinder's length in...
You are measuring the distance between the 6th and 2nd levels of the hydrogen atom while...
You are measuring the distance between the 6th and 2nd levels of the hydrogen atom while it is passing you at 99.99% of c. ​ A) What will this distance appear to be in the direction perpendicular to the traveling speed. ​ B) What will this distance appear to be in the direction parallel to the traveling speed.​
Measuring the distance between two trees, you measure that there are 75.5 steps between the two...
Measuring the distance between two trees, you measure that there are 75.5 steps between the two trees. Give an estimate of the unit of measurement of one step in meters and give an estimate of what you think its uncertainty is. Give the distance that separates the trees in meters as well as feet/inches and round to the correct amount of significant digits. What would you say are the uncertainties for the these two distances
Find a relationship between the equilibrium temperature of a spherical object and the distance from the...
Find a relationship between the equilibrium temperature of a spherical object and the distance from the sun in terms of the Sun's emission temperature
16.   Is the relationship between frequency of recombination and the distance on a chromosome between two genes...
16.   Is the relationship between frequency of recombination and the distance on a chromosome between two genes always linear? Why? 17.   If a proliferating cell is exposed to UV radiation causing DNA damage, at what checkpoint would the cell cycle be halted? What is the mechanism behind this control? 18.   What do we mean by proofreading activity of a DNA polymerase? 19. What is a tumor suppressor gene? Explain and describe the role of Rb as an example. 20. What is an oncogene?...
Find the distance between the skew lines with the given parametric equations. x = 2 +...
Find the distance between the skew lines with the given parametric equations. x = 2 + t,   y = 3 + 6t,   z = 2t x = 1 + 4s,   y = 5 + 15s,   z = -2 + 6s.
Problem 3 The function distance returns the distance between two strings X and Y. Its running...
Problem 3 The function distance returns the distance between two strings X and Y. Its running time is exponential. Explain why. (Note: make sure you understand what X[0: -1] is.) # # Input: X, Y, which are strings # Output: a number, which is the distance between the two strings # def distance(X, Y): if len(X)==0: return len(Y) if len(Y)==0: return len(X) if X[-1]==Y[-1]: return distance(X[0:-1], Y[0:-1]) else: a = distance(X[0:-1], Y[0:-1]) b = distance(X, Y[0:-1]) c = distance(X[0:-1], Y)...
Two long, parallel wires are separated by a distance of 3.80 cm. The force per unit...
Two long, parallel wires are separated by a distance of 3.80 cm. The force per unit length that each wire exerts on the other is 3.80×10−5 N/m, and the wires repel each other. The current in one wire is 0.600 A. What is the current in the second wire? Express your answer in amperes. Are the two currents in the same direction or in opposite directions?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT