Advertisement
NullChips

Untitled

Mar 15th, 2022
695
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function FindLat(East, North)
  2.  
  3. 'REQUIRES THE "Marc" AND "InitialLat" FUNCTIONS
  4.  
  5. 'SET CONSTANTS
  6.    a = 6377563.396
  7.     b = 6356256.909
  8.     e0 = 400000
  9.     n0 = -100000
  10.     f0 = 0.9996012717
  11.     PHI0 = 49
  12.     LAM0 = -2
  13.  
  14. 'Convert angle measures to radians
  15.    Pi = 3.14159265358979
  16.     RadPHI0 = PHI0 * (Pi / 180)
  17.     RadLAM0 = LAM0 * (Pi / 180)
  18.  
  19. 'Find af0, bf0, e squared (e2), n and Et
  20.    af0 = a * f0
  21.     bf0 = b * f0
  22.     e2 = ((af0 ^ 2) - (bf0 ^ 2)) / (af0 ^ 2)
  23.     n = (af0 - bf0) / (af0 + bf0)
  24.     Et = East - e0
  25.  
  26. 'Find initial value for latitude (PHI) in radians
  27.    PHId = InitialLat(North, n0, af0, RadPHI0, n, bf0)
  28.    
  29. 'Find nu, rho and eta2 using value for PHId
  30.    nu = af0 / (Sqr(1 - (e2 * ((Sin(PHId)) ^ 2))))
  31.     rho = (nu * (1 - e2)) / (1 - (e2 * (Sin(PHId)) ^ 2))
  32.     eta2 = (nu / rho) - 1
  33.    
  34. 'Find Latitude
  35.    VII = (Tan(PHId)) / (2 * rho * nu)
  36.     VIII = ((Tan(PHId)) / (24 * rho * (nu ^ 3))) * (5 + (3 * ((Tan(PHId)) ^ 2)) + eta2 - (9 * eta2 * ((Tan(PHId)) ^ 2)))
  37.     IX = ((Tan(PHId)) / (720 * rho * (nu ^ 5))) * (61 + (90 * ((Tan(PHId)) ^ 2)) + (45 * ((Tan(PHId)) ^ 4)))
  38.    
  39.     FindLat = (180 / Pi) * (PHId - ((Et ^ 2) * VII) + ((Et ^ 4) * VIII) - ((Et ^ 6) * IX))
  40.  
  41. End Function
  42.  
  43.  
  44. Function FindLong(East, North)
  45.  
  46. 'REQUIRES THE "Marc" AND "InitialLat" FUNCTIONS
  47.  
  48. 'SET CONSTANTS
  49.    a = 6377563.396
  50.     b = 6356256.909
  51.     e0 = 400000
  52.     n0 = -100000
  53.     f0 = 0.9996012717
  54.     PHI0 = 49
  55.     LAM0 = -2
  56.  
  57. 'Convert angle measures to radians
  58.    Pi = 3.14159265358979
  59.     RadPHI0 = PHI0 * (Pi / 180)
  60.     RadLAM0 = LAM0 * (Pi / 180)
  61.  
  62. 'Find af0, bf0, e squared (e2), n and Et
  63.    af0 = a * f0
  64.     bf0 = b * f0
  65.     e2 = ((af0 ^ 2) - (bf0 ^ 2)) / (af0 ^ 2)
  66.     n = (af0 - bf0) / (af0 + bf0)
  67.     Et = East - e0
  68.  
  69. 'Find initial value for latitude (PHI) in radians
  70.    PHId = InitialLat(North, n0, af0, RadPHI0, n, bf0)
  71.    
  72. 'Find nu, rho and eta2 using value for PHId
  73.    nu = af0 / (Sqr(1 - (e2 * ((Sin(PHId)) ^ 2))))
  74.     rho = (nu * (1 - e2)) / (1 - (e2 * (Sin(PHId)) ^ 2))
  75.     eta2 = (nu / rho) - 1
  76.    
  77. 'Find Longitude
  78.    X = ((Cos(PHId)) ^ -1) / nu
  79.     XI = (((Cos(PHId)) ^ -1) / (6 * (nu ^ 3))) * ((nu / rho) + (2 * ((Tan(PHId)) ^ 2)))
  80.     XII = (((Cos(PHId)) ^ -1) / (120 * (nu ^ 5))) * (5 + (28 * ((Tan(PHId)) ^ 2)) + (24 * ((Tan(PHId)) ^ 4)))
  81.     XIIA = (((Cos(PHId)) ^ -1) / (5040 * (nu ^ 7))) * (61 + (662 * ((Tan(PHId)) ^ 2)) + (1320 * ((Tan(PHId)) ^ 4)) + (720 * ((Tan(PHId)) ^ 6)))
  82.  
  83.     FindLong = (180 / Pi) * (RadLAM0 + (Et * X) - ((Et ^ 3) * XI) + ((Et ^ 5) * XII) - ((Et ^ 7) * XIIA))
  84.  
  85. End Function
  86.  
  87. Function InitialLat(North, n0, afo, PHI0, n, bfo)
  88.  
  89. 'REQUIRES THE "Marc" FUNCTION
  90. 'THIS FUNCTION IS CALLED BY THE "E_N_to_Lat" and "E_N_to_Long" FUNCTIONS
  91.  
  92. 'First PHI value (PHI1)
  93.    PHI1 = ((North - n0) / afo) + PHI0
  94.    
  95. 'Find M
  96.    M = Marc(bfo, n, PHI0, PHI1)
  97.    
  98. 'Find new PHI value (PHI2)
  99.    PHI2 = ((North - n0 - M) / afo) + PHI1
  100.    
  101. 'Iterate to get final value for InitialLat
  102.    Do While Abs(North - n0 - M) > 0.00001
  103.         PHI2 = ((North - n0 - M) / afo) + PHI1
  104.         M = Marc(bfo, n, PHI0, PHI2)
  105.         PHI1 = PHI2
  106.     Loop
  107.    
  108.     InitialLat = PHI2
  109.    
  110. End Function
  111.  
  112. Function Marc(bf0, n, PHI0, PHI)
  113. 'Compute meridional arc.
  114.  
  115.     Marc = bf0 * (((1 + n + ((5 / 4) * (n ^ 2)) + ((5 / 4) * (n ^ 3))) * (PHI - PHI0)) _
  116.     - (((3 * n) + (3 * (n ^ 2)) + ((21 / 8) * (n ^ 3))) * (Sin(PHI - PHI0)) * (Cos(PHI + PHI0))) _
  117.     + ((((15 / 8) * (n ^ 2)) + ((15 / 8) * (n ^ 3))) * (Sin(2 * (PHI - PHI0))) * (Cos(2 * (PHI + PHI0)))) _
  118.     - (((35 / 24) * (n ^ 3)) * (Sin(3 * (PHI - PHI0))) * (Cos(3 * (PHI + PHI0)))))
  119.  
  120. End Function
  121.  
Advertisement
RAW Paste Data Copied
Advertisement