(Please use the given format. In the previously mentioned assignment, where the
ID: 3829069 • Letter: #
Question
(Please use the given format. In the previously mentioned assignment, where the great circle equation comes from, I needed to convert the 4 inputs into radians using the command ' math.radians(...) '. I first converted all the inputs to radians then did i = math.sin(x1) * math.sin(x2), j = math.cos(x1) * math.cos(x2) * math.cos(y1 - y2), then k = i + j, then d = math.acos(k), then d = math.degrees(d), then d = 111 * d. This was the order of my commands, I hope this helps, thanks in advance)
Problem 1. (Geo Location) Define a data type Location in location. py that represents a location on Earth using its latitude and longitude. The data type must support t e following API method description Location (lat, lon) a new location l from the given latitude and longitude values the great-circle distance between l and m 1.distanceTo (m) the string representation of l as (lat, lon) str (1) See Problem 7 from Project 2 for the great-circle distance formula. python location py 48.87 -2.33 37.8 122.4 (48.87 2.33) loci (37.8 122.4) lo c2 d (locl, loc2) 8701.38954324 d 111 arccos (sin(a1) sin (z2) cos(z1)cos (a2) cos(yi y2)) Great-Circle Distance Formula import math stdio import import sys class Location Represents a location on Earth def init (self, lat, lon Constructs a new location given its latitude and longitude values self lat self lon def distanceTo (self, other Returns the great-circle distance between self and other def str self Returns a string representation of self Test client DO NOT EDIT Reads floats latl, lonl, lat2, lon2 from command representing two locations on Earth constructs two Location objects from them, and writes them along with the great-circle distance between the two def main lat1, lonl lat2, lon2 map (float sys.argv locl Location (latl, lonl loc2 Location (lat2, lon2 stdio. writeln locl str OC1 stdio writeln loc2 str loc2 str distanceTo(loc2)) stdio writeln d loci, loc2 if name main mainExplanation / Answer
import math
import stdio
import sys
class Location:
def __init__(self, lat,lon):
self._lat=lat
self._lon=lon
def distanceTo(self,other):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
self._lon, self._lat, other._lon, other._lan = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
r = 6371 # Radius of earth in kilometers. Use 3956 for miles
return c * r
def __str__(self):
return "(%f,%f)"%(self._lat,self._lon)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.