Advertisement
Guest User

Untitled

a guest
Jun 20th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. def bilateration(latA, lonA, distA, latB, lonB, distB):
  2.     """
  3.    @param latA: latitude of point 1
  4.    @type latA: C{float}
  5.    @param lonA: longitude of point 1
  6.    @type lonA: C{float}
  7.    @param distA: distance from point1 to the third point in miles
  8.    @type distA: C{int}
  9.    @param latB: latitude of point 1
  10.    @type latB: C{float}
  11.    @param lonB: longitude of point 1
  12.    @type lonB: C{float}
  13.    @param distB: distance from point2 to the third point in miles
  14.    @type distB: C{int}
  15.    """
  16.     #Converting miles to nautical miles
  17.     distA *= 0.868976
  18.     distB *= 0.868976
  19.  
  20.     xA = math.cos(lonA)*math.cos(latA)
  21.     yA = math.sin(lonA)*math.cos(latA)
  22.     zA = math.sin(latA)
  23.  
  24.     xB = math.cos(lonB)*math.cos(latB)
  25.     yB = math.sin(lonB)*math.cos(latB)
  26.     zB = math.sin(latB)
  27.  
  28.     x1 = numpy.array([xA, yA, zA])
  29.     x2 = numpy.array([xB, yB, zB])
  30.  
  31.     #Converting from nautical miles to radians
  32.     r1 = distA*math.pi/(60*180)
  33.     r2 = distB*math.pi/(60*180)
  34.  
  35.     q = numpy.dot(x2, x1)
  36.     a = (math.cos(r1) - math.cos(r2)*q) / (1 - pow(q,2))
  37.     b = (math.cos(r2) - math.cos(r1)*q) / (1 - pow(q,2))
  38.  
  39.     n = numpy.cross(x1,x2)
  40.  
  41.     x0 = (a*x1 + b*x2)
  42.  
  43.     t = math.sqrt((1 - numpy.dot(x0, x0))/numpy.dot(n, n))
  44.  
  45.     coords1 = x0 + t*n
  46.     coords2 = x0 - t*n
  47.  
  48.     x1 = coords1[0]
  49.     y1 = coords1[1]
  50.     z1 = coords1[2]
  51.     x2 = coords2[0]
  52.     y2 = coords2[1]
  53.     z2 = coords2[2]
  54.  
  55.     lon1 = math.atan(x1,y1)
  56.     lat1 = math.atan(math.sqrt[pow(x1,2)+pow(y1,2)], z1)
  57.  
  58.     lon2 = math.atan(x2,y2)
  59.     lat2 = math.atan(math.sqrt[pow(x2,2)+pow(y2,2)], z2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement