Autor Beitrag
Al Borland
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 16



BeitragVerfasst: Mi 15.12.04 16:44 
Hallo allerseits!

Ich suche nach einer Methode Polygone zu rotieren.
Es soll ein Programm werden, daß Rundskalen zeichnen soll -
also wie bei einem Uhren- Zifferblatt.

Dabei muss der Mittelpunkt der Rotation gewählt werden können...

Wer hat dafür eine Idee? Komm ich eventuell ums Rechnen herum?
Kann man vielleicht ein Metafile gedreht auf ein Canvas ausgeben?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 15.12.04 17:04 
:welcome:

Al Borland hat folgendes geschrieben:
Komm ich eventuell ums Rechnen herum?

Also das mal sicher nicht ;)

Soweit ich weiß, hatten wir grad vor kurzem einen solchen Beitrag. Siehe auch Forensuche Suche in: Delphi-Forum, Delphi-Library POLYGON

AXMD
Al Borland Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 16



BeitragVerfasst: Mi 15.12.04 17:37 
AXMD hat folgendes geschrieben:

Also das mal sicher nicht ;)


Echt nicht? :bawling: Wie soll ich das denn alles rechnen...
Mit Winkelfunktionen wird das ganz schön aufwendig.
Gibt es nicht irgendeine schlaue Grafik Bibliothek, die so was kann?
sourcehunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 482

Win XP | Suse 10.1
Delphi 2005 Pers.
BeitragVerfasst: Do 16.12.04 10:23 
Hast du schon mal was von Matrizen gehört? Also wir hatten sowas im Unterricht, wie man Polygone dreht.

_________________
Linux und OpenSource rulez!
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Do 16.12.04 17:27 
Wir auch - und da brauchst du doch eine ziemliche Ahnung von Mathe, damit du weißt, was du tust; und damit auch dein Programm macht, was es machen soll ;)

AXMD
P_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 75

Win XP
Delphi 7 / 8 Enterprise
BeitragVerfasst: Fr 17.12.04 13:58 
Hi Al,

du kannst es auf folgende Weise machen:

Die Koordinatenpunkte deines Polygons legst du in einem Array of TPoint ab. Dieses Array nenne ich im folgenden Codebeispiel "Points".
Dann implementierst du zunächst die Prozedur mit der Rotationsmatrix:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure RotatePoints(var Points: array of TPoint;
  const Angle: Extended; const Org: TPoint);
var
  Sin, Cos: Extended;
  Prime: TPoint;
  I: Integer;
begin
 SinCos(Angle, Sin, Cos);
 for I := Low(Points) to High(Points) do
   with Points[I] do
   begin
     Prime.X := X - Org.X;
     Prime.Y := Y - Org.Y;
     X := Round(Prime.X * Cos - Prime.Y * Sin) + Org.X;
     Y := Round(Prime.X * Sin + Prime.Y * Cos) + Org.Y;
   end;
end;


Diese Prozedur kannst du jetzt aufrufen:

ausblenden Quelltext
1:
RotatePoints(Points, DegToRad(10), Point(X,Y));					


Der zweite Parameter ist der frei wählbare Rotationswinkel. Der dritte Parameter ist der Koordinatenpunkt des Rotationszentrums. Er ließe sich durch eine entsprechende Matrix auch zur Laufzeit errechnen, wenn der Graphic-Mittelpunkt noch nicht bekannt ist, oder veränderbar sein soll. Nach der Rotation zeichnest du nun auf dem Canvas.


Gruß, P_G
Al Borland Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 16



BeitragVerfasst: Mo 20.12.04 10:41 
:autsch: Oh nein...

Ich hätte vielleicht mal vorher wieder ins Forum gucken sollen...

Ich hab nämlich in der Zwischenzeit eine Routine selbst programmiert, allerdings nicht so elegant mit einer Matrize, sondern ziemlich umständlich :oops: (32 Zeilen - man bin ich blöd)...

Deine Routine klappt sehr gut - Danke!