Autor Beitrag
DelphiMarkus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Mo 29.12.08 23:00 
Hallo!

Ich habe ein Problem. Ich wollte eine Anwendung für OpenStreetMap erstellen, die mir die Bildkacheln zu den angegebenen Koordinaten herunterläd. Es gibt den Code für Python, Perl, C/C++, Java usw. hier: wiki.openstreetmap.o...Slippy_map_tilenames (englisch).

Das ist ja auch alles sehr gut und war mir auch hilfreich, aber leider sind die Funktionen nicht gleich.
Zu log(1) sagt mein Taschenrechner (und bestimmt auch Delphi): 0,017455065 und Python: 1.5574077246549023. Dieses Problem habe ich aber dank Wikipedia und Python.org gelöst der Delphi-Code dafür sieht so aus: LogN(1, 2.7182818284590452) (bei uses muss math eingetragen werden).
Aber ein ähnliches Problem habe ich mit den Funtionen cos und tan. Der Taschenrechner gibt ein anderes Ergebniss aus als der Pythoninterpreter. :autsch: Und ich denke, dass Delphi wie der Taschenrechner und nicht wie Python rechnet.

Ich weiß überhaupt nicht weiter. :cry:
Bitte helft mir! :flehan:

Danke,
Maxi

//Edit:
Da sieht man mal wie verzweifelt ich bin... Das Thema hätte nach "Algorithmen, Optimierung und Assembler" vielleicht besser gepasst.


Zuletzt bearbeitet von DelphiMarkus am Mo 29.12.08 23:06, insgesamt 1-mal bearbeitet
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mo 29.12.08 23:05 
Du musst darauf achten ob die Winkelfunktionen den Winkel in Grad oder in Rad haben wollen. Entsprechende Umrechnungsfunktionen heißen bei Delphi DegToRad und RadToDeg.
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Mo 29.12.08 23:11 
Danke, dann hätte ich schonmal eine Stelle im Programm die ich ändern muss.

Hier übrigends der Python-Code:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
import math
def deg2num(lat_deg, lon_deg, zoom):
  lat_rad = lat_deg * math.pi / 180.0  <-- Hier ist ja die Umwandlung DegToRad
  n = 2.0 ** zoom
  xtile = int((lon_deg + 180.0) / 360.0 * n)
  ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
  return(xtile, ytile)


Aber das erwünsche Ergebniss habe ich dann immer noch nicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button9Click(Sender: TObject);
var
  lat_rad, lat_deg, lon_deg, zoomx, n: Real;
  xtile, ytile: String;
begin
  lat_deg := StrToFloat(Edit1.Text);
  lon_deg := StrToFloat(Edit2.Text);
  zoomx := StrToFloat(Edit3.Text);
  lat_rad := DegToRad(lat_deg);
  n :=   2.0 *  zoomx;
  xtile := FloatToStrF((lon_deg + 180.0) / 360.0 * n, ffNumber, 10, 0);
  ytile := FloatToStrF((1.0 - LogN(Tan(lat_rad) + (1 / Cos(lat_rad)), 2.7182818284590452) / Pi) / 2.0 * n, ffNumber, 10, 0);
  Label4.Caption := xtile;
  Label5.Caption := ytile;
end;

Das ist mein Code. Die Anwendung sollte eigentlich nur so zum Spass werden, naja...
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mo 29.12.08 23:24 
user profile iconDelphiMarkus hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Quelltext
1:
  n = 2.0 ** zoom					
Das ist eine Potenz, keine Multiplikation.

_________________
>λ=
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Mo 29.12.08 23:32 
Hm... Das stimmt, wenn es das ist, fresse ich doch glatt meinen Hut auf.
Leider ist mein Rechner gerade aus und auf dem eee hab ich kein Delphi. Ich probiere es morgen aus, aber ich bin doch wirklich sehr zuversichtich, dass es das ist. Die Werte sind immer zu klein : 12 und 8 bei Zoom 12 und: 51.84 und 7.1 oder so... Ich weiß die Koordinaten nicht mehr genau.

Aber Python ich auf de eee und den Code kann ich ja in Python auch hier umschreiben um zu sehen, ob die gleichen Ergebnisse wie bei Delphi rauskommen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 29.12.08 23:35 
user profile iconDelphiMarkus hat folgendes geschrieben Zum zitierten Posting springen:
Hm... Das stimmt, wenn es das ist, fresse ich doch glatt meinen Hut auf.
:shock: Guten Appetit! :D

Solche Versprechen würde ich nicht machen. :P
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Mo 29.12.08 23:41 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconDelphiMarkus hat folgendes geschrieben Zum zitierten Posting springen:
Hm... Das stimmt, wenn es das ist, fresse ich doch glatt meinen Hut auf.
:shock: Guten Appetit! :D

Solche Versprechen würde ich nicht machen. :P

Wer hat denn gesagt, dass ich überhaupt einen Hut habe? :P

Oha!
Daran liegt es wirklich, danke Kha!
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Di 30.12.08 23:16 
Hallo!

Ich habe es noch immer nicht hinbekommen. Der Tipp von user profile iconKha war allerdings Gold wert.

Hier mein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button9Click(Sender: TObject);
var
  lat_rad, lat_deg, lon_deg, n: Double;
  xtile, ytile, zoomx: Integer;
begin
  lat_deg := StrToFloat(Edit1.Text);
  lon_deg := StrToFloat(Edit2.Text);
  zoomx := StrToInt(Edit3.Text);
  lat_rad := DegToRad(lat_deg);
  n :=  Power(2, zoomx);
  xtile := Trunc((lon_deg + 180.0) / 360.0 * n);
  ytile := Trunc((1.0 - LogN(Tan(lat_rad) + (1 /Cos(lat_rad)), 2.7182818284590452) / Pi) / 2.0 * n);
  Label4.Caption := IntToStr(xtile);
  Label5.Caption := IntToStr(ytile);
  xAchse := xtile;
  yAchse := ytile;
  Zoom := zoomx;
  Button1.Click;
end;


Ich habe nun herausgefunden, dass cos() und tan() in Delphi und Python das gleiche Ergebnis liefern. Aber log() (in Delphi dann LogN(), Log10() oder Log2()) nicht. Ich habe keine Idee mehr. log() in Python berechnet in meinen Beispielen anders als Log*() in Delphi.

Ich weiß wieder nicht weiter. Ich bitte nochmals um Hilfe.
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: Di 30.12.08 23:24 
OK, es hat sich erledigt. user profile iconSmileySN hat mir geholfen.
So muss der Code aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button9Click(Sender: TObject);
var
  lat_rad, lat_deg, lon_deg, n: Double;
  xtile, ytile, zoomx: Integer;
begin
  lat_deg := StrToFloat(Edit1.Text);
  lon_deg := StrToFloat(Edit2.Text);
  zoomx := StrToInt(Edit3.Text);
  lat_rad := DegToRad(lat_deg);
  n :=  Power(2, zoomx);
  xtile := Trunc((lon_deg + 180.0) / 360.0 * n);
  ytile := Trunc((1.0 - Ln(Tan(lat_rad) + (1 /Cos(lat_rad))) / Pi) / 2.0 * n);
  Label4.Caption := IntToStr(xtile);
  Label5.Caption := IntToStr(ytile);
  xAchse := xtile;
  yAchse := ytile;
  Zoom := zoomx;
  Button1.Click;
end;


ln() statt logN() oder so...