2012-11-08 110 views

回答

0

我有一個功能用於火腿無線電計算。一個「純粹」的公式對我來說太笨重了。

Function BearingFromCoord(lat_base_deg, long_base_deg, lat_dest_deg, long_dest_deg As Single) As Long 
    Dim rad_deg_factor As Single 
    Dim long_diff As Single 
    Dim frac0 As Single 
    Dim frac1 As Single 
    Dim frac2 As Single 
    Dim lat_base As Single 
    Dim long_base As Single 
    Dim lat_dest As Single 
    Dim long_dest As Single 
    Dim bearing As Single 

    rad_deg_factor = 360/(2 * pi()) 

    long_diff = (long_base_deg - long_dest_deg)/rad_deg_factor 
    lat_base = lat_base_deg/rad_deg_factor 
     lat_dest = lat_dest_deg/rad_deg_factor 
      frac0 = Sin(lat_base) * Sin(lat_dest) _ 
       + Cos(lat_base) * Cos(lat_dest) _ 
       * Cos(long_diff) 
      bearing = rad_deg_factor * Application.WorksheetFunction.Acos((Sin(lat_dest) _ 
         - Sin(lat_base) * frac0) _ 
        /(Cos(lat_base) * Sin(WorksheetFunction.Acos(frac0)))) 
      If Sin(long_diff) < 0 Then 
      BearingFromCoord = bearing 
      Else 
      BearingFromCoord = 360 - bearing 
      End If 
End Function 

Private Function pi() As Single 
    pi = 3.1415926535 
End Function 
相關問題