![]() |
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:
[edit=Matze]Hinweis hinzugefügt. Mfg, Matze[/edit]
{
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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz