Autor Beitrag
goose
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 93



BeitragVerfasst: Di 14.02.06 10:39 
Hallo,

ich muss den Kurs von a nach b berechnen.
Als Werte dafür hab ich die Koordinaten ( lat/lon ) der beiden Punkte.

Für die Berechnung gibts hier :

ne tolle Formel :
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
// Berechnet den Kurs von Dep zu Arr
function GetKurs(Lat1, Lon1, Lat2, Lon2: Real): Real;
var
  tc1    : real;
  t1, t2 : real;
  d      : real;
begin
  d:=arccos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));

  lat1 := ABS(lat1 * pi/180);
  lon1 := ABS(lon1 * pi/180);
  lat2 := ABS(lat2 * pi/180);
  lon2 := ABS(lon2 * pi/180);

  Debug(' Lat1: '+FloatToStr(lat1) );
  Debug(' Lon1: '+FloatToStr(lon1) );
  Debug(' Lat2: '+FloatToStr(lat2) );
  Debug(' Lon2: '+FloatToStr(lon2) );

  Debug('Minus : '+FloatToStr(lon2-lon1) );
  Debug('Sinus : '+FloatToStr(sin(lon2-lon1)) );
  Debug('cos(d): '+FloatToStr( cos(d) ) );

  If sin(lon2-lon1) < 0 then
  begin
    tc1 := (arccos((sin(lat2)-sin(lat1)*cos(d))))/(((sin(d)*cos(lat1))));
  end else
  begin
   tc1 := 2*pi-(arccos((sin(lat2)-sin(lat1)*cos(d))))/(((sin(d)*cos(lat1))));
  end;

  result :=(180/pi)*tc1;
end;


Das Problem ist nur das das manchmal schief geht da der ARCCOS ja nur werte zwischen -1 und 1 berechnen kann.
Wenn der Wert also ausserhalb lkiegt kommt ne fette Fehlermeldung.
Leider weiss ich nicht was ich hier falsch mache ?

Hier ist mal ein Beispiel wo es nicht funktioniert :

Von : ORTAG
LAT : 51.486667
LON : 11.079722

Nach : IQQ
LAT : -20.374772
LON : -70.1725

Vielleicht habt Ihr nen Plan warum das nicht geht ?

Matthias
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 14.02.06 13:48 
Hallo,

ich fand bei :
www.delphi-forum.de/...92fb6364e2ae0321e329 etwas anderes.
Du berechnest Dein d zu frueh, schon vor der Umwandlung DegtoRad (*pi/180) zudem ist da etwas vertauscht, falls der obengenannte Beitrag stimmt .
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
//mit Freepascal getestet
program lat;
{$Apptype Console}
uses
  sysutils,math;

procedure debug(strText:string);
begin
writeln(strText)
end;

function GetKurs(Lat1, Lon1, Lat2, Lon2: Real): Real;
var
  tc1    : real;
  t1, t2 : real;
  d      : real;
begin
  lat1 := ABS(lat1 * pi/180);
  lon1 := ABS(lon1 * pi/180);
  lat2 := ABS(lat2 * pi/180);
  lon2 := ABS(lon2 * pi/180);
  //vertauscht??...........................................v....v
  d:=arccos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1));
  tc1 :=  arccos( (sin(lat2)-sin(lat1)*cos(d)) / (sin(d)*cos(lat1)) );
  If sin(lon2-lon1) >0 then
   tc1 := 2*pi-tc1;

  Debug(' Lat1: '+FloatToStr(lat1) );
  Debug(' Lon1: '+FloatToStr(lon1) );
  Debug(' Lat2: '+FloatToStr(lat2) );
  Debug(' Lon2: '+FloatToStr(lon2) );
  Debug('Minus : '+FloatToStr(lon2-lon1) );
  Debug('Sinus : '+FloatToStr(sin(lon2-lon1)) );
  Debug('cos(d): '+FloatToStr( cos(d) ) );
  Debug('tc1  : '+FloatToStr( tc1 ) );

  result :=(180/pi)*tc1;
end;

begin
  writeln(GetKurs(51.48667,11.079722,-20.374772,-70.1725));
end.

ergibt
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 Lat1: 0,898611912387789
 Lon1: 0,193377629105651
 Lat2: 0,35560685574315
 Lon2: 1,224741169355721
Minus : 1,03136354025007
Sinus : 0,858000168224664
cos(d): 0,572258522087556
tc1  : 1.767121418240463
 2.587514008476491E+002



Gruss Horst
goose Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 93



BeitragVerfasst: Di 14.02.06 21:53 
Hallöchen,

also das mit dem Kurs berechnen funktioniert jetzt einwandfrei !! Danke Dir !
Hatte da wirklich was vertauscht.

Allerdings stimmt da irgendwas mit der berechnung der entfernung ( d ) nicht wirklich ??

Wenn ich folgende Koordinaten nehme :

Von : ORTAG
LAT : 51.486667
LON : 11.079722

nach : TIVIL
LAT : 35.017386
LON : -82.343558

Kommt bei der rechnung als d ( Entfernung ) irgendwas bei 3000 NM raus.
Stimmt aber nicht. Laut Flugplaner ( der geht :-) ) kommt da was bei 6000 NM raus.

Was ist denn da noch verkehrt ?
Ich seh nur noch Zahlen :-)

Ich hab d so in NM umgerechnet :
FloatToStr( d * 180 * 60/pi )

Das müssten doch NM sein oder ?

Matthias
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Mi 15.02.06 15:53 
Hallo,

ohne in die Details zu gucken, würde ich mal sagen, daß bei einem Faktor von ca. 1 zu 2 irgendwo Radius mit Durchmesser verwechselt wurde.

Aus den Koordinaten kann man sehen, daß da etwas mehr als ein Viertelkreis als Distanz herauskommt - die 6000 NM sind sicher ok.

Viel Spaß beim Fehlersuchen... :D
Horst