BlaueLed
05.08.2014, 06:55
Hallo zusammen,
mit nachfolgendem Code berechne ich die Distanz zwischen 2 Koordinaten. Das funktioniert auch gut, sobald die Distanz unter 1000m liegt. Wenn die Distanz über 1000m liegt bekomme ich kein vernünftiges Ergebnis wie z.B. 1.299939393e3.
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 9600
$swstack = 64
$hwstack = 64
$framesize = 32
$sim
Declare Sub Calc_all
Declare Sub Calc_radiants
Declare Sub Calc_angles
Declare Sub Calc_distance
Dim Lon_a As Double 'longitude base (deg)
Dim Lat_a As Double 'latitude base (deg)
Dim Lon_b As Double 'longitude air (deg)
Dim Lat_b As Double 'latitude air (deg)
Dim Lon_a_rad As Double 'longitude base (radiant)
Dim Lat_a_rad As Double 'latitude base (radiant)
Dim Lon_b_rad As Double 'longitude air (radiant)
Dim Lat_b_rad As Double 'latitude air (radiant)
Dim Angle_azi As Double 'Angle azimuth
Dim Angle_ele As Double 'Angle elevation
Dim Distance As Double 'tmp distance
Dim Distance_m_2d As Double 'Distance 2D in meters
Dim Distance_m_3d As Double 'Distance 3D in meters
Dim Altitude As Double 'Altitude over ground
Const Earthradiuskm = 6378.137 'Const for earth radius
Dim Tmp_double(4) As Double 'tmp variable
'### Main Loop ####
Main:
Lat_a = 49.394882
Lon_a = 8.389916
Lat_b = 49.394938
Lon_b = 8.401187
Altitude = 200
Call Calc_all
Print "Distanz: " ; Distance_m_2d ; "m" ; " in 3D: " ; Distance_m_3d ; " Grad Azi: " ; Angle_azi ; " Grad Ele: " ; Angle_ele
Goto Main
'#### Subs ###
Sub Calc_radiants 'convert degree to radiant
Lon_a_rad = Deg2rad(lon_a)
Lat_a_rad = Deg2rad(lat_a)
Lon_b_rad = Deg2rad(lon_b)
Lat_b_rad = Deg2rad(lat_b)
End Sub
Sub Calc_distance 'calculate distances 2D and 3D
'calc distance 2D
Tmp_double(4) = Sin(lat_a_rad)
Tmp_double(3) = Sin(lat_b_rad)
Tmp_double(1) = Tmp_double(4) * Tmp_double(3)
Tmp_double(4) = Cos(lat_a_rad)
Tmp_double(3) = Cos(lat_b_rad)
Tmp_double(2) = Lon_b_rad - Lon_a_rad
Tmp_double(2) = Cos(tmp_double(2))
Tmp_double(4) = Tmp_double(4) * Tmp_double(3)
Tmp_double(4) = Tmp_double(4) * Tmp_double(2)
Tmp_double(1) = Tmp_double(1) + Tmp_double(4)
Distance = Acos(tmp_double(1))
Tmp_double(1) = Distance * Earthradiuskm
Distance_m_2d = Tmp_double(1) * 1000
'calc distance 3D
Tmp_double(4) = Distance_m_2d * Distance_m_2d
Tmp_double(3) = Altitude * Altitude
Tmp_double(1) = Tmp_double(3) + Tmp_double(4)
Distance_m_3d = Sqr(tmp_double(1))
End Sub
Sub Calc_angles 'calculate angles
'Azimuth angle
Tmp_double(1) = Sin(lat_b_rad)
Tmp_double(2) = Sin(lat_a_rad)
Tmp_double(3) = Cos(distance)
Tmp_double(2) = Tmp_double(2) * Tmp_double(3)
Tmp_double(1) = Tmp_double(1) - Tmp_double(2)
Tmp_double(2) = Cos(lat_a_rad)
Tmp_double(3) = Sin(distance)
Tmp_double(2) = Tmp_double(2) * Tmp_double(3)
Tmp_double(1) = Tmp_double(1) / Tmp_double(2)
Tmp_double(1) = Acos(tmp_double(1))
Angle_azi = Rad2deg(tmp_double(1))
If Lon_a > Lon_b Then
Angle_azi = 360.0 - Angle_azi
End If
'Elevation angle
Tmp_double(1) = Altitude / Distance_m_2d
Tmp_double(1) = Atn(tmp_double(1))
Angle_ele = Rad2deg(tmp_double(1))
End Sub
Sub Calc_all 'Do all calculations, set lat and lon's before..
Call Calc_radiants
Call Calc_distance
Call Calc_angles
End Sub
End
Die Frage ist jetzt warum ? Liegt das an einer Variablendeklaration ?
Gruß Kay
mit nachfolgendem Code berechne ich die Distanz zwischen 2 Koordinaten. Das funktioniert auch gut, sobald die Distanz unter 1000m liegt. Wenn die Distanz über 1000m liegt bekomme ich kein vernünftiges Ergebnis wie z.B. 1.299939393e3.
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 9600
$swstack = 64
$hwstack = 64
$framesize = 32
$sim
Declare Sub Calc_all
Declare Sub Calc_radiants
Declare Sub Calc_angles
Declare Sub Calc_distance
Dim Lon_a As Double 'longitude base (deg)
Dim Lat_a As Double 'latitude base (deg)
Dim Lon_b As Double 'longitude air (deg)
Dim Lat_b As Double 'latitude air (deg)
Dim Lon_a_rad As Double 'longitude base (radiant)
Dim Lat_a_rad As Double 'latitude base (radiant)
Dim Lon_b_rad As Double 'longitude air (radiant)
Dim Lat_b_rad As Double 'latitude air (radiant)
Dim Angle_azi As Double 'Angle azimuth
Dim Angle_ele As Double 'Angle elevation
Dim Distance As Double 'tmp distance
Dim Distance_m_2d As Double 'Distance 2D in meters
Dim Distance_m_3d As Double 'Distance 3D in meters
Dim Altitude As Double 'Altitude over ground
Const Earthradiuskm = 6378.137 'Const for earth radius
Dim Tmp_double(4) As Double 'tmp variable
'### Main Loop ####
Main:
Lat_a = 49.394882
Lon_a = 8.389916
Lat_b = 49.394938
Lon_b = 8.401187
Altitude = 200
Call Calc_all
Print "Distanz: " ; Distance_m_2d ; "m" ; " in 3D: " ; Distance_m_3d ; " Grad Azi: " ; Angle_azi ; " Grad Ele: " ; Angle_ele
Goto Main
'#### Subs ###
Sub Calc_radiants 'convert degree to radiant
Lon_a_rad = Deg2rad(lon_a)
Lat_a_rad = Deg2rad(lat_a)
Lon_b_rad = Deg2rad(lon_b)
Lat_b_rad = Deg2rad(lat_b)
End Sub
Sub Calc_distance 'calculate distances 2D and 3D
'calc distance 2D
Tmp_double(4) = Sin(lat_a_rad)
Tmp_double(3) = Sin(lat_b_rad)
Tmp_double(1) = Tmp_double(4) * Tmp_double(3)
Tmp_double(4) = Cos(lat_a_rad)
Tmp_double(3) = Cos(lat_b_rad)
Tmp_double(2) = Lon_b_rad - Lon_a_rad
Tmp_double(2) = Cos(tmp_double(2))
Tmp_double(4) = Tmp_double(4) * Tmp_double(3)
Tmp_double(4) = Tmp_double(4) * Tmp_double(2)
Tmp_double(1) = Tmp_double(1) + Tmp_double(4)
Distance = Acos(tmp_double(1))
Tmp_double(1) = Distance * Earthradiuskm
Distance_m_2d = Tmp_double(1) * 1000
'calc distance 3D
Tmp_double(4) = Distance_m_2d * Distance_m_2d
Tmp_double(3) = Altitude * Altitude
Tmp_double(1) = Tmp_double(3) + Tmp_double(4)
Distance_m_3d = Sqr(tmp_double(1))
End Sub
Sub Calc_angles 'calculate angles
'Azimuth angle
Tmp_double(1) = Sin(lat_b_rad)
Tmp_double(2) = Sin(lat_a_rad)
Tmp_double(3) = Cos(distance)
Tmp_double(2) = Tmp_double(2) * Tmp_double(3)
Tmp_double(1) = Tmp_double(1) - Tmp_double(2)
Tmp_double(2) = Cos(lat_a_rad)
Tmp_double(3) = Sin(distance)
Tmp_double(2) = Tmp_double(2) * Tmp_double(3)
Tmp_double(1) = Tmp_double(1) / Tmp_double(2)
Tmp_double(1) = Acos(tmp_double(1))
Angle_azi = Rad2deg(tmp_double(1))
If Lon_a > Lon_b Then
Angle_azi = 360.0 - Angle_azi
End If
'Elevation angle
Tmp_double(1) = Altitude / Distance_m_2d
Tmp_double(1) = Atn(tmp_double(1))
Angle_ele = Rad2deg(tmp_double(1))
End Sub
Sub Calc_all 'Do all calculations, set lat and lon's before..
Call Calc_radiants
Call Calc_distance
Call Calc_angles
End Sub
End
Die Frage ist jetzt warum ? Liegt das an einer Variablendeklaration ?
Gruß Kay