Autor Beitrag
Unknown
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Sa 28.10.06 15:21 
Hi LeUtZ,
ich wollt wissen ob das geht:
-Ich hab ne linie(5 cm)
-Ein Ende der Linie ist "fest"
-Das andere ende soll in die Richtung der maus zeigen
-Det wars!!!!!!!!! :!: :!: :!: :!: :!: :!: :!: :!:
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 28.10.06 15:29 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 form1.Repaint;
 form1.Canvas.LineTo(Form1.Width div 2, Form1.Height div 2); // mittelpunkt der form
 Form1.Canvas.MoveTo(x,y);
end;


//edit: die linie kann natürlich länger bzw. kürzer als 5cm sein ;)
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Sa 28.10.06 15:39 
wird die linie dann von aleine gezeichnet oder wie
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 28.10.06 15:40 
probieren geht über studieren ;)
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: So 29.10.06 15:09 
könntest du mir das erklären(Zeile für Zeile)
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 29.10.06 15:44 
ausblenden Delphi-Quelltext
1:
2:
3:
 form1.Repaint;
 form1.Canvas.LineTo(Form1.Width div 2, Form1.Height div 2); // mittelpunkt der form
 Form1.Canvas.MoveTo(x,y);


1. löcht alle zuvor gezeichneten linien ("neuzeichnen")
2. setzt den startpunkt, der zu zeichnenden linie, fest - in dem fall Form-Mitte
3. zeichnet vom startpunkt aus eine linie zum punkt x,y ;)
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: So 29.10.06 16:50 
Hier hilft die Vektorrechnung
Du baust dir den Vektor vom Fixpunkt zum Punkt der Maus.
P(5;8) sei z.B. der Fixpunkt
Der Punkt der Maus sei M(x;y)
Dann ist der Vektor von P nach M: M-P also (x-5;y-8).
Dann normierst du den Vektor, in dem du durch seinen Betrag teilst.
Betrag eines Vektors ist d=sqrt(x^2+y^2)
Und dann hat der Vektor die Länge eins.
Dann noch mal die Länge des Vektors, wie lang er sein soll, dann haste den Vektor, der von P in RIchtung M zeigt mit der Länge , mit der du Multipliziert hast.
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: So 29.10.06 16:54 
@Kroni: Ich glaube nicht, dass er in seinem Alter was mit Vektorenrechnung anfangen kann ;-)
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: So 29.10.06 16:59 
user profile iconDanny87 hat folgendes geschrieben:
@Kroni: Ich glaube nicht, dass er in seinem Alter was mit Vektorenrechnung anfangen kann ;-)

gut
a) ich habe nicht auf sein Alter geachtet
b) naja, er muss ja theoretisch nur die Rechnungen dort befolgen, aber gut, stimmt schon, könnte für ihn etwas kompliziert sein....aber habe angenommen, dass er jünger sei.
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Mo 30.10.06 15:09 
ihr habt meine Frage falsch verstanden,
ich wollte eine Linie mit 5cm und nicht länger oder kürzer.
Das heißt:
-Sie soll genau 5cm betragen
-Und der "Nicht-feste" Punkt soll in Richrung Maus zeigen

Richtig, VektorenRechnung bin ich nen bissel jung :oops: :oops:
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 30.10.06 15:45 
Ich hab das von oben mal in Quelltext umgewandelt. Das Problem ist dabei die 5cm, da das ja vom Bildschirm und der Auflösung abhängt. Das wird man nicht so ohne weiteres "mal eben" hinbekommen. Eine konstant lange Linie in Richtung des Mauszeigers bekommt man so:
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:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var xcenter, ycenter: Integer;
  DeltaX, DeltaY: Integer;
  Hypothenuse: Double;
  Streckfaktor: Double;
begin
 form1.Repaint;

 // Mitte der Form
 xCenter := Form1.Width div 2;
 yCenter := Form1.Height div 2;

 // Stift in die Mitte bewegen
 form1.Canvas.MoveTo(xCenter,yCenter); // mittelpunkt der form

 // Abstand in X/Y Richtung der Mitte zum Mauszeiger
 // In diese Richtung muss der Strich gehen!
 DeltaX := X - xCenter;
 DeltaY := Y - yCenter;

 // Satz des Pythagoras Anwenden, um die Länge der Strecke "Mittelpunkt-Maus" zu berechnen
 Hypothenuse := sqrt(DeltaX*DeltaX + DeltaY*DeltaY);

 // Wir möchten aber dem Strich eine bestimmte Länge geben.
 // Hier: Länge = 100 Pixel
 if Hypothenuse <> 0 then
   Streckfaktor := 100 / Hypothenuse
 else
  Streckfaktor := 0;

 // Linie Zeichnen
 Form1.Canvas.LineTo( Round(xCenter + Streckfaktor * DeltaX), Round(yCenter + StreckFaktor * DeltaY));
end;

_________________
We are, we were and will not be.