Autor Beitrag
Chiyoko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 298
Erhaltene Danke: 8

Win 98, Win Xp, Win 10
C# / C (VS 2019)
BeitragVerfasst: Fr 11.06.10 01:44 
Huhu,

ich versuche, wie der Titel schon sagt, die zurueckgelegte Strecke der Maus zu errechnen.

Das mache ich folgendermasen:

ausblenden C#-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:
Die Variablen
/// <summary>
        /// Cursor
        /// </summary>
        private Cursor meinCursor;
        /// <summary>
        /// X-Koordinate der neuen Cursorposition
        /// </summary>
        private int xPosDeltaAktuell;
        /// <summary>
        /// Y-Koordinate der neuen Cursorposition
        /// </summary>
        private int yPosDeltaAktuell;
        /// <summary>
        /// X-Koordinate der alten Cursorposition
        /// </summary>
        private int xPosDeltaAlt;
        /// <summary>
        /// X-Koordinate der alten Cursorposition
        /// </summary>
        private int yPosDeltaAlt;
        /// <summary>
        /// Pixeel in km
        /// </summary>
        private double km_ergebnis;
        private double dpi = 96.0;
        private double cm = 2.54;


Konstructor
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
public Form1()
{
    InitializeComponent();

    this.meinCursor = Cursors.Cross;
    Cursor.Show();
    xPosDeltaAlt = Cursor.Position.X;     
    yPosDeltaAlt = Cursor.Position.Y;
}


Timer:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
private void timIntervall_Tick(object sender, EventArgs e)
{
     this.xPosDeltaAktuell = Cursor.Position.X;
     this.yPosDeltaAktuell = Cursor.Position.Y;

     int xPosDelta = Math.Abs(xPosDeltaAktuell - xPosDeltaAlt);
     int yPosDelta = Math.Abs(yPosDeltaAktuell - yPosDeltaAlt);

     km_ergebnis += (xPosDelta + yPosDelta);
     km_ergebnis /= dpi;
     km_ergebnis *= cm;

     this.xPosDeltaAlt = this.xPosDeltaAktuell;
     this.yPosDeltaAlt = this.yPosDeltaAktuell;

// pixel/dpi, distanz in inch
// * 2.54 , ergebnis in cm
}


Der erste Wert ist korrekt und liefert die Pixel aus. km_ergebnis += (xPosDelta + yPosDelta);

Der 2te und 3te Wert allerdings stimmt dann i-wie nicht ....aber warum?
Theoretisch muesste die Rechnung so stimmen.

Oder lieg ich da falsch?
Als Ergebnis bekomme ich eine 0,0000231238120938 Zahl raus, anstatt (bei 14000 Pixeln) ~ 360,....cm..

Bitte um Hilfe/Rat...danke.


EDIT: geloest: es lag daran, das ich im timer weiter gerechnet hatte,...
ausblenden C#-Quelltext
1:
2:
km_ergebnis /= dpi;
km_ergebnis *= cm;

Das darf sich nicht im timer befinden.
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Fr 11.06.10 20:48 
user profile iconChiyoko hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden C#-Quelltext
1:
 km_ergebnis += (xPosDelta + yPosDelta);					
Das ist aber nicht die Länge der Diagonalen...

_________________
>λ=
Chiyoko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 298
Erhaltene Danke: 8

Win 98, Win Xp, Win 10
C# / C (VS 2019)
BeitragVerfasst: So 13.06.10 11:56 
Die wollt ich auch gar nicht;)

ausblenden C#-Quelltext
1:
2:
int xPosDelta = Math.Abs(xPosDeltaAktuell - xPosDeltaAlt);
int yPosDelta = Math.Abs(yPosDeltaAktuell - yPosDeltaAlt);
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 13.06.10 14:31 
Ok, dachte eben, du willst
user profile iconChiyoko hat folgendes geschrieben Zum zitierten Posting springen:
die zurueckgelegte Strecke der Maus
;) .

_________________
>λ=
Chiyoko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 298
Erhaltene Danke: 8

Win 98, Win Xp, Win 10
C# / C (VS 2019)
BeitragVerfasst: So 13.06.10 21:51 
Oehm, ...dafuer waer der Quelltext jetzt zu gros:D...belassen wir es dabei, das es funktioniert:)