From 5015ece4e255649e1571e4c1650a35beffd25def Mon Sep 17 00:00:00 2001 From: Wizzup? Date: Tue, 6 Oct 2009 03:42:52 +0000 Subject: [PATCH] mmath git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@108 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Units/MMLCore/mmath.pas | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Units/MMLCore/mmath.pas diff --git a/Units/MMLCore/mmath.pas b/Units/MMLCore/mmath.pas new file mode 100644 index 0000000..d0dd32a --- /dev/null +++ b/Units/MMLCore/mmath.pas @@ -0,0 +1,48 @@ +unit mmath; +// mufasa math + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils,MufasaTypes; + +function RotatePoints(P: TPointArray; A, cx, cy: Extended): TPointArray; +function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint; + + +implementation + +{/\ + Rotates the given points (P) by A (in radians) around the point defined by cx, cy. +/\} + +function RotatePoints(P: TPointArray; A, cx, cy: Extended): TPointArray; + +var + I, L: Integer; + +begin + L := High(P); + SetLength(Result, L + 1); + for I := 0 to L do + begin + Result[I].X := Round(cx + cos(A) * (p[i].x - cx) - sin(A) * (p[i].y - cy)); + Result[I].Y := Round(cy + sin(A) * (p[i].x - cx) + cos(A) * (p[i].y - cy)); + end; +end; + +{/\ + Rotates the given point (p) by A (in radians) around the point defined by cx, cy. +/\} + +function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint; + +begin + Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my)); + Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my)); +end; + +end. +