Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Grafik / Sound / Multimedia (https://www.delphipraxis.net/21-library-grafik-sound-multimedia/)
-   -   Delphi Drehung und Verschiebung im 2D Raum (https://www.delphipraxis.net/33175-drehung-und-verschiebung-im-2d-raum.html)

shmia 2. Nov 2004 17:15


Drehung und Verschiebung im 2D Raum
 
folgende Funktionen ermöglichen Drehungen und Verschiebungen im 2-dimensionalen Raum.
Winkel sind wie üblich im Bogenmass anzugeben.

Um auf die Winkelfunktionen zugreifen zu können, muss Math über uses eingebunden werden.

Delphi-Quellcode:
{
  Rotate a Point by Angle 'alpha'
}
function Rotate2D(p:TPoint; alpha:double): TPoint;
var
  sinus, cosinus : Extended;
begin
(*
  sinus  := sin(alpha);
  cosinus := cos(alpha);
*)
  { twice as fast than calc sin() and cos() }
  SinCos(alpha, sinus, cosinus);

  result.x := Round(p.x*cosinus + p.y*sinus);
  result.y := Round(-p.x*sinus + p.y*cosinus);
end;

{
  Move Point "a" by Vector "b"
}
function Translate2D(a, b:TPoint): TPoint;
begin
  result.x := a.x + b.x;
  result.y := a.y + b.y;
end;

procedure Rotate2Darray(var p:array of TPoint; alpha:double);
var
  i : Integer;
begin
  for i:=Low(p) to High(p) do
    p[i] := Rotate2D(p[i], alpha);
end;

procedure Translate2Darray(var p:array of TPoint; shift:TPoint);
var
  i : Integer;
begin
  for i:=Low(p) to High(p) do
    p[i] := Translate2D(p[i], shift);
end;
[edit=Matze]Hinweis hinzugefügt. Mfg, Matze[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:46 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz