Autor Beitrag
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: So 02.04.06 09:56 
So, hallo

Ich habe einen Anfangs- und Endpunkt (jeweils TPoint). Nun möchte ich die Länge (in Pixeln) bestimmen die zwischen den Punkten liegt. Sowaeit bin ich jetzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function GetLineLength(Startpunkt: TPoint; EndPunkt: TPoint): extended;
var
PSchnitt: TPoint;
KatX, KatY: integer;
begin
PSchnitt.X := EndPunkt.X;          //PSchnitt rausschmeißen!!!!
PSchnitt.Y := StartPunkt.Y;
KatX := PSchnitt.Y - EndPunkt.Y;
KatY := PSchnitt.X - EndPunkt.X;
//Satz vom Pythagoras
result := sqr(Power(KatX, 2) + Power(KatY, 2));
end;
Gleich vorweg: Ich weiß dass die Funktion kürzer sein könnte mach ich auch noch, aber zu Fehlerbehebung will ich noch nicht dran rumschrauben. Ich weiß auch dass die Funktion an gerdane linien scheitern wird - behebe ich alles noch.
Aber auch bei Koordinaten bei denen es gehen sollte kommen 5-stellige werte raus?! Wo liegt da der Fehler?


mfg
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: So 02.04.06 10:13 
Probier mal statt

ausblenden Delphi-Quelltext
1:
result := sqr(Power(KatX, 2) + Power(KatY, 2));					


das hier:

ausblenden Delphi-Quelltext
1:
result := sqrt(sqr(KatX) + sqr(KatY));					


:D


MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 02.04.06 10:28 
Nimm doch einfach

ausblenden Delphi-Quelltext
1:
2:
3:
dx := Startpunkt.x - EndPunkt.x; 
dy := Startpunkt.y - EndPunkt.y;
result := sqrt(Power(dx, 2) + Power(dy, 2));
Dann versteht das auch sofort jeder, der den Pythagoras kennt...

Dein Fehler liegt übrigens hier:
ausblenden Delphi-Quelltext
1:
result := sqrt(Power(KatX, 2) + Power(KatY, 2));					

sqr ist Quadrat (square), sqrt ist Quadratwurzel (squareroot) ;-)

_________________
We are, we were and will not be.
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: So 02.04.06 14:02 
Oha, THX! Ja das PSchnitt hätte ich noch rausgeworfen, aber das mit dem t is schon *** ;-) :mrgreen: