Question

In: Computer Science

(Great Circle Distance) Write a program great_circle.py that takes four floats x 1 , y 1...

(Great Circle Distance) Write a program great_circle.py that takes four floats x 1 , y 1 , x 2 , and y 2 (latitude and longitude in degrees of two points on Earth) as command-line arguments and writes the great-circle distance (in km) between them, given by the equation

d = 111 arccos(sin(x 1 ) sin(x 2 ) + cos(x 1 ) cos(x 2 ) cos(y 1 − y 2 )).

$python3 great_circle .py 48.87 -2.33 37.8 -122.4

8701.389543238289

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

import sys
from math import *

#checking if extra 4 command line arguments are given (first one is script name)
if len(sys.argv)!=5:
    #printing usage and quitting
   
print("Usage: great_circle.py <x1> <y1> <x2> <y2>")
    exit(0)

#converting each argument to float and converting to radians by multiplying with pi/180
x1=float(sys.argv[1])*(pi/180)
y1=float(sys.argv[2])*(pi/180)
x2=float(sys.argv[3])*(pi/180)
y2=float(sys.argv[4])*(pi/180)

'''
The equation you provided was not fully correct, or not getting correct results, so I googled
and found the correct equation. instead of multiplying with 111, you should multiply with
6371 (radius of earth in km), and each angle provided is in radians
'''

distance=6371*acos(sin(x1)*sin(x2) + cos(x1)*cos(x2)*cos(y1-y2))
#displaying the distance.
print(distance)

#for an input of 48.87 -2.33 37.8 -122.4, the distance is 8716.67001 and not 8701.389543238289
#as you have shown in the example output. If you are having doubts, try some online great distance
#calculator and verify it yourself.

#input and output

> great_circle .py 48.87 -2.33 37.8 -122.4

> 8716.670017712719


Related Solutions

Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
1. Here is a pseudo-code of a program that takes two non-negative numbers X and Y...
1. Here is a pseudo-code of a program that takes two non-negative numbers X and Y as its inputs and outputs a number Z. Write this program in C. What does this program do? Explain how it computes the output Z from its inputs X and Y. Determine the big-Oh of this program in terms of its input sizes.                                                                 f (int x, int y) {      z = 0; k = y; w = x;      while (k != 0) {           if...
In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming...
In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming distance between two strings is the number of positions at which the corresponding symbols are different. The program should output an integer representing this distance. For example a = XXWWZZ b = ZZWWXX answer = 4 More examples: "Phone" and "PHOONE" = 3 "God" and "Dog" = 2 "Dog" and "House" = 4
Parametrize the osculating circle to the parabola y = x2 at x = -1
Parametrize the osculating circle to the parabola y = x2 at x = -1
PYTHON 1. Write a program that takes the first derivative of f(x) = 3x2 + 20x...
PYTHON 1. Write a program that takes the first derivative of f(x) = 3x2 + 20x + 5 and prints the values of this derivative at x= -5; x= +5 and x = +10        2. Write a program that takes the 2nd derivative of x5 and prints its value when x = 10. 3.  Write a program that generates 5 random integers between 1 and 75 inclusive ad prints the 5 integers, one per line.
y'=y-x^2 ; y(1)= -4 Write a MATLAB program that makes two plots of the solution to...
y'=y-x^2 ; y(1)= -4 Write a MATLAB program that makes two plots of the solution to the equation using the following values. Suggest you use nested loops instead of two different loops. Be sure to label your plots. a. x0 = 1.0, step size h = .2, number of steps n = 20. b. x0 = 1.0, step size h = .05, number of steps n = 80.
Write the class Square that takes X,Y and Side as parameters (these are used in the...
Write the class Square that takes X,Y and Side as parameters (these are used in the __init__ method) Write the method draw that will draw the square at location X,Y of size Side from the __init__ parameters using turtle graphics. Instantiate the class. Call the draw method The result of the program's execution will be to draw a square. Good descriptive comments are vital. No comments, no grade. There should be comments after every line, and you need to explain...
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments...
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments w, x, y, and z. Define a boolean variable whose value is true if the four values are either in strictly ascending order (w < x < y < z) or strictly descending order (w > x > y > z), and false otherwise. Then, display the boolean variable value. NOTE 1: Do not use if statements on this program. NOTE 2: Assume that...
Write a MARIE program that implements the following logic. If X < Y Then X =...
Write a MARIE program that implements the following logic. If X < Y Then X = X + Y Else Y = 2X Assume the two numbers are X and Y and are entered by the user. Provide prompts to the user to enter the numbers and provide a meaningful output to the screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT