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:
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:
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