Autor Beitrag
MysteryEskimo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN Xp
Visual C# Studio 2005
BeitragVerfasst: Fr 20.11.09 13:46 
p1 = punkt1;
p2 = punkt2;
double m = (p2.Y - p1.Y) / (p2.X - p1.X);

Beispiele:
(p2.Y - p1.Y) /// (p2.X - p1.X) /// m
-22 /// 146 /// 0
51 /// 152 /// 0
112 /// -6 /// -18

Hat jemand eine Idee, wie so etwas zustande kommt?
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Fr 20.11.09 16:50 
Hallo,

leider verschweigst du uns den Typ von p1 und p2. Wegen der Formulierung "Punkt" vermute ich, dass es sich jeweils um einen Point handelt; dessen X- und Y-Elemente sind als int deklariert. Also wird mit '/' eine Integer-Division ausgeführt; und das bedeutet: Das Ergebnis ist der ganzzahlige Anteil der Division - also bei (-22) / 146 wird es -0. Erst danach kommt bei deinem Verfahren die Konvertierung in double.

Wenn du es anders haben willst, musst du einen der Operanden vorher zu double konvertieren. Beispiel:
ausblenden C#-Quelltext
1:
double m = (double)(p2.Y - p1.Y) / (p2.X - p1.X);					

Gruß Jürgen

PS. Bitte vergiss nicht, Code als solchen zu markieren!